MIT Licence
Log in to post a comment.
// TurtleToy Spirograph Script
// Initial spirograph from Chat GPT
// You can find the Turtle API reference here: https://turtletoy.net/syntax
// Released under the MIT licence
// https://mit-license.org/
// you can use this for commercial gain if you like eg you can sell artworks with this image.
turtle = new Turtle
var step = 0
// Adjust these values to change the appearance of the spirograph
const R = 22; // min=1 max=100 step=1 // Radius of fixed circle
const rMoving = 73.7; // min=1 max=100 step=0.1 // Radius of moving circle
const S =40; // min=1 max=100 step=1
const Steps = 437; // min=1 max=1000 step=1
// const grid = 12; // min=1 max=24 step=1
function spirograph(R, r, Scale) {
for (let t = 0; t < Steps; t += 0.1) {
// Parametric equations for spirograph
x = (R - rMoving) * Math.cos(t) + S * Math.cos((R - rMoving) * t / r);
y = (R - rMoving) * Math.sin(t) - S * Math.sin((R - rMoving) * t / r);
// Move the turtle to the calculated point
turtle.goto(x, y);
turtle.pendown();
}
}
turtle.penup();
spirograph(R, rMoving, S);