Barnsley fern

The Barnsley fern is a fractal named after the British mathematician Michael Barnsley who first described it in his book Fractals Everywhere. en.wikipedia.org/wiki/barnsley_fern

#Barnsley #fern #fractal

Log in to post a comment.

Canvas.setpenopacity(-0.1);

const turtle = new Turtle();

let x = 0;
let y = 0;

function walk(i) {
    turtle.jump(x * 15, 75 - y * 15);
    turtle.circle(0.1);
    
    const r = Math.random();
    
    if (r < 0.01) {
        [x, y] = [ 0.00 * x + 0.00 * y,  0.00 * x + 0.16 * y + 0.00];
    } else if (r < 0.86) {
        [x, y] = [ 0.85 * x + 0.04 * y, -0.04 * x + 0.85 * y + 1.60];
    } else if (r < 0.93) {
        [x, y] = [ 0.20 * x - 0.26 * y,  0.23 * x + 0.22 * y + 1.60];
    } else {
        [x, y] = [-0.15 * x + 0.28 * y,  0.26 * x + 0.24 * y + 0.44];
    }
    
    return i < 100000;
}