We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › logic error from newbie.
Page Index Toggle Pages: 1
logic error from newbie. (Read 532 times)
logic error from newbie.
Sep 13th, 2005, 11:06pm
 
Hello. I am starting to learn processing and can someone please explain to me why this draws more than 10 circles. I have checked the logic a few times and I can't see what I am doing wrong. Thanks for all help!
best,
nix
------------------------
void setup(){
size(300, 800);
background(0);
ellipseMode(CENTER);
}

int xwidth=10;
int yheight=10;
int ypos=0;
int yspeed=5;
int max = 10;
int xpos[] = new int[max];


void draw(){
noStroke();
fill(150);
for(int i=0; i<max; i++) {
fill(150);
xpos[i]= int(random(0,300));

ellipse(xpos[i], ypos, xwidth, yheight);
ypos=ypos + yspeed;
}

if (ypos>height){
ypos=0;
noLoop();
}


}
Re: logic error from newbie.
Reply #1 - Sep 13th, 2005, 11:43pm
 
it's continually drawing the 10 circles each time through the draw9), so first you have 10, then 20, then 30, etc.

to erase them each time through the draw(), put a background(0); at the beginning of the draw()
Re: logic error from newbie.
Reply #2 - Sep 13th, 2005, 11:53pm
 
thanks so much. that also answers my next question too.  i also realized that i was declaring i as 0 every time it ran draw and if I changed the code so that i declared i outside of the draw function, it didn't reset and I only got 10 dots.
thanks again. as a total aside, i posted up about tutorials i found on the alpha site i was using to learn. later, i realized that the ones that i though where part of the processing site where actually Daniel Shiffman's from his NYU class. thanks for getting back to me then too.

best,
nix

void setup(){
size(300, 800);
background(0);
ellipseMode(CENTER);}

int xwidth=10;
int yheight=10;
int ypos=0;
int yspeed=5;
int max = 10;
int xpos[] = new int[max];
int i=0;

void draw(){
noStroke();
fill(150);
if(i<11)
fill(150);
xpos[i]= int(random(0,300));

ellipse(xpos[i], ypos, xwidth, yheight);
ypos=ypos + yspeed;
i++;
}

if (ypos>height){
ypos=0;
noLoop();
}


}
Page Index Toggle Pages: 1