-
Notifications
You must be signed in to change notification settings - Fork 0
/
balloons.pde
97 lines (75 loc) · 2 KB
/
balloons.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
int r = 30;
int amount = 10;
int rad = 200;
Item items[] = new Item[amount];
void setup() {
size(900, 800, P2D);
noStroke();
smooth(8);
for(int i = 0; i < amount; i++) {
int randX = (int)random(r, width - r);
int randY = (int)random(r, height - r);
items[i] = new Item(randX, randY, r);
items[i].draw();
}
}
void draw() {
background(50);
for(int i = 0; i < items.length; i++) {
Item data = items[i];
float x = data.posX += data.vx;
float y = data.posY += data.vy;
if(x < data.R || x > (width - data.R)) data.setVelocity(-data.vx, data.vy);
if(y < data.R || y > (height - data.R)) data.setVelocity(data.vx, -data.vy);
// lines
for(int j = 0; j < i; j++) {
Item dataJ = items[j];
int distantion = (int)dist(data.posX, data.posY, dataJ.posX, dataJ.posY);
stroke(255);
if(distantion < rad) {
strokeWeight(map(distantion, 0, rad, 4, 0.5));
line(data.posX, data.posY, dataJ.posX, dataJ.posY);
}
}
data.update(data.posX, data.posY);
}
}
class Item {
int posX;
int posY;
int R;
color col;
float vx = random(1, 5);
float vy = random(1, 5);
Item(int posX, int posY, int R) {
this.posX = posX;
this.posY = posY;
this.R = R;
this.col = color(random(100, 255), random(100, 255), random(100, 255));
}
Item(int posX, int posY, int R, color col) {
this.posX = posX;
this.posY = posY;
this.R = R;
this.col = col;
}
void update(int posX, int posY) {
this.posX = posX;
this.posY = posY;
this.draw(posX, posY);
}
void setVelocity(float x, float y) {
this.vx = int(x);
this.vy = int(y);
}
void draw(int posX, int posY) {
fill(this.col);
noStroke();
circle(posX, posY, this.R);
}
void draw() {
fill(this.col);
noStroke();
circle(this.posX, this.posY, this.R);
}
}