Spiro 1

Yet another spirograph/Lissajous figure style stacked oscillations.

Was trying to make something else specific, but in the process of playing with params and getting distracting got this.

Some variants:
// Spiro 1 (variation)
// Spiro 1 (variation)
// Spiro 1 (variation)
// Spiro 1 (variation)
// Spiro 1 (variation)
// Spiro 1 (variation)
// Spiro 1 (variation)

Log in to post a comment.

// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(1);

let stepMul=256;// min=2 max=512 step=1
let offset=1.2; // min=-2 max=2 step=0.1
let length=21; // min=1 max=200 step=1
let extraRot=0; // min=-360 max=360 step=5
let mulX=0.7; // min=0.1 max=3 step=0.1
let mulY=0.7;// min=0.1 max=3 step=0.1
let zfreq=0.39; // min=0.1 max=10 step=0.01
let h=0.0; // min=0.0 max=200 step=0.1
let rs=2.15; // min=0.1 max=10 step=0.01
let lift=0; // min=0, max=1, step=1 (No, Yes)

// Global code will be evaluated once.
const turtle = new Turtle();
turtle.penup();


function f(i, down) {
    let x = Math.cos(2 * Math.PI * i / stepMul) + offset;
    let y = Math.sin(2 * Math.PI  * i / stepMul);
    
    
    let rotk = Math.PI * 2 * (Math.floor((i + (down ? 0 : -1)) / stepMul) * rs);
    let xt=x;
    let yt=y;
    x = Math.cos(rotk)*xt-Math.sin(rotk)*yt; // buggy implementation of rotation but it makes interesting effect
    y = Math.sin(rotk)*xt-Math.cos(rotk)*yt;
    xt=x;
    yt=y;
    let realRot = 2 * Math.PI * extraRot/360;
    x = Math.cos(realRot)*xt-Math.sin(realRot)*yt;
    y = Math.sin(realRot)*xt+Math.cos(realRot)*yt;
    
    
    let t = (1+Math.cos(zfreq * 2 * Math.PI * i / stepMul))*0.5;
    let w = 1;//t;
    let z = (1-Math.cos(t * Math.PI*0.5))*0.5;
    
    x *= w * 50 * mulX;
    y *= w * 50 * mulY;
    y += (-z * h);
    
    turtle.goto(x, y);
}
// The walk function will be called until it returns false.
function walk(i) {
    let i2 = i-1;
   
    let first = ((i2 % stepMul) == 0);
    let last = (((i2+1) % stepMul) == 0);
    
    f(i2, true);
    if (first) { turtle.pendown(); } 
    if (last) {
        f(i2+1, false);
        if (lift) {
            turtle.penup();
        }
    }

    return i < length * stepMul;
}