-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlanet-Rotation.js
More file actions
54 lines (37 loc) · 836 Bytes
/
Planet-Rotation.js
File metadata and controls
54 lines (37 loc) · 836 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE html>
<html>
<head>
<title>Planet Rotation</title>
<style>
canvas {
border: 5px solid black;
}
</style>
</head>
<body>
<canvas id="canvas" width="500" height="500"></canvas>
<script>
var planet = {
x: 250,
y: 150,
radius: 50,
angle: 0,
speed: 0.02
};
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
function animate() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.beginPath();
ctx.arc(planet.x, planet.y, planet.radius, 0, Math.PI * 2);
ctx.fillStyle = 'blue';
ctx.fill();
planet.angle += planet.speed;
planet.x = 250 + 150 * Math.cos(planet.angle);
planet.y = 250 + 150 * Math.sin(planet.angle);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>