1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-04-16 12:03:32 +02:00
This commit is contained in:
Justin Lin 2019-09-07 15:59:47 +08:00
parent dc31063b4c
commit 4174cde9d8
2 changed files with 45 additions and 44 deletions

View File

@ -231,4 +231,48 @@ module build_square_maze(rows, columns, blocks, block_width, wall_thickness, lef
if(bottom_border) {
line2d([0, 0], [block_width * columns, 0], wall_thickness);
}
}
}
function block_walls(block, block_width) =
let(
loc = [get_x(block) - 1, get_y(block) - 1] * block_width,
wall_type = get_wall_type(block),
upper_wall = wall_type == UPPER_WALL || wall_type == UPPER_RIGHT_WALL ? [[0, block_width] + loc, [block_width, block_width] + loc] : [],
right_wall = wall_type == RIGHT_WALL || wall_type == UPPER_RIGHT_WALL ? [[block_width, block_width] + loc, [block_width, 0] + loc] : []
)
concat(
upper_wall,
right_wall
);
function maze_walls(blocks, rows, columns, block_width, left_border = true, bottom_border = true) =
let(
left_walls = left_border ? [for(y = [0:rows - 1]) [[0, block_width * (y + 1)], [0, block_width * y]]] : [],
buttom_walls = bottom_border ? [for(x = [0:columns - 1]) [[block_width * x, 0], [block_width * (x + 1), 0]]] : []
)
concat(
[
for(block = blocks)
let(pts = block_walls(block, block_width))
if(pts != []) pts
]
, left_walls, buttom_walls
);
function y_twist(walls, angle, rows, columns, block_width) =
let(
x_offset = columns * block_width / 2,
x_centered = [
for(wall_pts = walls)
[for(pt = wall_pts) [pt[0], pt[1], 0] + [-x_offset, 0, 0]]
],
a_step = angle / rows
)
[
for(wall_pts = x_centered)
[
for(pt = wall_pts)
rotate_p(pt, [0, pt[1] * a_step, 0]) + [x_offset, 0, 0]
]
];

View File

@ -9,49 +9,6 @@ wall_thickness = 1;
angle = 90;
// $fn = 24;
function block_walls(block, block_width) =
let(
loc = [get_x(block) - 1, get_y(block) - 1] * block_width,
wall_type = get_wall_type(block),
upper_wall = wall_type == UPPER_WALL || wall_type == UPPER_RIGHT_WALL ? [[0, block_width] + loc, [block_width, block_width] + loc] : [],
right_wall = wall_type == RIGHT_WALL || wall_type == UPPER_RIGHT_WALL ? [[block_width, block_width] + loc, [block_width, 0] + loc] : []
)
concat(
upper_wall,
right_wall
);
function maze_walls(blocks, rows, columns, block_width, left_border = true, bottom_border = true) =
let(
left_walls = left_border ? [for(y = [0:rows - 1]) [[0, block_width * (y + 1)], [0, block_width * y]]] : [],
buttom_walls = bottom_border ? [for(x = [0:columns - 1]) [[block_width * x, 0], [block_width * (x + 1), 0]]] : []
)
concat(
[
for(block = blocks)
let(pts = block_walls(block, block_width))
if(pts != []) pts
]
, left_walls, buttom_walls
);
function y_twist(walls, angle, rows, columns, block_width) =
let(
x_offset = columns * block_width / 2,
x_centered = [
for(wall_pts = walls)
[for(pt = wall_pts) [pt[0], pt[1], 0] + [-x_offset, 0, 0]]
],
a_step = angle / rows
)
[
for(wall_pts = x_centered)
[
for(pt = wall_pts)
rotate_p(pt, [0, pt[1] * a_step, 0]) + [x_offset, 0, 0]
]
];
blocks = go_maze(
1, 1, // starting point
starting_maze(rows, columns),