Hacky gasket

It's the Sierpinski triangle with poor code quality. See en.wikipedia.org/wiki/sierpinski_triangle

Log in to post a comment.

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

// Global code will be evaluated once.
const turtle = new Turtle();
const TOPX = 0;
const TOPY = -50;
const LEFTX = -50;
const LEFTY = 20;
const RIGHTX = 50;
const RIGHTY = 20;

function spot(x, y) {
    turtle.penup();
    turtle.goto(x, y);
    turtle.pendown();
    turtle.circle(0.1);
    turtle.penup();
}

spot(TOPX, TOPY);
spot(LEFTX, LEFTY);
spot(RIGHTX, RIGHTY);

function getRandomInt(max) {
  return Math.floor(Math.random() * Math.floor(max));
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function pausecomp(millis)
{
  var date = new Date();
  var curDate = null;
  do { curDate = new Date(); }
  while(curDate-date < millis);
}
var latest_x = TOPX;
var latest_y = TOPY;

const X_CHOICES = [TOPX, LEFTX, RIGHTX];
const Y_CHOICES = [TOPY, LEFTY, RIGHTY];

// The walk function will be called until it returns false.
function walk(i) {
    const choice = getRandomInt(3);
    const chosen_x = X_CHOICES[choice];
    const chosen_y = Y_CHOICES[choice];
    latest_x = (latest_x + chosen_x) / 2;
    latest_y = (latest_y + chosen_y) / 2;
    spot(latest_x, latest_y);
    pausecomp(1);
    return i < 10000;
}