-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
56 lines (45 loc) · 1.48 KB
/
app.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
import Snap from 'snapsvg'
import css from './s.css'
import mp3 from './art.mp3'
const modulo = 200
const padding = 20
const radius = (Math.min(window.innerHeight, window.innerWidth) / 2 - padding)
const circleCenterX = radius + (padding / 2)
const circleCenterY = radius + (padding / 2)
const surfaceSize = 2 * radius
const surface = Snap(surfaceSize + padding, surfaceSize + padding)
const pythagDistance = (aX, aY, bX, bY) => {
const a = aX - bX
const b = aY - bY
return Math.sqrt(a * a + b * b)
}
const joinTwoNumbers = (a, b) => {
const [aX, aY] = getCoordForNumber(a)
const [bX, bY] = getCoordForNumber(b)
let color = pythagDistance(aX, aY, bX, bY)
color %= 360
color /= 360
surface.line(aX, aY, bX, bY).attr({
stroke: `hsl(${color}, 100%, 50%)`,
strokeWidth: 1,
strokeLinecap: 'round'
})
}
const getCoordForNumber = (number) => {
// subtracting 180 deg here to have 0 be on the left instead of the right
const angle = ((number / modulo) * 360) - 180
const x = circleCenterX + radius * Math.cos(-angle * Math.PI / 180)
const y = circleCenterY + radius * Math.sin(-angle * Math.PI / 180)
return [x, y]
}
let factor = 1
const draw = () => {
surface.clear()
for (let i = 0; i < modulo; i++) {
joinTwoNumbers(i, i * factor % modulo)
}
// const [intPart, decimal] = `${factor}`.split('.')
// surface.text(5, 15, `Factor: ${intPart}${decimal ? '.' + decimal.charAt(0) : ''}`)
factor += 0.005
}
setInterval(() => Promise.resolve().then(draw), 100)