-
Notifications
You must be signed in to change notification settings - Fork 0
/
static3.html
66 lines (52 loc) · 1.24 KB
/
static3.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Attempt 3</title>
<style type="text/css">
html, body {
margin: 0px;
background-color: #111;
width: 100%;
height: 100%;
overflow: hidden;
}
</style>
</head>
<body>
<canvas id='canvas'></canvas>
</body>
<script type="text/javascript">
async function noise() {
let h = window.innerHeight;
let w = window.innerWidth;
let canvas = document.getElementById('canvas');
canvas.height = h;
canvas.width = w;
let ctx = canvas.getContext('2d');
let pixels = []
for (let y=0; y<h; y+=1) {
for (let x=0; x<w; x+=1) {
pixels.push([x,y]);
}
}
while (pixels.length > 0) {
let i = Math.floor(Math.random()*pixels.length);
let pixel = pixels[i];
let color = Math.random().toString(16).slice(-6);
ctx.fillStyle = '#' + color;
ctx.fillRect(pixel[0], pixel[1], 1, 1);
pixels.splice(i, 1);
if (pixels.length % 1000 == 0) {
await drawPixels();
}
}
}
function drawPixels() {
return new Promise(resolve => setTimeout(resolve, 0));
}
window.onresize = noise;
window.onload = noise;
window.onclick = noise;
</script>
</html>