We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Edit: Solved -- question can be deleted.
I believe I'm misunderstanding something about how the draw()
function works. Below is a minimal working example of what I have in mind. The conditional 'if' statement seems to be reversing the fill colour. Rectangles should be in red, ellipses in blue.
Instead, the rectangle shows up in blue, while the circle shows up in red. If I only display(0)
or display(1)
, then the correct colour shows up. Any thoughts?
Thanks for any help!
void setup() {
size(400, 400);
}
void draw() {
display(0);
display(1);
}
void display(int i) {
if(i == 0) {
rect(20, 20, 40, 40);
fill(200, 0, 0); // rectangles are red!
}
if(i == 1) {
ellipse(100, 100, 20, 20);
fill(0, 0, 200); // circles are blue!
}
}
Answers
This question can be deleted, the obvious mistake is that
fill
must be called before the shape to be drawn. Reversing the order solves the issue.