TurtleToy Code to Draw an Epicycloid
Log in to post a comment.
// TurtleToy Code to Draw an Epicycloid Canvas.setpenopacity(1); const turtle = new Turtle(); // User-defined parameters const directrixRadius = 200; // min=0 max=200 step=1 // Radius of the fixed circle const epicycleRadius = 20; // min=0 max=100 step=5 // Radius of the rolling circle const numberOfSegments = 300; // min=0 max=300 step=1; // Increase for a smoother curve const size = 0.3; // min=0.1 max=1 step=0.1 // Scaling factor for the overall size // Function to draw the Epicycloid function drawEpicycloid() { for (let i = 0; i <= numberOfSegments; i++) { const angle = i * 2 * Math.PI / numberOfSegments; const x = (directrixRadius + epicycleRadius) * Math.cos(angle) - epicycleRadius * Math.cos(((directrixRadius + epicycleRadius) / epicycleRadius) * angle); const y = (directrixRadius + epicycleRadius) * Math.sin(angle) - epicycleRadius * Math.sin(((directrixRadius + epicycleRadius) / epicycleRadius) * angle); if (i === 0) { turtle.jump(x * size, y * size); } else { turtle.goto(x * size, y * size); } } } // Draw the Epicycloid drawEpicycloid(); function loop() { return false; }