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 › sequneces of numbers
Page Index Toggle Pages: 1
sequneces of numbers (Read 352 times)
sequneces of numbers
Oct 28th, 2007, 9:15pm
 
dear advanced coders,

I have this sequence of numbers goes like,
5, 15, 25, 35, 45, 55......so on until 500. (n+=10)

I want divide this into two sequence of numbers as 5, 25, 45, 65...etc.
and 15, 35, 55, 75....etc.

But I have no idea which math formula to use for that.

for example,

Quote:




size(501,501);
background(255);
smooth();

for (int y=5; y<height; y+=10){
 for (int x=5; x<width; x+=10){

   ellipse(x,y,10,10);
println(x);
 }

}





I want that one row of circles to be black and after red, than balck, red....so on.

I was thinking about using array, but how??? no idea!

I hope that my question is clear....

thank you.
Re: sequneces of numbers
Reply #1 - Oct 28th, 2007, 9:53pm
 
you need an on-off-switch:

Code:

size(501,501);
background(255);
smooth();

boolean aSwitch = false;

for (int y=5; y<height; y+=10)
{
   if ( aSwitch ) fill( 0 );
   else fill( color( 255, 0, 0 ) );
   
   for (int x=5; x<width; x+=10)
   {
       ellipse(x,y,10,10);
       println(x);
   }
   
   aSwitch = !aSwitch; // flip to opposite
}


F
Re: sequneces of numbers
Reply #2 - Oct 28th, 2007, 10:10pm
 
thank you for the reply, it works perfectly!

in the terminal, it flips ture/false each time the first loop excute, I don't fully understand yet, but I'll try to apply this to different situations to understand better.

thank you again for quick & kind answer.

Page Index Toggle Pages: 1