We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello yall, I 'd like to draw lines with 20 pixels increments like below.
However, when I put "int x=0" after void draw(), I couldn't see anything.
Why it doesn't show anythiing?
Case one
int x = 0;
void setup() {
size(400,300);
}
void draw() {
background(0);
strokeWeight(2);
stroke(255);
line (x,0,x,height);
x = x+20;
}
case two
void setup() {
size(400,300);
}
void draw() {
int x = 0;
background(0);
strokeWeight(2);
stroke(255);
line (x,0,x,height);
x = x+20;
}
Answers
I made this for you:
I apologize for the weird formatting, I'm new to the forums.
Draw is a loop, it is called repeatedly.
In case 1 it is called repeatedly and X increments because X is global, so you see lots of lines.
In case 2 it is called repeatedly but X is local so it's always 0. You see 1 line at x = 0, lots of times.
Read the FAQ about setup and draw.
And the one about formatting code.
And all the others whilst you are there.