Fading background method in P3D with pjs?

edited May 2016 in JavaScript Mode

The normal method in draw for a fading background effect:

    fill(180, 30);
    rect(0, 0, width, height);

It does not work for me in Processing.JS with P3D or OpenGL. There is no trace/fade going on, it's just the same as:

background(180);

Is there a solution?

Answers

  • I have resolved this. The solution was where I had the code in my program. It needed to be after a translate reset to the center of the screen, and the rect needs to be at the bottom of the program in my case.

  • Actually I have not fixed this. It isn't displaying like it would in normal Java mode. Here is my code:

    import processing.opengl.*;
    int radius = 100;
    
    
    void setup() { 
      size(800, 800, OPENGL);
      stroke(255);
      sphereDetail(5);
    }
    
    
    void draw() { 
    
      fill(180, 4);
      rect(0, 0, width, height);
      translate(width/2, height/2, 0);
    
      rotateY(frameCount * 0.01);
      rotateX(frameCount * 0.02);
      float s = 0;
      float t = 0;
      float lastx = 0.0;
      float lasty = 0.0;
      float lastz = 0.0;
    
      while (t < 180) { 
    
        s += 18;
        t += 1;
        float radianS = radians(s);
        float radianT = radians(t);
    
        float thisx = 0 + (radius * cos(radianS) * sin(radianT));
        float thisy = 0 + (radius * sin(radianS) * sin(radianT));
        float thisz = 0 + (radius * cos(radianT));
    
        pushMatrix();
        if (lastx != 0) {
    
          float r = random(1);
          //line(thisx, thisy, thisz, lastx, lasty, lastz);
    
          if (r > 0.999) {
            line(thisx, thisy, thisz, lastx, lasty, lastz);
          }
    
    
          translate(thisx, thisy, thisz);
          point(thisx, thisy, thisz);
          //line(thisx, thisy, thisz, lastx, lasty, lastz);
          sphere(2);
    
          translate(lastx, lasty, lastz);
          //line(thisx, thisy, thisz, lastx, lasty, lastz);
    
          point(lastx, lasty, lastz);
    
          if (r > 0.999) {
            line(thisx, thisy, thisz, lastx, lasty, lastz);
          }
        }
    
    
        popMatrix();
        lastx = thisx;
        lasty = thisy;
        lastz = thisz;
      }
    }
    
Sign In or Register to comment.