-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
123 lines (96 loc) · 3.44 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>Glitter</title>
<style>
body {
margin: 0;
}
</style>
</head>
<body>
<script src="js/three.js"></script>
<script>
var scene = new THREE.Scene();
var frontSpot = new THREE.SpotLight(0xeeeece);
frontSpot.position.set(1000, 1000, 1000);
scene.add(frontSpot);
var frontSpot2 = new THREE.SpotLight(0xddddce);
frontSpot2.position.set(-300, -300, -300);
scene.add(frontSpot2);
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
class Paillette extends THREE.Mesh {
constructor(i, j, k) {
super();
let material = new THREE.MeshPhongMaterial({
color: this.createRandomColor(),
specular: this.createRandomColor(),
});
let geometry = new THREE.CircleGeometry(0.1, 32);
this.geometry = geometry;
this.material = material;
this.position.x = i;
this.position.y = j;
this.position.z = k;
this.floatingToLeft = true;
}
createRandomColor() {
return Math.floor(Math.random() * 16777215);
}
float() {
let random = Math.floor(Math.random() * Math.floor(2));
if (this.floatingToLeft) {
if (random === 0) {
this.position.x -= Math.random() * 0.1;
}
if (random === 1) {
this.position.y -= Math.random() * 0.03;
}
if (random === 2) {
this.position.z -= Math.random() * 0.1;
}
}
else {
if (random === 0) {
this.position.x += Math.random() * 0.1;
}
if (random === 1) {
this.position.y += Math.random() * 0.03;
}
if (random === 2) {
this.position.z += Math.random() * 0.1;
}
}
this.rotation.x += 0.11;
this.rotation.y += 0.11;
this.rotation.z += 0.11;
}
}
var pailletteArray = [];
for (var k = 0; k < 100; k = k + 6) {
for (var j = 0; j < 100; j = j + 9) {
for (var i = 0; i < 5; i = i + 0.1) {
const pa = new Paillette(i, j, k);
scene.add(pa);
pailletteArray.push(pa);
}
}
}
render();
camera.position.z = 25;
function render() {
requestAnimationFrame(render);
for (var u = 0; u < pailletteArray.length; u++) {
pailletteArray[u].float();
if (pailletteArray[u].position.x < -5 || pailletteArray[u].position.x > 5) {
pailletteArray[u].floatingToLeft = !pailletteArray[u].floatingToLeft;
}
}
renderer.render(scene, camera);
}
</script>
</body>
</html>