Created
May 6, 2009 23:50
-
-
Save latrokles/107821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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