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 › really simple problem
Page Index Toggle Pages: 1
really simple problem (Read 297 times)
really simple problem
Oct 6th, 2008, 11:34pm
 
Hello,

  I go in and out of using processing and as a result, sometimes have no Idea  what is going on.

This is supposed to be a stupid-easy program that makes circles appear on the screen in a roygbiv fashion, however, the colors seem to change position when I add more than one.

this places the red circle where expected

void setup ()
{
size(1000, 200);
smooth();
background(0);
noStroke();

}


void draw()
{
float c = 60;



 if (key=='a')
   
   ellipse(50,150, c, c);
   fill(255,0,0);
   
   

   
 
}


This code, however flip flops my expected outcome

void setup ()
{
size(1000, 200);
smooth();
background(0);
noStroke();

}


void draw()
{
float c = 60;



 if (key=='a')
   
   ellipse(50,150, c, c);
   fill(255,0,0);
   
   
if (key=='s')
   
   ellipse(120,150, c, c);
   fill(230,100,0);

   
 
}

any help would be really appreciated, as I said, this is probably really simple.
I think I am doing something fundamentally wrong, but have no clue what exactly.


thanks




Re: really simple problem
Reply #1 - Oct 7th, 2008, 5:48am
 
i suspect you are missing the curly brackets in your if-statements. if an if-statement should only execute one line of code, the curly brackets are not required, but if there is more than 1 line to be executed in an if-statement, curly brackets are required. same goes for for-loops. reading through your code, i recommend to set the color before you draw a shape (same goes for lines). which would give you the following
Code:

void setup() {
size(1000,200);
smooth();
background(0);
noStroke();
}


void draw() {
// use background to
// overwrite what has been drawn
// in the previous frame.
background(0);

float c = 60;

// the variable key stores
// the last key that has been pressed.
// even if you release the key on
// your keyboard, the variable key
// will still contain the last
// key pressed.

if (key=='a') {
fill(255,0,0);
ellipse(50,150, c, c);
}

if (key=='s') {
fill(230,100,0);
ellipse(120,150, c, c);
}

}
Re: really simple problem
Reply #2 - Oct 7th, 2008, 7:34am
 
thanks so much. I see what I was forgetting. very helpful.

It has been too long, it is a shame how quickly my skills seem to rust
Page Index Toggle Pages: 1