-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSymmetries.js
125 lines (111 loc) · 2.76 KB
/
Symmetries.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
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
class TranslationSymmetry extends Renderable {
render(newState) {
this.setRenderState(newState);
const {
Element,
max,
startX,
startY,
direction = 'x',
spacing = 10,
rotation,
} = this.state;
for (let translation = 0; translation <= max; translation += spacing) {
const renderState = {
startY: direction === 'y' ? startY + translation : startY,
startX: direction === 'x' ? startX + translation : startX,
}
// hacky af
if (rotation) {
renderState.rotation = rotation;
}
Element.render(renderState);
}
}
}
class PlanarSymmetry extends Renderable {
render(newState) {
this.setRenderState(newState);
const {
Element,
maxX,
maxY,
startX,
startY,
spacingX = 10,
spacingY = 10,
rotation
} = this.state;
const RowTransSymmetry = new TranslationSymmetry({
Element,
max: maxX,
spacing: spacingX,
startX,
startY,
rotation
});
const ColumnTransSymmetry = new TranslationSymmetry({
Element: RowTransSymmetry,
max: maxY,
spacing: spacingY,
startX,
startY,
direction: 'y'
})
ColumnTransSymmetry.render()
}
}
class ReflectionSymmetry extends Renderable {
render(newState) {
this.setRenderState(newState);
const {
Element,
startX,
startY,
spacing = 10,
rotation,
} = this.state;
Element.render({
startX,
startY,
rotation
});
push()
// why need to add this 10?
translate(spacing + 10, 0)
scale(-1, 1)
Element.render({
startX: -startX,
startY,
rotation
})
pop()
}
}
class RotationSymmetry extends Renderable {
render(newState) {
this.setRenderState(newState);
const {
Element,
startX,
startY,
order = 2,
radius,
elementHeight,
rotation,
} = this.state;
const angle = 360 / order;
push()
translate(startX, startY)
for (let i = 0; i < order; i++) {
Element.render({
startX: 0,
startY: 0,
rotation
})
translate(radius * 2, -elementHeight)
rotate(angle)
}
pop()
}
}