-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
42 lines (37 loc) · 855 Bytes
/
utils.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
export function getRandom(min, max) {
return Math.random() * (max - min) + min;
}
export function getDistances(w, h) {
const d0 = h / 2
const d1 = Math.sqrt(Math.pow(h / 2, 2) + Math.pow(w, 2))
const d2 = Math.sqrt(Math.pow(h / 2, 2) + Math.pow(w / 2, 2))
const d3 = 1.2 * h
return [
d0,
d1,
d2,
d3,
d2,
d1,
]
}
export function getAngles(w, h, rotation) {
const θa = Math.atan(w / ( h / 2 ))
const θb = Math.atan(w / h)
return [
0,
θa,
Math.PI - θb,
Math.PI,
Math.PI + θb,
(2 * Math.PI) - θa,
].map(angle => (angle + rotation) % (2 * Math.PI))
}
export function getPoints(x, y, distances, angles) {
return distances.map((distance, index) => {
return {
x: x + (Math.cos(angles[index]) * distance),
y: y + (Math.sin(angles[index]) * distance),
}
})
}