Jiggle Tortoise

jiggle wiggle gyroid siggle

Make your turtles scribbly by adding this tortoise transform
#tortoise

Log in to post a comment.

const turtle = new Tortoise();

const xOffset = 1.85; //min=0, max=20, step=0.01
const yOffset = 0.1; //min=0, max=20, step=0.01
const amp = 1.5; //min=0, max=20, step=0.01
turtle.addTransform(GyroidScribble(xOffset, yOffset, amp));


// draw something
const size = 85; // min=10, max=100, step=10
const totalCircles = 4; // min=1, max=20, step=1
function walk(i) {
    turtle.jump(0, -i * 10/totalCircles * size/10);
    turtle.circle(i * 10/totalCircles * size/10);
    return i < totalCircles;
}


////////////////////////////////////////////////////////////////
// GyroidScribble code. Created by Mark Knol 2026
// https://turtletoy.net/turtle/f05e740f76
////////////////////////////////////////////////////////////////

function gyroid (x, y, z) { 
    return Math.sin(x) * Math.cos(y) + Math.sin(y) * Math.cos(z) + Math.sin(z) * Math.cos(x);
}
function GyroidScribble(x, y, amp) {
  return p => [
    p[0] + (-0.5 + gyroid(p[0], p[1], x) * amp),
    p[1] + (-0.5 + gyroid(p[0], p[1], y) * amp),
  ];
}


////////////////////////////////////////////////////////////////
// Tortoise utility code. Created by Reinder Nijhoff 2019
// https://turtletoy.net/turtle/102cbd7c4d
////////////////////////////////////////////////////////////////

function Tortoise(x, y) {
    class Tortoise extends Turtle {
        constructor(x, y) {
            super(x, y);
            this.ps = Array.isArray(x) ? [...x] : [x || 0, y || 0];
            this.transforms = [];
        }
        addTransform(t) {
            this.transforms.push(t);
            this.jump(this.ps);
            return this;
        }
        applyTransforms(p) {
            if (!this.transforms) return p;
            let pt = [...p];
            this.transforms.map(t => { pt = t(pt); });
            return pt;
        }
        goto(x, y) {
            const p = Array.isArray(x) ? [...x] : [x, y];
            const pt = this.applyTransforms(p);
            if (this.isdown() && (this.pt[0]-pt[0])**2 + (this.pt[1]-pt[1])**2 > 4) {
               this.goto((this.ps[0]+p[0])/2, (this.ps[1]+p[1])/2);
               this.goto(p);
            } else {
                super.goto(pt);
                this.ps = p;
                this.pt = pt;
            }
        }
        position() { return this.ps; }
    }
    return new Tortoise(x,y);
}