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 › Add Some Colour To My Life
Page Index Toggle Pages: 1
Add Some Colour To My Life (Read 822 times)
Add Some Colour To My Life
Apr 7th, 2010, 3:17pm
 
The following code will generate a random circle in a random position, but won't seem to add a colour to the circle. Can anyone help in doing this?

Code:
boolean paused = true;
float x1;
float y1;
float c1;

void setup()
{
size(400,400);
background(255);
smooth();
x1 = random(400);
y1 = random(400);
color c1 = color(102, 102, 0);
}
void draw()
{
fill(c1);
background(255);
ellipse(x1,y1,20,20);
}

void keyPressed()
{
paused = !paused;
if(paused) noLoop();
else loop();
}

Re: Add Some Colour To My Life
Reply #1 - Apr 7th, 2010, 8:02pm
 
That's because you declared c1 as a float and then later on tried to declare it as a colour. I'm surprised the compiler doesn't pick this up.

Here's the amended program:

Code:
boolean paused = true;
float x1;
float y1;
color c1;

void setup()
{
size(400,400);
background(255);
smooth();
x1 = random(400);
y1 = random(400);
c1 = color(102, 102, 0);
}
void draw()
{
fill(c1);
background(255);
ellipse(x1,y1,20,20);
}

void keyPressed()
{
paused = !paused;
if(paused) noLoop();
else loop();
}
Re: Add Some Colour To My Life
Reply #2 - Apr 8th, 2010, 6:07am
 
Quote:
I'm surprised the compiler doesn't pick this up.


I think its being overridden by the declaration in setup() and then its discarded as soon as setup ends. So then you have yet again the global unassigned float value. So technically it's legit.
Re: Add Some Colour To My Life
Reply #3 - Apr 8th, 2010, 7:48am
 
Oh yes...you're right.
Page Index Toggle Pages: 1