The Sine Map

https://beta.observablehq.com/%40mattdiamond/the-sine-map

Created by mdiamond on 2018/12/14
1147
0

Log in to post a comment.

const scale = 100;
const iterations = 50000;

/*
    Try changing the value of k
    and the start coordinate
*/

const k = 3;
const start = [10, 10];

setup();
const turtle = getTurtle();

function walk(i) {
    turtle.setpos(iterate(turtle.pos()));
    return i < iterations;
}

function iterate([x, y]) {
    [x, y] = [x / scale, y / scale];
    return [
        Math.sin(k * (y + x)) * scale,
        Math.sin(k * (y - x)) * scale
    ];
}

function getTurtle () {
    const turtle = new Turtle();
    turtle.penup();
    turtle.goto(start);
    turtle.pendown();
    return turtle;
}

function setup() {
    Canvas.setpenopacity(0.01);
}