Hector

function surface(x, y) {
const r = -0.075 * Math.sqrt(x * x + y * y);
const z = -100 * Math.sin(r) / r;
}

Log in to post a comment.

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

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

// f(x,y) equation
function surface(x, y) {
	const r = -0.075 * Math.sqrt(x * x + y * y);
	const z = -100 * Math.sin(r) / r;
	return z * cv - y * sv;
}

const av = 0.2;
const sv = Math.sin(av);
const cv = Math.cos(av);
const ph = Array.from({ length: 4000 }, () => 1000);

// The walk function will be called until it returns false.
function walk(i) {
    const y = i - 200;
    for (let x = -200; x <= 200; x += 0.1) {
        const z = surface(x, y);
        let py, px =  x * 0.5;
        if (z <= ph[Math.round(x * 10 + 2000)]) {
            py =  z;
            ph[Math.round(x * 10 + 2000)] = z;
        } else {
            py =  ph[Math.round(x * 10 + 2000)];
        }
        turtle.goto(px, py + 15);
        turtle.down();
    }
    turtle.up();
    return i < 400;
}