mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-16 19:54:29 +02:00
refactor
This commit is contained in:
@@ -5,41 +5,6 @@ maze_rows = 8;
|
||||
block_width = 10;
|
||||
stairs_width = 5;
|
||||
|
||||
module draw_block(wall_type, block_width, wall_thickness) {
|
||||
if(wall_type == UPPER_WALL || wall_type == UPPER_RIGHT_WALL) {
|
||||
// draw a upper wall
|
||||
line2d(
|
||||
[0, block_width], [block_width, block_width], wall_thickness
|
||||
);
|
||||
}
|
||||
|
||||
if(wall_type == RIGHT_WALL || wall_type == UPPER_RIGHT_WALL) {
|
||||
// draw a right wall
|
||||
line2d(
|
||||
[block_width, block_width], [block_width, 0], wall_thickness
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module draw_maze(rows, columns, blocks, block_width, wall_thickness) {
|
||||
for(block = blocks) {
|
||||
// move a block to a right position.
|
||||
translate([get_x(block) - 1, get_y(block) - 1] * block_width)
|
||||
draw_block(
|
||||
get_wall_type(block),
|
||||
block_width,
|
||||
wall_thickness
|
||||
);
|
||||
}
|
||||
|
||||
// the lowermost wall
|
||||
line2d([0, 0], [block_width * columns, 0],
|
||||
wall_thickness);
|
||||
// the leftmost wall
|
||||
line2d([0, block_width], [0, block_width * rows],
|
||||
wall_thickness);
|
||||
}
|
||||
|
||||
module pyramid_with_stairs(base_width, stairs_width, rows) {
|
||||
height = base_width * sqrt(2) / 2;
|
||||
|
||||
@@ -81,15 +46,20 @@ module pyramidal_staircase_maze(maze_rows, block_width, stairs_width) {
|
||||
square([block_width * maze_rows + stairs_width, block_width * maze_rows + stairs_width], center = true);
|
||||
|
||||
translate([-(maze_rows * block_width) / 2, -(maze_rows * block_width) / 2, 0])
|
||||
difference() {
|
||||
draw_maze(
|
||||
maze_rows,
|
||||
maze_rows,
|
||||
maze_blocks,
|
||||
block_width,
|
||||
stairs_width
|
||||
);
|
||||
|
||||
|
||||
draw_maze(
|
||||
maze_rows,
|
||||
maze_rows,
|
||||
maze_blocks,
|
||||
block_width,
|
||||
stairs_width
|
||||
);
|
||||
translate([0, stairs_width])
|
||||
square(stairs_width, center = true);
|
||||
translate([maze_rows * block_width, maze_rows * block_width - stairs_width])
|
||||
square(stairs_width, center = true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -168,4 +168,38 @@ function try_routes_from(x, y, dir, maze, rows, columns) =
|
||||
rows, columns
|
||||
)
|
||||
// road closed so return maze directly
|
||||
: maze;
|
||||
: maze;
|
||||
|
||||
|
||||
module draw_block(wall_type, block_width, wall_thickness) {
|
||||
if(wall_type == UPPER_WALL || wall_type == UPPER_RIGHT_WALL) {
|
||||
// draw a upper wall
|
||||
line2d(
|
||||
[0, block_width], [block_width, block_width], wall_thickness
|
||||
);
|
||||
}
|
||||
|
||||
if(wall_type == RIGHT_WALL || wall_type == UPPER_RIGHT_WALL) {
|
||||
// draw a right wall
|
||||
line2d(
|
||||
[block_width, block_width], [block_width, 0], wall_thickness
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module draw_maze(rows, columns, blocks, block_width, wall_thickness) {
|
||||
for(block = blocks) {
|
||||
// move a block to a right position.
|
||||
translate([get_x(block) - 1, get_y(block) - 1] * block_width)
|
||||
draw_block(
|
||||
get_wall_type(block),
|
||||
block_width,
|
||||
wall_thickness
|
||||
);
|
||||
}
|
||||
|
||||
// the lowermost wall
|
||||
line2d([0, 0], [block_width * columns, 0], wall_thickness);
|
||||
// the leftmost wall
|
||||
line2d([0, 0], [0, block_width * rows], wall_thickness);
|
||||
}
|
Reference in New Issue
Block a user