Based on code from Chat GPT3
rupert.id.au/js/001.html
Log in to post a comment.
// Based on code from Chat GPT3 see rupert.id.au/js/001.html
// 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.
// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(1);
// Global code will be evaluated once.
const turtle = new Turtle();
const OuterCircle=42; //min=1 max=100 step=1
const O=24; //min=-100 max=100 step=1
const count=6; //min=2 max=50 step=1
var r = OuterCircle / count;
const xOffset=0; // //min=-100 max=100 step=1
const yOffset=0; // //min=-100 max=100 step=1
drawSpirograph(OuterCircle, r, O, xOffset, yOffset);
function drawSpirograph(R, r, O, xO, yO) {
for (let t = 0; t < 2 * Math.PI; t += 0.001) {
const x = (R - r) * Math.cos(t) + O * Math.cos((R - r) / r * t) + xOffset;
const y = (R - r) * Math.sin(t) - O * Math.sin((R - r) / r * t) + yOffset;
if (t === 0) {
turtle.jump(x, y);
} else {
turtle.goto(x, y);
}
}
}