forked from mhenstell/acw
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Bursts.pde
133 lines (109 loc) · 2.55 KB
/
Bursts.pde
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
class Bursts extends Routine {
int NUMBER_OF_BURSTS = 16;
Burst[] bursts;
void setup(PApplet parent) {
super.setup(parent);
bursts = new Burst[NUMBER_OF_BURSTS];
for (int i = 0; i<NUMBER_OF_BURSTS; i++) {
bursts[i] = new Burst();
}
}
void reset() {
}
void draw()
{
draw.background(0,0,20);
for (int i=0; i<NUMBER_OF_BURSTS; i++) {
bursts[i].draw();
}
if (frameCount - modeFrameStart > Config.FRAMERATE * Config.MODE_TIMEOUT) {
newMode();
}
}
}
class Burst {
float x;
float y;
float xv;
float yv;
float d;
float maxd;
float speed;
int intensity;
float r;
float g;
float b;
public Burst()
{
init();
}
public void reset()
{
resetColor();
x = random(Config.WIDTH);
y = random(Config.HEIGHT);
float max_speed = 0.25;
xv = random(max_speed) - max_speed/2;
yv = random(max_speed) - max_speed/2;
maxd = random(6);
speed = random(5)/10 + 0.4;
d = 0;
intensity = 255;
}
public void resetColor()
{
color col;
float i = random(3);
if (i<1) col = primaryColor;
else if (i<2) col = secondaryColor;
else col = tertiaryColor;
r = red(col);
g = green(col);
b = blue(col);
}
public void init()
{
reset();
}
public void draw_ellipse(float x, float y, float widt, float heigh, color c) {
while(widt > 1 && heigh > 1) {
float target_brightness = random(.8,1.5);
c = color(red(c)*target_brightness, green(c)*target_brightness, blue(c)*target_brightness);
draw.fill(c);
draw.stroke(c);
draw.ellipse(x, y, widt, heigh);
widt -= 1;
heigh -= 1;
}
}
public void draw()
{
// Draw multiple elipses, to handle wrapping in the y direction.
draw_ellipse(x, y, d*(.5-.3*y/Config.HEIGHT), d*3, color(r,g,b));
draw_ellipse(x-Config.WIDTH, y, d*(.5-.3*y/Config.HEIGHT), d*3, color(r,g,b));
draw_ellipse(x+Config.WIDTH, y, d*(.5-.3*y/Config.HEIGHT), d*3, color(r,g,b));
d+= speed;
if (d > maxd) {
// day
r -= 2;
g -= 2;
b -= 2;
intensity -= 15;
//night
// r -= 1;
// g -= 1;
// b -= 1;
// intensity -= 3;
}
// add speed, try to scale slower at the bottom...
x +=xv*(Config.HEIGHT - y/3)/Config.HEIGHT;
y +=yv*(Config.HEIGHT - y/3)/Config.HEIGHT;
if (intensity <= 0) {
reset();
}
long frame = frameCount - modeFrameStart;
if (frame >Config.FRAMERATE*Config.MODE_TIMEOUT) {
newMode();
}
}
}