-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrain2d.pde
121 lines (114 loc) · 2.22 KB
/
rain2d.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
/*
Wanying Cao
*/
PShape rain, head, body;
int l=80;
Rainy []r= new Rainy[l];
int count=0;
void setup() {
size(1000, 600);
background(0, 0, 50);
frameRate(10);
for (int i=0; i<l; i++) {
r[i]= new Rainy(random(width), 0);
}
//setDefaultCloseOperation(EXIT_ON_CLOSE);
}
class Rainy {
private float x, y;
public Rainy(float x, float y) {
this.x=x;
this.y=y;
}
public void Shape() {
rain = createShape(GROUP);
ellipseMode(CORNER);
noStroke();
head= createShape(TRIANGLE, x, 20+y, x+15, 20+y, x+7.5, y);
head.setFill(color(0, 0, 150));
body= createShape(ARC, x, y+10, 15, 20, 0, PI);
body.setFill(color(0, 0, 150));
rain.addChild(head);
rain.addChild(body);
shape(rain);
}
public void RShape() {
rain = createShape(GROUP);
ellipseMode(CORNER);
noStroke();
head= createShape(ARC, x, y-10, 15, 20, PI, 2*PI);
head.setFill(color(0, 0, 150));
body= createShape(TRIANGLE, x, y, x+15, y, x+7.5, y+20);
body.setFill(color(0, 0, 150));
rain.addChild(head);
rain.addChild(body);
shape(rain);
}
public void setY(float y) {
this.y=y;
}
public float getX() {
return x;
}
public float getY() {
return y;
}
}
void drop() {
}
void wave(Rainy r[], int i, float b) {
ellipseMode(CENTER);
for (int j=2; j>0; j--) {
fill(0, 0, b);
stroke(0, 0, (3-j)*((150-b)/3+b));
ellipse(r[i].getX(), r[i].getY()+40, 30*j, 10*j);
}
}
void mousePressed() {
count++;
}
float y=0.0;
float dy=0.5;
int t=1, b=150;
void draw() {
if (count%3==0) {
if (b>50) {
b-=t;
}
background(0, 0, b);
for (int i=0; i<l; i++) {
if (y>height-30) {
//print(y+" "+dy);
y=0;
dy=0.5;
wave(r, i, b);
}
dy+=0.2;
y+=dy;
r[i].setY(y);
r[i].Shape();
}
} else if (count%3==1) {
background(0, 0, b);
for (int i=0; i<l; i++) {
fill(0, 0, 150);
stroke(255);
ellipse(r[i].getX(), r[i].getY(), 20, 20);
}
} else {
if (b<150) {
b+=t;
}
background(0, 0, b);
for (int i=0; i<l; i++) {
if (y<30) {
y=576.7;
dy=15.1;
}
dy-=0.2;
y-=dy;
r[i].setY(y);
r[i].RShape();
}
}
}