Rotate Image

Hello, I was given a problem and I can't tell if I'm on the right track. I'm stuck at the rotate part. Can someone help?

Create a script that lets you rotate an image through some number of degrees
(out of a maximum of 360 degrees). The script should let you specify that you want to spin
the image continuously. It should let you adjust the spin speed dynamically.

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
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<title>Final</title>
</head>
<body>
<canvas id = "drawRectangle" width = "200" height = "200"
style = "border: 5px solid black;">
</canvas>
<script>
var canvas = document.getElementById("drawRectangle");
var context = canvas.getContext("2d")
function startRotating()
{
context.translate(canvas.width / 2, canvas.height / 2);
setInterval(rotate, 0);
}
function rotate()
{
context.clearRect(-100, -100, 200, 200);
context.rotate(Math.PI / 360);
context.fillStyle = "black";
context.fillRect(-50, -50, 100, 100);
}
window.addEventListener("load", startRotating, false);
</script>
</body>
</html>
This is a C++ forum.
I'm sorry, I completely forgot it was html. My mind is getting mixed up
Topic archived. No new replies allowed.