-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolours.html
78 lines (60 loc) · 1.7 KB
/
colours.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<style>
canvas {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
</style>
<body>
<canvas id="canvas">
</canvas>
<script>
const canvas = document.getElementById('canvas') // sets up our canvas a bit
const ctx = canvas.getContext('2d');
// const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let rectSize = 2;
let widthLimit = 400;
let t0 = new Date().getTime();
(function () {
let xpos = 0;
let ypos = 0;
let count = 0;
for (let r = 0; r <= 255; r+=8) {
for (let g = 0; g <= 255; g+=8) {
for (let b = 0; b <= 255; b+=8) {
rectangle = {
x: xpos,
y: ypos,
width: rectSize,
height: rectSize
}
ctx.fillStyle = `RGB(${r}, ${g}, ${b})`
ctx.fillRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height)
count += 1;
xpos = xpos + rectSize
if (xpos % widthLimit == 0) {
ypos += rectSize
xpos = 0
}
}
}
}
console.log(count);
})();
let t1 = new Date().getTime();
console.log(t1-t0)
</script>
</body>
</html>