Spirographs!

  • Parameters:

  • Fun stuff:

  • Press "?" to see keyboard shortcuts
    In inputs:
  • Up/Down: Increment/Decrement by .01
  • Page Up/Page Down: Increment/Decrement by .1

  • Anywhere on page:
  • R: Randomize Everything
  • D: Start drawing
  • S: Stop drawing
  • U: Undo
// The Spirograph function definition
function drawSpirograph(canvas,R,r,O){
      var x1 = R-O;
      var y1 = 0;
      var i  = 1;
      canvas.beginPath();
      canvas.moveTo(x1,y1);
      do {
            if (i >  ) break;
            var x2 = (R+r)*Math.cos(i*Math.PI/72) 
                - (r+O)*Math.cos(((R+r)/r)*(i*Math.PI/72))
            var y2 = (R+r)*Math.sin(i*Math.PI/72) 
                - (r+O)*Math.sin(((R+r)/r)*(i*Math.PI/72))
            canvas.lineTo(x2,y2);
            x1 = x2;
            y1 = y2;
            i++;
          } while (x2 != R-O && y2 != 0 );
          canvas.stroke();
    }

// Calling the function
drawSpirograph(
      canvas,
       * (  ) / (  ),
       * (  ) / (  ),
      10
    );

// Thanks to MDN and the code examples on this page: Canvas Transformations
image here!