Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Multiple Rotating Objects witg Fixed Positions || Canvas

Hello there, I have created this rotating object (black) and I wish to have one object more that rotates (orange). My problem is that the Orange extends the black instead of having it's own center. It should look like two clocks next to each others.

Anyone who knows how to fix this? I've tried translate(), save(), restore(), etc. Thanks!

Here's my code so far:

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
    body {
        margin: 40px; background:#666;
    }
    #my_canvas {
        background:#fff; border:#000 1px solid;
    }
</style>
<script>
    function draw(){

        var canvas = document.getElementById("my_canvas");
        var ctx    = canvas.getContext("2d");
        ctx.translate(ctx.canvas.width/3, ctx.canvas.height/2);
        var degree = (Math.PI / 180) * 1;

        function spinnBall(){

            // Black rotating Object 
            ctx.beginPath();
            ctx.strokeStyle = "black";
            ctx.moveTo(0, 0);
            ctx.lineTo(100, 0);
            ctx.lineWidth = 1;
            ctx.stroke();

            // Orange rotating Object
            ctx.beginPath();
            ctx.strokeStyle = "orange";
            ctx.moveTo(100, 0);
            ctx.lineTo(200, 0);
            ctx.lineWidth = 1;
            ctx.stroke();
            ctx.rotate(degree);
        }
        var iv = setInterval(spinnBall, 25);
    }
    window.onload = draw;

</script>
</head>
<body>
<canvas id="my_canvas" width="500" height="500">
</canvas>
</body>
</html>