Fork: Lissajous curves

Some Lissajous curves: en.wikipedia.org/wiki/lissajous_curve
Please note that some of these patterns are repeated and may cause a plotter to overwrite the same point multiple times. I am going to see if I can adapt this code to prevent this.

Log in to post a comment.

// Forked from "Lissajous curves" by reinder
// https://turtletoy.net/turtle/982e9ce2ae

// Lissajous curves. Created by Reinder Nijhoff 2018
// @reindernijhoff
//
// https://turtletoy.net/turtle/982e9ce2ae
//

Canvas.setpenopacity(1);
const count=16; //min=4 max=20 step=1

const div = count;
const steps = 60;//min=10 max=60 step=1
const turtles = [];
const scale = 200; //min=50 max=200 step=1

for (let x=0; x<div; x++) {
    for (let y=0; y<div; y++) {
        turtles.push(new Turtle((x + .5) * scale/div - scale/2, (y + .9) * scale/div - scale/2));
    }
}

function walk(i) {
    for (let x=0; x<div; x++) {
        for (let y=0; y<div; y++) {
            turtles[y+x*div].goto( 
                (x + .5 + .4 * Math.sin((x+1)*i*2*Math.PI/steps)) * scale/div - scale/2, 
                (y + .5 + .4 * Math.cos((y+1)*i*2*Math.PI/steps)) * scale/div - scale/2);
        }
    }
    return i < steps;
}