xxxxxxxxxx
49
const HIERARCHY = new Dusa(`
#builtin INT_PLUS plus
#builtin INT_MINUS minus
#builtin NAT_SUCC s
#demand max is _.
dim max.
dim (minus N 1) :- dim N, N > 0.
dir horizontal.
dir vertical.
bound 0 is? (square D c 0 max 0 max) :- dir D.
bound (s N) is? {
square horizontal a X1 X' Y1 Y2,
square horizontal b X' X2 Y1 Y2
} :-
bound N is (square vertical _ X1 X2 Y1 Y2),
dim X', X1 < X', X' < X2.
bound (s N) is? {
square vertical a X1 X2 Y1 Y',
square vertical b X1 X2 Y' Y2
} :-
bound N is (square horizontal _ X1 X2 Y1 Y2),
dim Y', Y1 < Y', Y' < Y2.
line X' Y1 X' Y2 :- bound _ is (square horizontal a _ X' Y1 Y2).
line X' Y1 X' Y2 :- bound _ is (square horizontal b X' _ Y1 Y2).
line X1 Y' X2 Y' :- bound _ is (square vertical a X1 X2 _ Y').
line X1 Y' X2 Y' :- bound _ is (square vertical b X1 X2 Y' _).`);
const SIZE = 400;
HIERARCHY.assert({ name: 'max', value: SIZE })
function setup() {
createCanvas(SIZE, SIZE);
fill(255, 255, 255, 50);
stroke(0);
}
function draw() {
rect(0,0,SIZE,SIZE);
const solution = HIERARCHY.sample();
for (const args of solution.lookup('line')) {
line(args);
}
}