-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsquare2.html
More file actions
73 lines (61 loc) · 1.35 KB
/
square2.html
File metadata and controls
73 lines (61 loc) · 1.35 KB
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
<!doctype HTML>
<html>
<head>
<style type="text/css">
#canvas{
position: absolute;
left: 50%;
margin-left: -300px;
top: 50%;
margin-top: -300px;
}
</style>
</head>
<body>
<canvas id="canvas" height="600px" width="600px"></canvas>
<script>
var c = document.getElementById("canvas");
var ctx = c.getContext("2d");
ctx.fillRect(0,0,c.width,c.height);
var triangleSize = 0;
var triangleStyle = 0;
var start = 600;
ctx.fillStyle = '#'+ Math.random().toString(16).slice(-6);
triangleFill();
function triangleFill(){
requestAnimationFrame(triangleFill);
drawTriangle(start,start, triangleSize,triangleStyle);
triangleSize += 15;
if(triangleSize > c.width*2){
ctx.fillStyle = '#'+ Math.random().toString(16).slice(-6);
triangleSize = 0;
if(triangleStyle == 0){
triangleStyle = 1;
start = 0;
}
else{
triangleStyle = 0;
start = 600;
}
}
}
function drawTriangle(x,y, size, type){
ctx.beginPath();
ctx.moveTo(x,y);
switch(type){
case 0: // up
ctx.lineTo(x,y-size);
ctx.lineTo(x-size, y);
ctx.lineTo(x,y);
break;
case 1: // down
ctx.lineTo(x+size,y);
ctx.lineTo(x,y+size);
ctx.lineTo(x,y);
break;
}
ctx.fill();
}
</script>
</body>
</html>