1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-20 05:21:38 +02:00
This commit is contained in:
Justin Lin
2020-11-10 14:54:01 +08:00
parent 92137568b3
commit 271e71f63f
8 changed files with 37 additions and 37 deletions

View File

@@ -6,7 +6,7 @@ function starting_maze(rows, columns) = [
for(x = [1:columns]) for(x = [1:columns])
block( block(
x, y, x, y,
// all blocks have upper and right walls // all blocks have top and right walls
3, 3,
// unvisited // unvisited
false false
@@ -36,7 +36,7 @@ function set_visited(x, y, maze) = [
[x, y, get_wall_type(b), true] : b [x, y, get_wall_type(b), true] : b
]; ];
// 0(right), 1(upper), 2(left), 3(down) // 0(right), 1(top), 2(left), 3(bottom)
_rand_dir_table = [ _rand_dir_table = [
[0, 1, 2, 3], [0, 1, 2, 3],
[0, 1, 3, 2], [0, 1, 3, 2],
@@ -92,17 +92,17 @@ 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] ? (
upper_right_wall(b) ? top_right_wall(b) ?
[x, y, 1, visited(x, y, maze)] : [x, y, 1, visited(x, y, maze)] :
[x, y, 0, visited(x, y, maze)] [x, y, 0, visited(x, y, maze)]
) : b ) : b
]; ];
// go up and carve the upper wall // go up and carve the top 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] ? (
upper_right_wall(b) ? top_right_wall(b) ?
[x, y, 2, visited(x, y, maze)] : [x, y, 2, visited(x, y, maze)] :
[x, y, 0, visited(x, y, maze)] [x, y, 0, visited(x, y, maze)]
@@ -117,26 +117,26 @@ 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] ? (
upper_right_wall(b) ? top_right_wall(b) ?
[nx, y, 1, visited(nx, y, maze)] : [nx, y, 1, visited(nx, y, maze)] :
[nx, y, 0, visited(nx, y, maze)] [nx, y, 0, visited(nx, y, maze)]
) : b ) : b
]; ];
// go down and carve the upper wall of the down block // go down and carve the top wall of the bottom block
function go_down_from(x, y, maze, rows) = [ function go_down_from(x, y, maze, rows) = [
let( let(
y_minus_one = y - 1, y_minus_one = y - 1,
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] ? (
upper_right_wall(b) ? top_right_wall(b) ?
[x, ny, 2, visited(x, ny, maze)] : [x, ny, 2, visited(x, ny, maze)] :
[x, ny, 0, visited(x, ny, maze)] [x, ny, 0, visited(x, ny, maze)]
) : b ) : b
]; ];
// 0(right), 1(upper), 2(left), 3(down) // 0(right), 1(top), 2(left), 3(bottom)
function try_block(dir, x, y, maze, rows, columns) = function try_block(dir, x, y, maze, rows, columns) =
dir == 0 ? go_right_from(x, y, maze) : dir == 0 ? go_right_from(x, y, maze) :
dir == 1 ? go_up_from(x, y, maze) : dir == 1 ? go_up_from(x, y, maze) :

View File

@@ -1,12 +1,12 @@
// NO_WALL = 0; // NO_WALL = 0;
// UPPER_WALL = 1; // TOP_WALL = 1;
// RIGHT_WALL = 2; // RIGHT_WALL = 2;
// UPPER_RIGHT_WALL = 3; // TOP_RIGHT_WALL = 3;
function no_wall(block) = get_wall_type(block) == 0; function no_wall(block) = get_wall_type(block) == 0;
function upper_wall(block) = get_wall_type(block) == 1; function top_wall(block) = get_wall_type(block) == 1;
function right_wall(block) = get_wall_type(block) == 2; function right_wall(block) = get_wall_type(block) == 2;
function upper_right_wall(block) = get_wall_type(block) == 3; function top_right_wall(block) = get_wall_type(block) == 3;
function block(x, y, wall_type, visited) = [x, y, wall_type, visited]; function block(x, y, wall_type, visited) = [x, y, wall_type, visited];
function get_x(block) = block[0]; function get_x(block) = block[0];

View File

@@ -1,6 +1,6 @@
use <../../util/has.scad>; use <../../util/has.scad>;
function _mz_hamiltonian_upper(x, y) = function _mz_hamiltonian_top(x, y) =
let( let(
nx = (x - 1) * 2, nx = (x - 1) * 2,
ny = (y - 1) * 2 ny = (y - 1) * 2
@@ -14,7 +14,7 @@ function _mz_hamiltonian_right(x, y) =
) )
[[nx + 2, ny + 2], [nx + 2, ny + 1], [nx + 2, ny]]; [[nx + 2, ny + 2], [nx + 2, ny + 1], [nx + 2, ny]];
function _mz_hamiltonian_upper_right(x, y) = function _mz_hamiltonian_top_right(x, y) =
let( let(
nx = (x - 1) * 2, nx = (x - 1) * 2,
ny = (y - 1) * 2 ny = (y - 1) * 2

View File

@@ -4,9 +4,9 @@ function _get_x(block) = mz_get(block, "x");
function _get_y(block) = mz_get(block, "y"); function _get_y(block) = mz_get(block, "y");
function _get_wall_type(block) = mz_get(block, "w"); function _get_wall_type(block) = mz_get(block, "w");
function _is_upper_wall(block) = _get_wall_type(block) == "UPPER_WALL"; function _is_top_wall(block) = _get_wall_type(block) == "TOP_WALL";
function _is_right_wall(block) = _get_wall_type(block) == "RIGHT_WALL"; function _is_right_wall(block) = _get_wall_type(block) == "RIGHT_WALL";
function _is_upper_right_wall(block) = _get_wall_type(block) == "UPPER_RIGHT_WALL"; function _is_top_right_wall(block) = _get_wall_type(block) == "TOP_RIGHT_WALL";
function _cell_position(cell_radius, x_cell, y_cell) = function _cell_position(cell_radius, x_cell, y_cell) =
let( let(
@@ -18,18 +18,18 @@ function _cell_position(cell_radius, x_cell, y_cell) =
function _hex_seg(cell_radius, begin, end) = [for(a = [begin:60:end]) function _hex_seg(cell_radius, begin, end) = [for(a = [begin:60:end])
[cell_radius * cos(a), cell_radius * sin(a)]]; [cell_radius * cos(a), cell_radius * sin(a)]];
function _upper_right(cell_radius) = _hex_seg(cell_radius, 0, 60); function _top_right(cell_radius) = _hex_seg(cell_radius, 0, 60);
function _upper(cell_radius) = _hex_seg(cell_radius, 60, 120); function _top(cell_radius) = _hex_seg(cell_radius, 60, 120);
function _upper_left(cell_radius) = _hex_seg(cell_radius, 120, 180); function _top_left(cell_radius) = _hex_seg(cell_radius, 120, 180);
function _down_left(cell_radius) = _hex_seg(cell_radius, 180, 240); function _bottom_left(cell_radius) = _hex_seg(cell_radius, 180, 240);
function _down(cell_radius) = _hex_seg(cell_radius, 240, 300); function _bottom(cell_radius) = _hex_seg(cell_radius, 240, 300);
function _down_right(cell_radius) = _hex_seg(cell_radius, 300, 360); function _bottom_right(cell_radius) = _hex_seg(cell_radius, 300, 360);
function _right_wall(cell_radius, x_cell) = function _right_wall(cell_radius, x_cell) =
(x_cell % 2 != 0) ? _down_right(cell_radius) : _upper_right(cell_radius); (x_cell % 2 != 0) ? _bottom_right(cell_radius) : _top_right(cell_radius);
function _row_wall(cell_radius, x_cell, y_cell) = function _row_wall(cell_radius, x_cell, y_cell) =
x_cell % 2 != 0 ? [_upper_right(cell_radius), _upper_left(cell_radius)] : [_down_right(cell_radius)]; x_cell % 2 != 0 ? [_top_right(cell_radius), _top_left(cell_radius)] : [_bottom_right(cell_radius)];
function _build_cell(cell_radius, block) = function _build_cell(cell_radius, block) =
let( let(
@@ -37,8 +37,8 @@ function _build_cell(cell_radius, block) =
y = _get_y(block) - 1, y = _get_y(block) - 1,
walls = concat( walls = concat(
_row_wall(cell_radius, x, y), _row_wall(cell_radius, x, y),
[_is_upper_wall(block) || _is_upper_right_wall(block) ? _upper(cell_radius) : []], [_is_top_wall(block) || _is_top_right_wall(block) ? _top(cell_radius) : []],
[_is_right_wall(block) || _is_upper_right_wall(block) ? _right_wall(cell_radius, x) : []] [_is_right_wall(block) || _is_top_right_wall(block) ? _right_wall(cell_radius, x) : []]
) )
) )
[ [

View File

@@ -3,7 +3,7 @@ use <_mz_comm.scad>;
function _square_walls(block, block_width) = function _square_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,
upper = upper_wall(block) || upper_right_wall(block) ? [[0, block_width] + loc, [block_width, block_width] + loc] : [], top = top_wall(block) || top_right_wall(block) ? [[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 = right_wall(block) || top_right_wall(block) ? [[block_width, block_width] + loc, [block_width, 0] + loc] : []
) )
concat(upper, right); concat(top, right);

View File

@@ -6,4 +6,4 @@ function mz_get(block, query) =
["w", 2] ["w", 2]
])[0] ])[0]
) )
i != 2 ? block[i] : ["NO_WALL", "UPPER_WALL", "RIGHT_WALL", "UPPER_RIGHT_WALL"][block[i]]; i != 2 ? block[i] : ["NO_WALL", "TOP_WALL", "RIGHT_WALL", "TOP_RIGHT_WALL"][block[i]];

View File

@@ -18,9 +18,9 @@ function mz_hamiltonian(rows, columns, start, seed) =
x = mz_get(block, "x"), x = mz_get(block, "x"),
y = mz_get(block, "y"), y = mz_get(block, "y"),
wall_type = mz_get(block, "w"), wall_type = mz_get(block, "w"),
pts = wall_type == "UPPER_WALL" ? _mz_hamiltonian_upper(x, y) : pts = wall_type == "TOP_WALL" ? _mz_hamiltonian_top(x, y) :
wall_type == "RIGHT_WALL" ? _mz_hamiltonian_right(x, y) : wall_type == "RIGHT_WALL" ? _mz_hamiltonian_right(x, y) :
wall_type == "UPPER_RIGHT_WALL" ? _mz_hamiltonian_upper_right(x, y) : [] wall_type == "TOP_RIGHT_WALL" ? _mz_hamiltonian_top_right(x, y) : []
) )
each pts each pts
], ],

View File

@@ -11,8 +11,8 @@ function mz_hex_walls(blocks, rows, columns, cell_radius, wall_thickness, left_b
for(y = [0:rows - 1]) for(y = [0:rows - 1])
let( let(
cell_p = _cell_position(cell_radius, 0, y), cell_p = _cell_position(cell_radius, 0, y),
walls1 = _upper_left(cell_radius), walls1 = _top_left(cell_radius),
walls2 = _down_left(cell_radius) walls2 = _bottom_left(cell_radius)
) )
[ [
[walls1[0] + cell_p, walls1[1] + cell_p], [walls1[0] + cell_p, walls1[1] + cell_p],
@@ -28,9 +28,9 @@ function mz_hex_walls(blocks, rows, columns, cell_radius, wall_thickness, left_b
for(x = [0:columns - 1]) for(x = [0:columns - 1])
let( let(
cell_p = _cell_position(cell_radius, x, 0), cell_p = _cell_position(cell_radius, x, 0),
walls1 = _down(cell_radius), walls1 = _bottom(cell_radius),
walls2 = [ walls2 = [
for(pair = (x % 2 == 0 ? [_down_left(cell_radius), _down_right(cell_radius)] : [])) for(pair = (x % 2 == 0 ? [_bottom_left(cell_radius), _bottom_right(cell_radius)] : []))
for(wall = pair) for(wall = pair)
wall wall
] ]