-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcanvas.html
40 lines (39 loc) · 945 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<canvas id="canvas"></canvas>
<script>
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext("2d");
var radius = 50;
var x = 0;
var y = 0;
var angle =0;
var width = canvas.width = window.innerWidth;
var height = canvas.height = window.innerHeight;
var centerx = width/2;
var centery = height/2;
ctx.save();
ctx.beginPath();
ctx.translate(centerx,centery);
ctx.restore();
function draw(){
requestAnimationFrame(draw);
ctx.clearRect(0,0,width,height);
ctx.save();
ctx.translate(centerx,centery+Math.sin(angle)*50);
ctx.fillStyle="orange";
ctx.beginPath();
ctx.arc(0,0,radius,0,Math.PI*2,false);
ctx.fill();
ctx.restore();
angle+=0.1;
}
draw();
</script>
</body>
</html>