-
Notifications
You must be signed in to change notification settings - Fork 0
/
colors.html
55 lines (46 loc) · 2.24 KB
/
colors.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Colors</title>
<script>
function drawColorPalette(colorFocus) {
const canvas = document.getElementById(`${colorFocus}ColorPalette`);
const ctx = canvas.getContext("2d");
const pixelData = ctx.createImageData(canvas.height, canvas.width);
const time = new Date().getTime();
const i = parseInt(Math.sin(time / 1000) * 255);
ctx.clearRect(0, 0, 255, 255);
for (let j = 0; j < pixelData.height; j++) {
for (let k = 0; k < pixelData.width; k++) {
const length = j * (pixelData.width * 4) + k * 4;
if (colorFocus === "red") {
pixelData.data[length] = i;
pixelData.data[length + 1] = j;
pixelData.data[length + 2] = k;
} else if (colorFocus === "green") {
pixelData.data[length] = j;
pixelData.data[length + 1] = i;
pixelData.data[length + 2] = k;
} else {
pixelData.data[length] = j;
pixelData.data[length + 1] = k;
pixelData.data[length + 2] = i;
}
pixelData.data[length + 3] = 255;
}
}
ctx.putImageData(pixelData, 0, 0);
requestAnimationFrame(() => drawColorPalette(colorFocus));
}
const redColorPalettePixelTimer = requestAnimationFrame(() => drawColorPalette("red"));
const greenColorPalettePixelTimer = requestAnimationFrame(() => drawColorPalette("green"));
const blueColorPalettePixelTimer = requestAnimationFrame(() => drawColorPalette("blue"));
</script>
</head>
<body>
<canvas id="redColorPalette" width="256" height="256"></canvas>
<canvas id="greenColorPalette" width="256" height="256"></canvas>
<canvas id="blueColorPalette" width="256" height="256"></canvas>
</body>
</html>