-
Notifications
You must be signed in to change notification settings - Fork 0
/
canvas.html
46 lines (35 loc) · 837 Bytes
/
canvas.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
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="400" height="400" style="border:1px solid #c3c3c3;">
Your browser does not support the canvas element.
</canvas>
<script type="text/javascript">
var x=50;
var y=50;
var rad=35;
var isGoingRight = 1;
function drawCircle() {
if(x > 365)
isGoingRight = 0;
else if(x < 35)
isGoingRight = 1;
if(isGoingRight)
x = x + 3;
else
x = x - 3;
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.clearRect(0,0,400,400); // clear canvas
ctx.fillStyle="#FF0000";
ctx.beginPath();
ctx.arc(x,y,rad,0,Math.PI*2,true);
ctx.arc(x,y+100,rad,0,Math.PI*2,true);
ctx.closePath();
ctx.fill();
}
setInterval(drawCircle,50);
</script>
</body>
</html>