-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.pde
More file actions
88 lines (82 loc) · 1.94 KB
/
Copy pathWindow.pde
File metadata and controls
88 lines (82 loc) · 1.94 KB
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
class Window extends Frame {
float amt = in.bufferSize();
ArrayList<Droplet> rain = new ArrayList<Droplet>();
PImage bg;
boolean bt = false;
Window() {
bg = loadImage("rain/bg.jpg");
bg.resize(width, height);
}
void load() {
bg.resize(width, height);
}
void frame() {
colorMode(RGB);
background(0);
tint(255, 100);
image(bg, 0, 0);
noTint();
if (beat.isOnset()) {
fill(255, 64);
noStroke();
rect(0, 0, width, height);
bt = true;
} else if (bt) {
fill(255, 64);
noStroke();
rect(0, 0, width, height);
bt = false;
}
strokeWeight(4);
for (int i = 1; i < amt; i+=4) {
float i1 = in.mix.get(i);
float i2 = in.mix.get(i - 1);
if (random(1) < .5)
rain.add(new Droplet(random(width), 0, i1/2 + 1/2, 128 * i2 + 128, 128 * i2 + 128, 128 * i2 + 128));
else
rain.add(new Droplet(0, random(height), i1/2 + 1/2, 128 * i2 + 128, 128 * i2 + 128, 128 * i2 + 128));
}
for (int i = 0; i < rain.size(); i++) {
Droplet drop = rain.get(i);
drop.inc();
drop.setStroke();
line(drop.x, drop.y, drop.x(), drop.y());
if (drop.x > width || drop.y > height) drop.remove = true;
}
for (int i = 0; i < rain.size(); i++) {
if (rain.get(i).remove) rain.remove(i);
}
}
}
class Droplet {
public boolean remove = false;
public float r, g, b, a = 255;
public float x = 0, y = 0;
public float size = 0;
public float speed = 0;
Droplet(float x, float y, float size, float r, float g, float b) {
this.x = x;
this.y = y;
this.size = size;
this.r = r;
this.g = g;
this.b = b;
this.speed = random(20) + 20;
}
void setStroke() {
stroke(r, g, b, a);
strokeWeight(size);
}
void inc() {
x += speed;
y += speed;
a *= .99;
if (a < 10) remove = true;
}
float x() {
return x - speed;
}
float y() {
return y - speed;
}
}