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 & HelpPrograms › Redo on Click
Page Index Toggle Pages: 1
Redo on Click (Read 435 times)
Redo on Click
Jan 8th, 2009, 9:15am
 
How do I get this sketch to repaint the background after clicking the mouse? I can't figure it out...

void setup()
{
 size(500, 500);

 background (256, 256, 256);
 noStroke();
 smooth();

 drawCircles(250, 250, 100, 10);
}
 
// Circle splatter machine

void drawCircles(float x, float y, int radius, int level)
{
 float tt = 126 * level / 6.0;
 fill (tt, 0, 116);
 ellipse(x, y, radius*2, radius*2);
 if (level > 1) {
   level = level - 1;
   int num = int (random(2, 5));
   for(int i=0; i<num; i++) {
     float a = random(0, TWO_PI);
     float nx = x + cos(a) * 6.0 * level;
     float ny = y + sin(a) * 6.0 * level;
     drawCircles(nx, ny, radius/2, level);
   }
 }
}
Re: Redo on Click
Reply #1 - Jan 8th, 2009, 10:19am
 
Add this to your code

Code:

void draw() {
}

void mousePressed() {
background (255, 255, 255);
drawCircles(250, 250, 100, 10);
}


Without the empty draw, the sketch stops listening for clicks.

Also, the maximum RGB value is 255 and not 256... remember the 0 counts... so 0 to 255 = 256 values! Smiley

Cheers
Re: Redo on Click
Reply #2 - Jan 8th, 2009, 9:07pm
 
YAY! that's awesome. Thanks so much. Happy
Re: Redo on Click
Reply #3 - Jan 9th, 2009, 3:51am
 
ahhh that empty draw! who would have thought.
Page Index Toggle Pages: 1