-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElements.js
More file actions
72 lines (59 loc) · 1.49 KB
/
Elements.js
File metadata and controls
72 lines (59 loc) · 1.49 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
class TextElement {
constructor(text = 'TEST') {
this.text = text;
}
render({ startX = 10, startY = 10, rotation = 0 }) {
push()
translate(startX, startY)
rotate(rotation)
text(this.text, 0, 0)
pop()
}
}
class EllipseElement extends Renderable {
render(newState) {
this.state = {...this.state, ...newState};
const {
startX = 0,
startY = 0,
width = 10,
height = 10
} = this.state;
ellipse(startX, startY, width, height)
}
}
class RectElement extends Renderable {
render(newState) {
this.state = {...this.state, ...newState};
const {
startX = 0,
startY = 0,
width = 10,
height = 10
} = this.state;
rect(startX, startY, width, height)
}
}
class PolygonElement extends Renderable {
render(newState) {
this.state = {...this.state, ...newState};
const {
startX = 0,
startY = 0,
radius = 20,
sides = 6,
rotation = 0
} = this.state;
push();
translate(startX, startY);
rotate(rotation)
const rotAngle = 360 / sides;
beginShape();
for (let i = 0; i < sides; i++) {
const thisVertex = pointOnCircle(0, 0, radius / 2, i * rotAngle)
vertex(thisVertex.x, thisVertex.y)
}
endShape(CLOSE)
pop()
}
}