-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
02_black_and_red.html
96 lines (81 loc) · 2.2 KB
/
02_black_and_red.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
<!doctype html>
<html lang="en">
<head>
<title>Tween.js / Black and Red</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="css/style.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="info">
<h1><a href="http://github.com/tweenjs/tween.js">tween.js</a></h1>
<h2>02 _ Black and red</h2>
<p>4096 continuously changing color cells (in a 64x64 table)</p>
<p></p>
</div>
<div id="target"></div>
<style>
body {
font-family: Arial, Helvetica, sans;
}
table {
border-collapse: collapse;
}
td {
width: 5px;
height: 5px;
}
#target {
position: absolute;
top: 4em;
right: 3em;
}
</style>
<script src="js/stats.min.js"></script>
<script type="module">
import * as TWEEN from '../dist/tween.esm.js'
const group = new TWEEN.Group()
const target = document.getElementById('target')
const stats = new Stats()
target.appendChild(stats.domElement)
const t = document.createElement('table')
let index = 0
for (let i = 0; i < 64; i++) {
const tr = t.insertRow(-1)
for (let j = 0; j < 64; j++) {
const td = tr.insertCell(-1)
td.style.background = '#000'
const x = (i + j) * 0.1
const cell = {td: td, value: 0}
const tween = new TWEEN.Tween(cell)
.to({value: 1}, 8000)
.delay((0.001 * index + Math.random()) * 500)
.easing(TWEEN.Easing.Elastic.InOut)
.onUpdate(function (object) {
const c = Math.floor(object.value * 0xff)
object.td.style.background = 'rgb(' + c + ', 0, 0)'
})
const tweenBack = new TWEEN.Tween(cell)
.to({value: 0}, 4000)
.delay((0.001 * index + Math.random()) * 500)
.easing(TWEEN.Easing.Elastic.InOut)
.onUpdate(function (object) {
const c = Math.floor(object.value * 0xff)
object.td.style.background = 'rgb(' + c + ', 0, 0)'
})
tween.chain(tweenBack)
tweenBack.chain(tween)
group.add(tween, tweenBack)
tween.start()
index++
}
}
target.appendChild(t)
animate()
function animate(time) {
requestAnimationFrame(animate)
group.update(time)
stats.update()
}
</script>
</body>
</html>