mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-17 20:11:50 +02:00
change to 0-based
This commit is contained in:
@@ -21,7 +21,7 @@ module cube_maze(maze_rows, block_width, wall_thickness, inner_cube, travel_all)
|
||||
module one_maze() {
|
||||
translate([origin, origin, half_cube_size])
|
||||
linear_extrude(wall_thickness)
|
||||
square_maze([1, 1], maze_rows, block_width, wall_thickness);
|
||||
square_maze(maze_rows, block_width, wall_thickness);
|
||||
}
|
||||
|
||||
one_maze();
|
||||
|
@@ -60,9 +60,9 @@ module heart_to_heart_wall(radius, length, angle, thickness) {
|
||||
|
||||
module heart_maze(maze, radius, cblocks, levels, thickness = 1) {
|
||||
function no_wall(block) = get_wall_type(block) == "NO_WALL";
|
||||
function upper_wall(block) = get_wall_type(block) == "UPPER_WALL";
|
||||
function top_wall(block) = get_wall_type(block) == "TOP_WALL";
|
||||
function right_wall(block) = get_wall_type(block) == "RIGHT_WALL";
|
||||
function upper_right_wall(block) = get_wall_type(block) == "UPPER_RIGHT_WALL";
|
||||
function top_right_wall(block) = get_wall_type(block) == "TOP_RIGHT_WALL";
|
||||
|
||||
function get_x(block) = mz_square_get(block, "x");
|
||||
function get_y(block) = mz_square_get(block, "y");
|
||||
@@ -80,12 +80,12 @@ module heart_maze(maze, radius, cblocks, levels, thickness = 1) {
|
||||
|
||||
for(i = [0:len(maze) - 1]) {
|
||||
block = maze[i];
|
||||
cr = get_x(block);
|
||||
cc = get_y(block) - 1;
|
||||
cr = get_x(block) + 1;
|
||||
cc = get_y(block);
|
||||
|
||||
angle = cc * arc_angle;
|
||||
|
||||
if(upper_wall(block) || upper_right_wall(block)) {
|
||||
if(top_wall(block) || top_right_wall(block)) {
|
||||
heart_to_heart_wall(r * cr, r, cc * arc_angle , thickness);
|
||||
}
|
||||
}
|
||||
@@ -95,10 +95,10 @@ module heart_maze(maze, radius, cblocks, levels, thickness = 1) {
|
||||
// road to the next level
|
||||
for(i = [0:len(maze) - 1]) {
|
||||
block = maze[i];
|
||||
cr = get_x(block);
|
||||
cc = get_y(block) - 1;
|
||||
cr = get_x(block) + 1;
|
||||
cc = get_y(block);
|
||||
|
||||
if(no_wall(block) || upper_wall(block)) {
|
||||
if(no_wall(block) || top_wall(block)) {
|
||||
ring_heart_sector(r * (cr + 1), (cc + 0.5) * arc_angle , thickness, thickness * 0.75);
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ use <maze/mz_square_walls.scad>;
|
||||
use <maze/mz_square_initialize.scad>;
|
||||
use <voxel/vx_contour.scad>;
|
||||
|
||||
start = [2, 2];
|
||||
start = [1, 1];
|
||||
mask = [
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
|
||||
|
@@ -17,7 +17,7 @@ module pyramid_maze(maze_rows, block_width, wall_thickness) {
|
||||
intersection() {
|
||||
linear_extrude(leng * 2)
|
||||
translate([-half_leng, -half_leng])
|
||||
square_maze([1, 1], maze_rows, block_width, wall_thickness);
|
||||
square_maze(maze_rows, block_width, wall_thickness);
|
||||
|
||||
pyramid(leng + wall_thickness);
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ module random_scala(rows, columns, start, width, height) {
|
||||
random_scala(
|
||||
rows = 2,
|
||||
columns = 3,
|
||||
start = [1, 1],
|
||||
start = [0, 0],
|
||||
width = .5,
|
||||
height = .25
|
||||
);
|
@@ -38,9 +38,9 @@ module regular_polygon_to_polygon_wall(radius, length, angle, thickness, sides)
|
||||
|
||||
module regular_polygon_maze(radius, cblocks, levels, thickness = 1, sides) {
|
||||
function no_wall(block) = get_wall_type(block) == "NO_WALL";
|
||||
function upper_wall(block) = get_wall_type(block) == "UPPER_WALL";
|
||||
function top_wall(block) = get_wall_type(block) == "TOP_WALL";
|
||||
function right_wall(block) = get_wall_type(block) == "RIGHT_WALL";
|
||||
function upper_right_wall(block) = get_wall_type(block) == "UPPER_RIGHT_WALL";
|
||||
function top_right_wall(block) = get_wall_type(block) == "TOP_RIGHT_WALL";
|
||||
|
||||
function get_x(block) = mz_square_get(block, "x");
|
||||
function get_y(block) = mz_square_get(block, "y");
|
||||
@@ -62,12 +62,12 @@ module regular_polygon_maze(radius, cblocks, levels, thickness = 1, sides) {
|
||||
|
||||
for(i = [0:len(maze) - 1]) {
|
||||
block = maze[i];
|
||||
cr = get_x(block);
|
||||
cc = get_y(block) - 1;
|
||||
cr = get_x(block) + 1;
|
||||
cc = get_y(block);
|
||||
|
||||
angle = cc * arc_angle;
|
||||
|
||||
if(upper_wall(block) || upper_right_wall(block)) {
|
||||
if(top_wall(block) || top_right_wall(block)) {
|
||||
regular_polygon_to_polygon_wall(r * cr, r, cc * arc_angle , thickness, sides);
|
||||
}
|
||||
}
|
||||
@@ -80,10 +80,10 @@ module regular_polygon_maze(radius, cblocks, levels, thickness = 1, sides) {
|
||||
// road to the next level
|
||||
for(i = [0:len(maze) - 1]) {
|
||||
block = maze[i];
|
||||
cr = get_x(block);
|
||||
cc = get_y(block) - 1;
|
||||
cr = get_x(block) + 1;
|
||||
cc = get_y(block);
|
||||
|
||||
if(no_wall(block) || upper_wall(block)) {
|
||||
if(no_wall(block) || top_wall(block)) {
|
||||
ring_regular_polygon_sector(r * (cr + 1), (cc + 0.5) * arc_angle , thickness, thickness * 0.75 , sides);
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ use <maze/mz_hamiltonian.scad>;
|
||||
|
||||
rows = 2;
|
||||
columns = 2;
|
||||
start = [1, 1];
|
||||
start = [0, 0];
|
||||
width = .5;
|
||||
height = .05;
|
||||
test_torii = "FALSE"; // [TRUE, FALSE]
|
||||
|
@@ -40,7 +40,7 @@ module step_pyramid_maze(maze_rows, block_width, stairs_width) {
|
||||
|
||||
translate([-(maze_rows * block_width) / 2, -(maze_rows * block_width) / 2, 0])
|
||||
difference() {
|
||||
square_maze([1, 1], maze_rows, block_width, stairs_width);
|
||||
square_maze(maze_rows, block_width, stairs_width);
|
||||
|
||||
// entry
|
||||
translate([0, stairs_width])
|
||||
|
@@ -13,7 +13,7 @@ module stereographic_projection_maze2(maze_rows, block_width, wall_thickness, fn
|
||||
|
||||
module maze() {
|
||||
translate([-block_width * maze_rows / 2, -block_width * maze_rows / 2, 0])
|
||||
square_maze([1, 1], maze_rows, block_width, wall_thickness);
|
||||
square_maze(maze_rows, block_width, wall_thickness);
|
||||
}
|
||||
|
||||
stereographic_extrude(shadow_side_leng = length, $fn = fn)
|
||||
|
@@ -2,7 +2,7 @@ use <_mz_comm.scad>;
|
||||
|
||||
// find out the index of a block with the position (x, y)
|
||||
function indexOf(x, y, maze, i = 0) =
|
||||
i > len(maze) ? -1 : (
|
||||
i == len(maze) ? -1 : (
|
||||
[get_x(maze[i]), get_y(maze[i])] == [x, y] ? i :
|
||||
indexOf(x, y, maze, i + 1)
|
||||
);
|
||||
@@ -12,8 +12,8 @@ function visited(x, y, maze) = maze[indexOf(x, y, maze)][3];
|
||||
|
||||
// is (x, y) visitable?
|
||||
function visitable(x, y, maze, rows, columns) =
|
||||
y > 0 && y <= rows && // y bound
|
||||
x > 0 && x <= columns && // x bound
|
||||
y >= 0 && y < rows && // y bound
|
||||
x >= 0 && x < columns && // x bound
|
||||
!visited(x, y, maze); // unvisited
|
||||
|
||||
// setting (x, y) as being visited
|
||||
@@ -58,23 +58,13 @@ function rand_dirs(c, seed) =
|
||||
_next_x_table = [1, 0, -1, 0];
|
||||
function next_x(x, dir, columns, wrapping) =
|
||||
let(nx = x + _next_x_table[dir])
|
||||
wrapping ?
|
||||
nx < 1 ? nx + columns : (
|
||||
nx > columns ? nx % columns : nx
|
||||
)
|
||||
:
|
||||
nx;
|
||||
wrapping ? (nx < 0 ? nx + columns : nx % columns) : nx;
|
||||
|
||||
// get y value by dir
|
||||
_next_y_table = [0, 1, 0, -1];
|
||||
function next_y(y, dir, rows, wrapping) =
|
||||
let(ny = y + _next_y_table[dir])
|
||||
wrapping ?
|
||||
ny < 1 ? ny + rows : (
|
||||
ny > rows ? ny % rows : ny
|
||||
)
|
||||
:
|
||||
ny;
|
||||
wrapping ? (ny < 0 ? ny + rows : ny % rows) : ny;
|
||||
|
||||
// go right and carve the right wall
|
||||
function carve_right(x, y, maze) = [
|
||||
@@ -94,7 +84,7 @@ function carve_top(x, y, maze) = [
|
||||
function carve_left(x, y, maze, columns) =
|
||||
let(
|
||||
x_minus_one = x - 1,
|
||||
nx = x_minus_one < 1 ? x_minus_one + columns : x_minus_one
|
||||
nx = x_minus_one < 0 ? x_minus_one + columns : x_minus_one
|
||||
)
|
||||
[for(b = maze) [get_x(b), get_y(b)] == [nx, y] ? [nx, y, 1, 0] : b];
|
||||
|
||||
@@ -102,7 +92,7 @@ function carve_left(x, y, maze, columns) =
|
||||
function carve_bottom(x, y, maze, rows) =
|
||||
let(
|
||||
y_minus_one = y - 1,
|
||||
ny = y_minus_one < 1 ? y_minus_one + rows : y_minus_one
|
||||
ny = y_minus_one < 0 ? y_minus_one + rows : y_minus_one
|
||||
)
|
||||
[for(b = maze) [get_x(b), get_y(b)] == [x, ny] ? [x, ny, 2, 0] : b];
|
||||
|
||||
|
@@ -2,22 +2,22 @@ use <../../util/has.scad>;
|
||||
|
||||
function _mz_hamiltonian_top(x, y) =
|
||||
let(
|
||||
nx = (x - 1) * 2,
|
||||
ny = (y - 1) * 2
|
||||
nx = x * 2,
|
||||
ny = y * 2
|
||||
)
|
||||
[[nx, ny + 2], [nx + 1, ny + 2], [nx + 2, ny + 2]];
|
||||
|
||||
function _mz_hamiltonian_right(x, y) =
|
||||
let(
|
||||
nx = (x - 1) * 2,
|
||||
ny = (y - 1) * 2
|
||||
nx = x * 2,
|
||||
ny = y * 2
|
||||
)
|
||||
[[nx + 2, ny + 2], [nx + 2, ny + 1], [nx + 2, ny]];
|
||||
|
||||
function _mz_hamiltonian_top_right(x, y) =
|
||||
let(
|
||||
nx = (x - 1) * 2,
|
||||
ny = (y - 1) * 2
|
||||
nx = x * 2,
|
||||
ny = y * 2
|
||||
)
|
||||
[[nx, ny + 2], [nx + 1, ny + 2], [nx + 2, ny + 2], [nx + 2, ny + 1], [nx + 2, ny]];
|
||||
|
||||
|
@@ -33,8 +33,8 @@ function _row_wall(cell_radius, x_cell, y_cell) =
|
||||
|
||||
function _build_cell(cell_radius, block) =
|
||||
let(
|
||||
x = _get_x(block) - 1,
|
||||
y = _get_y(block) - 1,
|
||||
x = _get_x(block),
|
||||
y = _get_y(block),
|
||||
walls = concat(
|
||||
_row_wall(cell_radius, x, y),
|
||||
[_is_top_wall(block) || _is_top_right_wall(block) ? _top(cell_radius) : []],
|
||||
|
@@ -2,8 +2,8 @@ use <_mz_comm.scad>;
|
||||
|
||||
// create a starting maze for being visited later.
|
||||
function _rc_maze(rows, columns) = [
|
||||
for(y = [1:rows])
|
||||
for(x = [1:columns])
|
||||
for(y = [0:rows - 1])
|
||||
for(x = [0:columns - 1])
|
||||
block(
|
||||
x, y,
|
||||
// all blocks have top and right walls
|
||||
@@ -19,9 +19,9 @@ function _mz_mask(mask) =
|
||||
columns = len(mask[0])
|
||||
)
|
||||
[
|
||||
for(y = [1:rows])
|
||||
for(x = [1:columns])
|
||||
mask[rows - y][x - 1] == 0 ?
|
||||
for(y = [0:rows - 1])
|
||||
for(x = [0:columns - 1])
|
||||
mask[rows - y - 1][x] == 0 ?
|
||||
block(
|
||||
x, y,
|
||||
4, // mask
|
||||
@@ -31,8 +31,7 @@ function _mz_mask(mask) =
|
||||
block(
|
||||
x, y,
|
||||
// all blocks have top and right walls
|
||||
3,
|
||||
// unvisited
|
||||
3, // unvisited
|
||||
false
|
||||
)
|
||||
];
|
@@ -2,7 +2,7 @@ use <_mz_comm.scad>;
|
||||
|
||||
function _square_walls(block, block_width) =
|
||||
let(
|
||||
loc = [get_x(block) - 1, get_y(block) - 1] * block_width,
|
||||
loc = [get_x(block), get_y(block)] * block_width,
|
||||
top = top_wall(block) || top_right_wall(block) ? [[0, block_width] + loc, [block_width, block_width] + loc] : [],
|
||||
right = right_wall(block) || top_right_wall(block) ? [[block_width, block_width] + loc, [block_width, 0] + loc] : []
|
||||
)
|
||||
|
@@ -28,4 +28,4 @@ function mz_hamiltonian(rows, columns, start, seed) =
|
||||
),
|
||||
dot_pts = dedup(sort(all, by = "vt"), sorted = true)
|
||||
)
|
||||
_mz_hamiltonian_travel(dot_pts, start + [-1, -1], rows * columns * 4);
|
||||
_mz_hamiltonian_travel(dot_pts, start, rows * columns * 4);
|
@@ -1,7 +1,7 @@
|
||||
use <_impl/_mz_blocks_impl.scad>;
|
||||
use <mz_square_initialize.scad>;
|
||||
|
||||
function mz_square_blocks(rows, columns, start = [1, 1], maze, x_wrapping = false, y_wrapping = false, seed) =
|
||||
function mz_square_blocks(rows, columns, start = [0, 0], maze, x_wrapping = false, y_wrapping = false, seed) =
|
||||
go_maze(
|
||||
start[0], start[1], // starting point
|
||||
is_undef(maze) ? mz_square_initialize(rows, columns) : maze,
|
||||
|
Reference in New Issue
Block a user