latrokles (owner)

Revisions

gist: 107821 Download_button fork
public
Public Clone URL: git://gist.github.com/107821.git
Embed All Files: show embed
Java #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* 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);
  }
}