-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
114 lines (87 loc) · 2.35 KB
/
index.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<html>
<head>
<title>rgb canvas</title>
</head>
<body>
<canvas id="canvas">
<style>
html, body {
overflow: visible;
}
</style>
<script>
function init()
{
canvas = document.getElementById("canvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvasW = canvas.width;
canvasH = canvas.height;
canvasWa = canvasW - 50.5;
canvasHa = canvasH - 50.5;
console.log(canvasW + " * " + canvasH);
}
init();
var c = document.getElementById("canvas");
var ctx = c.getContext("2d");
ctx.strokeStyle = "#000000";
ctx.moveTo(0, 0);
ctx.lineTo(0, canvasHa);
for(i=0.5; i < canvasHa; i += 10) {
ctx.moveTo(0, i);
ctx.lineTo(5, i);
}
ctx.moveTo(0, 0);
ctx.lineTo(canvasWa , 0);
for(i=0.5; i < canvasWa; i += 10) {
ctx.moveTo(i, 0);
ctx.lineTo(i, 5);
}
ctx.font = "bold 12px sans-serif";
ctx.fillText("x", canvas.width - 50, 10);
ctx.fillText("y", 10, canvas.height - 50);
ctx.stroke();
var go = true;
(async function(){
while(!go)
{
await new Promise(r => setTimeout(r, 300));
}
ctx.clearRect(0, 0, canvas.width, canvas.height);
r = Math.floor(255 * Math.random());
g = Math.floor(255 * Math.random());
b = Math.floor(255 * Math.random());
cr = "#" + (r << 16).toString(16);
cg = "#00" + (g << 8).toString(16);
cb = "#0000" + b.toString(16);
c = "#" + r.toString(16) + g.toString(16) + b.toString(16);
ctx.fillStyle = cr
ctx.fillRect(20.5, 20.5, 100, canvasHa);
//ctx.strokeRect(20.5, 20.5, 100, canvasHa);
ctx.fillStyle = "#000000";
ctx.fillText(cr, 50, canvasHa + 40);
ctx.fillStyle = cg;
ctx.fillRect(140.5, 20.5, 100, canvasHa);
//ctx.strokeRect(140.5, 20.5, 100, canvasHa);
ctx.fillStyle = "#000000";
ctx.fillText(cg, 170, canvasHa + 40);
ctx.fillStyle = cb;
ctx.fillRect(260.5, 20.5, 100, canvasHa);
//ctx.strokeRect(260.5, 20.5, 100, canvasHa);
ctx.fillStyle = "#000000";
ctx.fillText(cb, 290, canvasHa + 40);
ctx.fillStyle = c;
ctx.fillRect(500.5, 20.5, 100, canvasHa);
ctx.fillStyle = "#000000";
//ctx.strokeRect(500.5, 20.5, 100, canvasHa);
setTimeout(arguments.callee, 300);
})();
document.body.onkeydown = function(e){
if(e.keyCode == 32){
go = !go;
}
}
</script>
</body>
</html>