-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcanvas.html
More file actions
35 lines (26 loc) · 752 Bytes
/
Copy pathcanvas.html
File metadata and controls
35 lines (26 loc) · 752 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
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="1000" height="600" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML canvas tag.</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
console.log("canvas size: " + c.width + "x" + c.height + "[px]");
var colors = ["pink", "blue", "yellow", "white", "purple", "red", "green"];
var colorIdx = 0;
changeColor();
function changeColor() {
if (colorIdx >= colors.length)
return;
document.body.bgColor = colors[colorIdx];
setTimeout(function() {
ctx.fillStyle = colors[colorIdx];
ctx.fillRect(0,0,c.width, c.height);
++colorIdx;
setTimeout(changeColor, 1000);
}, 1000);
}
</script>
</body>
</html>