Lines of thought

By changing the grid subdivision, spacing and angle between lines one can see similarities in ways of thinking.

Log in to post a comment.

Canvas.setpenopacity(1);


const turtle = new Turtle();

const subdivisions = 7; // min=1 max=8 step=1 grid subdivisions
const spacing = 4;     // min=3 max=30 step=1 spacing
const baseAngle = 142;       // min=0 max=180 step=5 line angles
let maxBorderLeft = -90;
let maxBorderRight = 90;

const cos = a => Math.cos(a * Math.PI / 180);
const sin = a => Math.sin(a * Math.PI / 180);

function fillCell(x0, y0, x1, y1, angle, spacing){
    // calculates cell center
    const cx = (x0 + x1) / 2;
    const cy = (y0 + y1) / 2;

    const size = Math.max(x1 - x0, y1 - y0);

    // line direction
    const dx = cos(angle);
    const dy = sin(angle);
    const px = -dy;
    const py = dx;

    for (let t = -size; t <= size; t += spacing){
        const mx = cx + px * t;
        const my = cy + py * t;

        // border points
        let ax = mx + dx * size;
        let ay = my + dy * size;
        let bx = mx - dx * size;
        let by = my - dy * size;

        ax = Math.max(x0, Math.min(x1, ax));
        ay = Math.max(y0, Math.min(y1, ay));
        bx = Math.max(x0, Math.min(x1, bx));
        by = Math.max(y0, Math.min(y1, by));

        turtle.jump(ax, ay);
        turtle.goto(bx, by);
    }
}

const totalSize = maxBorderRight - maxBorderLeft;
const cellSize = totalSize / subdivisions;

for (let row = 0; row < subdivisions; row++){
    for (let col = 0; col < subdivisions; col++){
        const x0 = maxBorderLeft + col * cellSize;
        const y0 = maxBorderLeft + row * cellSize;
        const x1 = x0 + cellSize;
        const y1 = y0 + cellSize;

        const cellAngle = (baseAngle + (row * subdivisions + col) * (180 / (subdivisions * subdivisions))) % 180;

        fillCell(x0, y0, x1, y1, cellAngle, spacing);
    }
}