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 › probably a preety noob question! for()
Page Index Toggle Pages: 1
probably a preety noob question! for() (Read 677 times)
probably a preety noob question! for()
May 25th, 2009, 11:47am
 
hey! im reading the Processing, a programming book for Visual Designer and artists....

and i got to the for(); Repetition section and  since i had already done some coding i tried to modify the simple code in the book...

and my for() would work with no setup done.... but once i put some void setup() the code would fall apart! can someone tell me what is going on? Code:
void setup(){
size(400,400);
}

for ( int i = 10; i < 30; i += 5){
ellipseMode(CORNER);
ellipse(20,i,80,i+15);
}
this is the code o got.... as simple as this... and it doesn't work with the void setup stuff
Re: probably a preety noob question! for()
Reply #1 - May 25th, 2009, 12:55pm
 
All code has to be inside a function - this works Smiley

Code:
void setup(){
 size(400,400);
 ellipseMode(CORNER);
 for ( int i = 10; i < 30; i += 5){
   ellipse(20,i,80,i+15);
   }
}

Re: probably a preety noob question! for()
Reply #2 - May 25th, 2009, 12:59pm
 
thanks a lot! but i tried to put it inside a draw function and it didn't work.... i must have been doing something wrong :s
Re: probably a preety noob question! for()
Reply #3 - May 25th, 2009, 1:04pm
 
This also works Smiley
Code:

void setup(){
 size(400,400);
 ellipseMode(CORNER);
}

void draw(){
 for ( int i = 10; i < 30; i += 5){
   ellipse(20,i,80,i+15);
 }
}  
Re: probably a preety noob question! for()
Reply #4 - May 25th, 2009, 1:08pm
 
Quark wrote on May 25th, 2009, 12:55pm:
All code has to be inside a function

It is right. For those wondering: if you just throw some lines without any function and wonder why it runs: Processing detects the absence of setup() and just create one, putting your code there.

Quote:
i tried to put it inside a draw function and it didn't work

Just show us your code! Smiley

PS.: I see the latest answer of Quark in my preview. You might want to add a call to background() at the start of draw().
Re: probably a preety noob question! for()
Reply #5 - May 25th, 2009, 1:09pm
 
Quote:
You might want to add a call to background() at the start of draw().


Good point Smiley
Re: probably a preety noob question! for()
Reply #6 - May 25th, 2009, 1:12pm
 
no need to show my code! it works already!i was probably doing something wrong, and the repetitions were giving me a hard time to understand! i understand it now! thank you guys!
Page Index Toggle Pages: 1