-
Notifications
You must be signed in to change notification settings - Fork 6
/
brick.js
46 lines (41 loc) · 1008 Bytes
/
brick.js
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
function Brick(pos, r) {
if (pos) {
this.pos = pos.copy();
} else {
this.pos = createVector(random(100, width - 100), random(100, height - 400));
}
if (r) {
this.r = r * 0.5;
} else {
this.r = random(20, 80);
}
this.total = 6;
this.offset = [];
this.index = Math.floor(random(5));
this.colors = ['#6CD9CC', '#FB6578', '#FE5A8F', '#FC9574', '#9A8DF2'];
this.miniDrops = [];
this.display = function() {
push();
stroke(this.colors[this.index]);
strokeWeight(2);
translate(this.pos.x, this.pos.y);
beginShape();
for (var i = 0; i < this.total; i++) {
var angle = map(i, 0, this.total, 0, TWO_PI);
var r = this.r;
var x = r * cos(angle);
var y = r * sin(angle);
vertex(x, y);
}
endShape(CLOSE);
stroke(0);
strokeWeight(1);
pop();
}
this.shrink = function() {
var newB = [];
newB[0] = new Brick(this.pos, this.r);
// newB[1] = new Brick(this.pos, this.r);
return newB;
}
}