Skip to content

Instantly share code, notes, and snippets.

@latrokles
Created May 6, 2009 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save latrokles/107821 to your computer and use it in GitHub Desktop.
Save latrokles/107821 to your computer and use it in GitHub Desktop.
/*
* background_shapes.pde
* latrokles -- samuraihippo.com
*
* Some quick tinkering with Processing in an otherwise boring day. The
* sketch draws circles of random colors as the mouse gets dragged around,
* the diameter of the circle is determined by the difference between the
* current mouse position and the previous mouse position so that the faster
* and further you move your mouse, the larger the circle will be.
*
* You can also clear the screen by pressing 'c' or save the image currently
* being displayed by pressing the space bar.
*/
//Variables for colors and circle diameter
int r, g, b, a;
int diameter;
void setup()
{
size(screen.width, screen.height);
background(0, 0, 0);
smooth();
}
/*
* Randomly generate values for red, green, blue, and alpha each frame of
* the sketch.
*/
void draw()
{
r = (int)random(0, 255);
g = (int)random(0, 255);
b = (int)random(0, 255);
a = (int)random(0, 255);
}
/*
* Only draw a circle when the mouse is being dragged.
*/
void mouseDragged()
{
drawCircle();
}
void mouseReleased()
{
}
/*
* Set the fill and stroke color (which are being
* randomly changed every frame of the sketch), then determine the diameter
* of the circle by computing the difference between the mouse's current
* and previous position. Finally, draw the circle at mouseX and mouseY.
*/
void drawCircle()
{
fill(r,g,b,a);
stroke(r-10, g-10, b-10, a);
strokeWeight(10);
diameter = abs((int)dist(mouseX, mouseY, pmouseX, pmouseY));
ellipse(mouseX, mouseY, diameter, diameter);
}
/*
* Save the image being displayed in the sketch data folder by pressing
* space, or clear the screen by pressing 'c'.
*/
void keyPressed()
{
if(key == ' ')
{
saveFrame("work-####.png");
}
if(key == 'c')
{
background(0, 0, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment