1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-12 09:44:16 +02:00
This commit is contained in:
Justin Lin
2019-09-09 09:03:29 +08:00
parent bd0325979f
commit 247574c2e4

View File

@@ -1,7 +1,12 @@
NO_WALL = 0; // NO_WALL = 0;
UPPER_WALL = 1; // UPPER_WALL = 1;
RIGHT_WALL = 2; // RIGHT_WALL = 2;
UPPER_RIGHT_WALL = 3; // UPPER_RIGHT_WALL = 3;
function no_wall(block_data) = get_wall_type(block_data) == 0;
function upper_wall(block_data) = get_wall_type(block_data) == 1;
function right_wall(block_data) = get_wall_type(block_data) == 2;
function upper_right_wall(block_data) = get_wall_type(block_data) == 3;
function block_data(x, y, wall_type, visited) = [x, y, wall_type, visited]; function block_data(x, y, wall_type, visited) = [x, y, wall_type, visited];
function get_x(block_data) = block_data[0]; function get_x(block_data) = block_data[0];
@@ -15,7 +20,7 @@ function starting_maze(rows, columns) = [
block_data( block_data(
x, y, x, y,
// all blocks have upper and right walls // all blocks have upper and right walls
UPPER_RIGHT_WALL, 3,
// unvisited // unvisited
false false
) )
@@ -96,9 +101,9 @@ function next_y(y, dir, rows, circular) =
// go right and carve the right wall // go right and carve the right wall
function go_right_from(x, y, maze) = [ function go_right_from(x, y, maze) = [
for(b = maze) [get_x(b), get_y(b)] == [x, y] ? ( for(b = maze) [get_x(b), get_y(b)] == [x, y] ? (
get_wall_type(b) == UPPER_RIGHT_WALL ? upper_right_wall(b) ?
[x, y, UPPER_WALL, visited(x, y, maze)] : [x, y, 1, visited(x, y, maze)] :
[x, y, NO_WALL, visited(x, y, maze)] [x, y, 0, visited(x, y, maze)]
) : b ) : b
]; ];
@@ -106,9 +111,9 @@ function go_right_from(x, y, maze) = [
// go up and carve the upper wall // go up and carve the upper wall
function go_up_from(x, y, maze) = [ function go_up_from(x, y, maze) = [
for(b = maze) [get_x(b), get_y(b)] == [x, y] ? ( for(b = maze) [get_x(b), get_y(b)] == [x, y] ? (
get_wall_type(b) == UPPER_RIGHT_WALL ? upper_right_wall(b) ?
[x, y, RIGHT_WALL, visited(x, y, maze)] : [x, y, 2, visited(x, y, maze)] :
[x, y, NO_WALL, visited(x, y, maze)] [x, y, 0, visited(x, y, maze)]
) : b ) : b
]; ];
@@ -121,9 +126,9 @@ function go_left_from(x, y, maze, columns) =
) )
[ [
for(b = maze) [get_x(b), get_y(b)] == [nx, y] ? ( for(b = maze) [get_x(b), get_y(b)] == [nx, y] ? (
get_wall_type(b) == UPPER_RIGHT_WALL ? upper_right_wall(b) ?
[nx, y, UPPER_WALL, visited(nx, y, maze)] : [nx, y, 1, visited(nx, y, maze)] :
[nx, y, NO_WALL, visited(nx, y, maze)] [nx, y, 0, visited(nx, y, maze)]
) : b ) : b
]; ];
@@ -134,9 +139,9 @@ function go_down_from(x, y, maze, rows) = [
ny = y_minus_one < 1 ? y_minus_one + rows : y_minus_one ny = y_minus_one < 1 ? y_minus_one + rows : y_minus_one
) )
for(b = maze) [get_x(b), get_y(b)] == [x, ny] ? ( for(b = maze) [get_x(b), get_y(b)] == [x, ny] ? (
get_wall_type(b) == UPPER_RIGHT_WALL ? upper_right_wall(b) ?
[x, ny, RIGHT_WALL, visited(x, ny, maze)] : [x, ny, 2, visited(x, ny, maze)] :
[x, ny, NO_WALL, visited(x, ny, maze)] [x, ny, 0, visited(x, ny, maze)]
) : b ) : b
]; ];
@@ -198,27 +203,27 @@ function try_routes_from(x, y, dir, maze, rows, columns, x_circular, y_circular)
: maze; : maze;
module build_square_maze(rows, columns, blocks, block_width, wall_thickness, left_border = true, bottom_border = true) { module build_square_maze(rows, columns, blocks, block_width, wall_thickness, left_border = true, bottom_border = true) {
module build_block(wall_type, block_width, wall_thickness) { module build_block(block, block_width, wall_thickness) {
if(wall_type == UPPER_WALL || wall_type == UPPER_RIGHT_WALL) { translate([get_x(block) - 1, get_y(block) - 1] * block_width) {
if(upper_wall(block) || upper_right_wall(block)) {
// draw a upper wall // draw a upper wall
line2d( line2d(
[0, block_width], [block_width, block_width], wall_thickness [0, block_width], [block_width, block_width], wall_thickness
); );
} }
if(wall_type == RIGHT_WALL || wall_type == UPPER_RIGHT_WALL) { if(right_wall(block) || upper_right_wall(block)) {
// draw a right wall // draw a right wall
line2d( line2d(
[block_width, block_width], [block_width, 0], wall_thickness [block_width, block_width], [block_width, 0], wall_thickness
); );
} }
} }
}
for(block = blocks) { for(block = blocks) {
// move a block to a right position.
translate([get_x(block) - 1, get_y(block) - 1] * block_width)
build_block( build_block(
get_wall_type(block), block,
block_width, block_width,
wall_thickness wall_thickness
); );
@@ -233,18 +238,13 @@ module build_square_maze(rows, columns, blocks, block_width, wall_thickness, lef
} }
} }
function block_walls(block, block_width) = function block_walls(block, block_width) =
let( let(
loc = [get_x(block) - 1, get_y(block) - 1] * block_width, loc = [get_x(block) - 1, get_y(block) - 1] * block_width,
wall_type = get_wall_type(block), upper = upper_wall(block) || upper_right_wall(block) ? [[0, block_width] + loc, [block_width, block_width] + loc] : [],
upper_wall = wall_type == UPPER_WALL || wall_type == UPPER_RIGHT_WALL ? [[0, block_width] + loc, [block_width, block_width] + loc] : [], right = right_wall(block) || upper_right_wall(block) ? [[block_width, block_width] + loc, [block_width, 0] + loc] : []
right_wall = wall_type == RIGHT_WALL || wall_type == UPPER_RIGHT_WALL ? [[block_width, block_width] + loc, [block_width, 0] + loc] : []
) )
concat( concat(upper, right);
upper_wall,
right_wall
);
function maze_walls(blocks, rows, columns, block_width, left_border = true, bottom_border = true) = function maze_walls(blocks, rows, columns, block_width, left_border = true, bottom_border = true) =
let( let(