-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvas2.html
47 lines (32 loc) · 891 Bytes
/
canvas2.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
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="1280" height="720" 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 = ["yellow", "lightgreen"];
var colorIdx = 0;
var sizesW = [ "500", "720" ];
var sizesH = [ "720", "500" ];
var sizesIdx = 0;
changeColor();
function changeColor() {
if (colorIdx >= colors.length)
return;
resizeCanvas();
ctx.fillStyle = colors[colorIdx];
ctx.fillRect(0,0,c.width, c.height);
colorIdx = (colorIdx + 1) % colors.length;
setTimeout(changeColor, 100);
}
function resizeCanvas() {
c.width = sizesW[sizesIdx];
c.height = sizesH[sizesIdx];
sizesIdx = (sizesIdx + 1) % 2;
}
</script>
</body>
</html>