-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshapes.js
More file actions
134 lines (130 loc) · 2.67 KB
/
shapes.js
File metadata and controls
134 lines (130 loc) · 2.67 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
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
133
134
class Shape {
constructor(x, y, colr = null) {
this.color = color(colr);
this.colorName = colr;
this.stroke = 0;
this.x = x;
this.y = y;
this.collected = false;
this.collectedIn = 0;
}
draw(size) {}
drawSmall = pushWrap(() => {
strokeWeight(2.5);
fill(200);
circle(0, 0, 0.625 * squareSize);
strokeWeight(1);
this.draw(0.4 * squareSize);
});
drawMed() {
this.draw(0.75 * squareSize);
}
drawLarge() {
this.draw(1.5 * squareSize);
}
renderBoard() {
this.drawMed();
}
dim(alph) {
this.color = setAlpha(this.color, alph);
this.stroke = map(alph, 0, 100, 255, 0);
}
undim() {
this.dim(255);
}
reset() {
this.collected = false;
this.collectedIn = 0;
}
}
class Triangle extends Shape {
constructor(x, y, color) {
super(x, y, color);
}
draw = pushWrap((size) => {
fill(this.color);
stroke(this.stroke);
triangle(
0,
-size / 2,
-(1 / sqrt(3)) * size,
size / 2,
(1 / sqrt(3)) * size,
size / 2
);
});
}
class Square extends Shape {
constructor(x, y, color) {
super(x, y, color);
}
draw = pushWrap((size) => {
fill(this.color);
stroke(this.stroke);
rect(-size / 2, -size / 2, size, size);
});
}
class Circle extends Shape {
constructor(x, y, color) {
super(x, y, color);
}
draw = pushWrap((size) => {
fill(this.color);
stroke(this.stroke);
circle(0, 0, size);
});
}
class Star extends Shape {
constructor(x, y, color) {
super(x, y, color);
}
draw = pushWrap((size) => {
fill(this.color);
stroke(this.stroke);
rotate(-PI / 2);
beginShape();
let x, y;
let increment = TWO_PI / 5;
for (let a = 0; a <= TWO_PI; a += increment) {
x = cos(a) * 0.6 * size;
y = sin(a) * 0.6 * size;
vertex(x, y);
x = cos(a + increment / 2) * 0.2 * size;
y = sin(a + increment / 2) * 0.2 * size;
vertex(x, y);
}
endShape();
});
}
class Block extends Shape {
constructor(x, y, color) {
super(x, y, color);
}
draw = pushWrap((size) => {
fill(this.color);
stroke(this.stroke);
rect(-size / 2, -size / 2, size);
});
}
class Burst extends Shape {
constructor(x, y, color) {
super(x, y, color);
}
draw = pushWrap((size) => {
let alph = 0.66 * alpha(this.color);
let colors = [
color(255, 0, 0, alph),
color(79, 0, 153, alph),
color(0, 119, 255, alph),
color(0, 153, 192, alph),
color(245, 126, 0, alph),
color(0, 0, 0, 100),
];
colors.forEach((color) => {
fill(color);
stroke(this.stroke);
ellipse(0, 0, size, size / 4);
rotate(PI / 6);
});
});
}