Beginner's question about the FILL command

This is driving me insane and I cannot seem to find any explanation.

Why are (in the following code) multiple shapes in the fill color (150) even though the fill command is the last command in the DRAW zone. I thought only subsequent shapes would be filled in that color - but it is also filling in earlier shapes in the same (150) grey.

void setup() {
    size(640,420);
    background(240);
    smooth();
}

void draw() {

  //body of zork
  rectMode(CENTER);
  rect(320,210,80,120);

  //head of zork
  ellipse(320,118,65,65);

  //eyes of zork
  //fill(50);
  ellipse(307,115,10,20);
  ellipse(333,115,10,20);
  fill(150);
}

Answers

  • Answer ✓

    fill sets the pen colour so everything drawn after it will have that fill colour.

    however, the draw() method loops around, so if you set the pen colour at the bottom then the same fill colour will be active at the top of the next loop...

  • Answer ✓

    also, if that's all you're doing, if you have no interaction or animation, then use noLoop();

  • edited June 2016
    size(640, 420);
    smooth(4);
    noLoop();
    
    background(240);
    
    //body of zork
    rectMode(CENTER);
    rect(320, 210, 80, 120);
    
    //head of zork
    ellipse(320, 118, 65, 65);
    
    //eyes of zork
    fill(50);
    ellipse(307, 115, 10, 20);
    ellipse(333, 115, 10, 20);
    
    fill(150);
    
  • Thank you koogs and GoToLoop. Makes much more sense now!

Sign In or Register to comment.