House of Cards

Pixel logic = pain

Log in to post a comment.

Canvas.setpenopacity(1);

const turtle = new Turtle();
turtle.penup();
turtle.goto(-100,100);
turtle.seth(270);
turtle.pendown();

const cardHeight = 12;
const layerPad = 6;
const cardAngle = Math.sin(layerPad/cardHeight)*180/Math.PI;
let layer = 1;
let layerWidth = 0;
let layerRoof;

function walk(i) {
    turtle.seth(270+cardAngle);
    turtle.forward(cardHeight);
    turtle.seth(90-cardAngle);
    turtle.forward(cardHeight);
    if (turtle.x() >= 101-(layer*layerPad)) {
        layerWidth = turtle.x() + 100 + layer;
        turtle.penup();
        turtle.backward(cardHeight);
        turtle.pendown();
        turtle.seth(180);
        layerRoof = layerWidth-((1+layer)*layerPad)-((layer-1)*0.4);
        if (layerRoof < layerPad) return false;
        turtle.forward(layerRoof);
        layer++;
    }
    return i < 500;
}