var b = document.getElementById("myCanvas"); var c = b.getContext("2d"); var step = 100; var angle = 0.01; var w = c.canvas.width; var h = c.canvas.height; var cmTID; c.translate(w / 2, h / 2); drawStep(); function drawStep() { c.clearRect(-w / 2, -h / 2, w, h); c.lineWidth = 3; c.strokeStyle = "#ffcd8a"; c.strokeRect(-20, -20, 40, 40); c.fillStyle = "#ffcd8a"; c.fillRect(10, 100, 50, 50); c.fillRect(-50, -70, 40, 40); c.fillRect(50, 30, 30, 30); c.rotate(angle); clearTimeout(cmTID); cmTID = setTimeout(drawStep, step); }