Help With Final Project - if / then statements

Hi everyone! We are required to make a digital image using processing with THREE "SCENES" here is my code with successfully TWO scenes, when the background changes to the green color and its a "clean slate" although now i am having trouble making the "third" scene. im assuming something needs to be done with an if statement like the first but im lost.

int x; int y;

void setup() {

size(800,800); background(200); }

void draw () { x=x+1; y=y+1; if(frameCount<300) { fill(242,121,2*y); noStroke(); rect(x,x,y,y);

fill(102,0,51); ellipse(400,400,6x,6x);

fill(255,178,102); ellipse(400,400,4x,4x);

fill(225,162,247); ellipse(400,400,x,x);

if(x>800) {x=0;} if(y>255) {y=0;} } if(frameCount==301) { background(204,255,153); } if(frameCount>300) { if(x>800) {x=0;} if(y>250) {y=0;}

fill(255, 222, 153); rect(0,0,y,y);

fill(252, 196, 240); rect(90,90,y,y);

fill(255, 181, 121); rect(200,200,y,y);

fill(247, 123, 182); rect(280,280,y,y);

fill(255, 253, 163); rect(340,340,y,y);

fill(252, 146, 146); rect(400,400,y,y);

fill(255, 186, 58); rect(400,400,y,y);

fill(183, 80, 142); rect(450,450,y,y);

fill(250, 255, 112); rect(500,500,y,y);

fill(252, 194, 169);

rect(550,550,y,y);

fill(255); ellipse(400,400,x2,x2);

if(frameCount>2000);

fill(78,y2,x2); triangle(200,400,400,400,mouseX,200); } }

Answers

  • Answer ✓

    you want if(frameCount.... else if(frameCount.....) else if.....

    Also you want for the 2nd if: frameCount >300&& frameCount < 700 and for the 3rd frameCount >=700

  • this if(frameCount>2000); won't work because of the semicolon ;

    The section that gets executed (if condition applies) would be between ) and ; which is nothing

    delete the semicolon and you get

      if (frameCount>2000) {
        fill(78, y*2, x*2); 
        triangle(200, 400, 400, 400, mouseX, 200);
      }
    

    here is the entire code:

    int x; 
    int y;
    
    void setup() {
    
      size(800, 800); 
      background(200);
    }
    
    void draw () { 
      x=x+1; 
      y=y+1; 
    
      if (frameCount<300) {
        // first sequence 
        fill(242, 121, 2*y); 
        noStroke(); 
        rect(x, x, y, y);
    
        fill(102, 0, 51); 
        ellipse(400, 400, 6*x, 6*x);
    
        fill(255, 178, 102); 
        ellipse(400, 400, 4*x, 4*x);
    
        fill(225, 162, 247); 
        ellipse(400, 400, x, x);
    
        if (x>800) {
          x=0;
        } 
        if (y>255) {
          y=0;
        }
      } else if (frameCount>=300 && 
        frameCount<309) {
        // just delete scene 
        background(204, 255, 153);
      } else if (frameCount>310 &&
        frameCount<1999) { 
        // long sequence 
        if (x>800) {
          x=0;
        } 
        if (y>250) {
          y=0;
        }
    
        fill(255, 222, 153); 
        rect(0, 0, y, y);
    
        fill(252, 196, 240); 
        rect(90, 90, y, y);
    
        fill(255, 181, 121); 
        rect(200, 200, y, y);
    
        fill(247, 123, 182); 
        rect(280, 280, y, y);
    
        fill(255, 253, 163); 
        rect(340, 340, y, y);
    
        fill(252, 146, 146); 
        rect(400, 400, y, y);
    
        fill(255, 186, 58); 
        rect(400, 400, y, y);
    
        fill(183, 80, 142); 
        rect(450, 450, y, y);
    
        fill(250, 255, 112); 
        rect(500, 500, y, y);
    
    
        fill(252, 194, 169);
    
        rect(550, 550, y, y);
    
        fill(255); 
        ellipse(400, 400, x*2, x*2);
      } else  if (frameCount>2000) {
        // last sequence 
        fill(78, y*2, x*2); 
        triangle(200, 400, 400, 400, mouseX, 200);
      }
    
      // test 
      fill(0); 
      text(frameCount, 14, 14);
    }
    //
    
Sign In or Register to comment.