-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
33 lines (28 loc) · 805 Bytes
/
script.js
File metadata and controls
33 lines (28 loc) · 805 Bytes
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
var cells = [];
var size = 10;
window.onload = initiate;
function initiate () {
var theTable = document.createElement('table');
for (var i = 0; i < size; i++)
theTable.appendChild(createRow(i));
document.body.appendChild(theTable);
startAnimation();
}
function createRow (j) {
var newRow = document.createElement('tr');
for (var i = 0; i < size; i++) {
cells[(j * size) + i] = document.createElement('td');
newRow.appendChild(cells[(j * size) + i]);
}
return newRow;
}
function startAnimation () {
setInterval(triggerCell, 10);
}
function triggerCell () {
cells[Math.floor(Math.random() * size * size)].style.background = 'rgb('
+ Math.floor(Math.random() * 256) + ','
+ Math.floor(Math.random() * 256) + ','
+ Math.floor(Math.random() * 256)
+ ')';
}