This repository has been archived by the owner on May 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (61 loc) · 1.65 KB
/
index.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
const TOTAL_DEGREES = 360
const STEP_DEGREES = 15
const STEPS = 350
const PI = 3.14159
const SPEED = 1.5
const width = window.innerWidth / 2
const height = window.innerHeight / 2
const initialRadius = window.innerWidth / 2
noise.seed(Math.random())
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(
30,
window.innerWidth / window.innerHeight,
1,
1000
)
camera.position.set(0, 0, 1000)
camera.lookAt(new THREE.Vector3(0, 0, 0))
const renderer = new THREE.WebGLRenderer()
renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild(renderer.domElement)
const material = new THREE.LineBasicMaterial({
color: 0xffffff,
opacity: 0.1,
transparent: true,
linewidth: 3
})
function updateScene(frameCount) {
scene.remove(...scene.children)
const geometry = new THREE.Geometry()
const line = new THREE.Line(geometry, material)
for (let step = 0; step < STEPS; step++) {
const p = step / STEPS
const radius = initialRadius * (p - 0.5)
for (let i = 0; i <= TOTAL_DEGREES; i += STEP_DEGREES) {
const noiseFactor = noise.perlin3(
i / (STEPS / 2),
step / (STEPS / 4),
frameCount / 200 * SPEED
)
const x = radius * Math.cos(i / 360 * PI) * noiseFactor
const y = radius * Math.sin(i / 360 * PI) * noiseFactor
geometry.vertices.push(
new THREE.Vector3(
x + p * width - width / 2,
y + p * height - height / 2,
0
)
)
}
}
scene.add(line)
}
function loop(frameCount = 0) {
requestAnimationFrame(() => {
updateScene(frameCount)
renderer.render(scene, camera)
loop(frameCount + 1)
})
}
loop()