Log in to post a comment.

Canvas.setpenopacity(1);

let base_shift = 0; // min=0, max=360, step=10
let cos_scalar = 100; // min=0, max=360, step=10
let freq_scalar = 10; // min=0, max=360, step=10
// You probably want to use 1, 2, or 100 for this. IE L1, L2, and approx Linfinity
let norm = 2; // min=0, max=100, step=2
let num_cubes = 40 // min=10, max=100, step=10


// Global code will be evaluated once.
const turtle = new Turtle();
turtle.penup();
turtle.goto(-50,-20);
turtle.pendown();

const width=195;
const height=195;
const cubesPerSide=num_cubes;
const cubeSpacing=width/(cubesPerSide);
const cubeSize=width/(cubesPerSide*0.95);
const minX=-(width)/2 ;
const minY=-(height)/2;

// The walk function will be called until it returns false.
function walk(i) {
    for(let y=0;y<cubesPerSide;++y) {
        for(x=0;x<cubesPerSide;++x) {
            turtle.penup();
            
            x_coord = minX+x*cubeSpacing+cubeSpacing/2
            y_coord = minY+y*cubeSpacing+cubeSpacing/2
            
            turtle.goto(x_coord, y_coord);
            
            x_norm = Math.pow(x_coord, norm)
            y_norm = Math.pow(y_coord, norm)
            
            // Between 0-1 of how far away it is
            coord_norm = Math.pow(x_norm+y_norm, 1/norm)/200
            
            turtle.setheading(base_shift+cos_scalar*Math.cos(coord_norm*freq_scalar))
                
            turtle.forward(cubeSize/2); turtle.right(90);
            turtle.pendown();
            turtle.forward(cubeSize/2); turtle.right(90);
            turtle.forward(cubeSize); turtle.right(90);
            turtle.forward(cubeSize); turtle.right(90);
            turtle.forward(cubeSize); turtle.right(90);
            turtle.forward(cubeSize/2); 
        }
    }
    return false;
}