1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-01 20:40:28 +02:00

use square_maze

This commit is contained in:
Justin Lin
2019-09-01 18:20:41 +08:00
parent ec399f3926
commit 22d2cfa413

View File

@@ -1,7 +1,7 @@
include <line2d.scad>; include <line2d.scad>;
include <polyline2d.scad>; include <polyline2d.scad>;
include <stereographic_extrude.scad>; include <stereographic_extrude.scad>;
include <maze.scad>; include <square_maze.scad>;
x_cells = 5; x_cells = 5;
cell_radius = 20; cell_radius = 20;
@@ -17,7 +17,7 @@ module hex_maze(y_cells, x_cells, maze_vector, cell_radius, wall_thickness) {
module cell(x_cell, y_cell, style) { module cell(x_cell, y_cell, style) {
module upper_wall() { module upper_wall() {
polyline2d( polyline2d(
[for(a = [240:60:300]) [for(a = [60:60:120])
[cell_radius * cos(a), cell_radius * sin(a)]], [cell_radius * cos(a), cell_radius * sin(a)]],
wall_thickness, wall_thickness,
startingStyle = "CAP_ROUND", endingStyle = "CAP_ROUND" startingStyle = "CAP_ROUND", endingStyle = "CAP_ROUND"
@@ -26,7 +26,7 @@ module hex_maze(y_cells, x_cells, maze_vector, cell_radius, wall_thickness) {
module down_wall() { module down_wall() {
polyline2d( polyline2d(
[for(a = [60:60:120]) [for(a = [240:60:300])
[cell_radius * cos(a), cell_radius * sin(a)]], [cell_radius * cos(a), cell_radius * sin(a)]],
wall_thickness, wall_thickness,
startingStyle = "CAP_ROUND", endingStyle = "CAP_ROUND" startingStyle = "CAP_ROUND", endingStyle = "CAP_ROUND"
@@ -34,33 +34,24 @@ module hex_maze(y_cells, x_cells, maze_vector, cell_radius, wall_thickness) {
} }
module up_left_wall() { module up_left_wall() {
polyline2d(
[for(a = [180:60:270])
[cell_radius * cos(a), cell_radius * sin(a)]],
wall_thickness,
startingStyle = "CAP_ROUND", endingStyle = "CAP_ROUND"
);
}
module down_left_wall() {
polyline2d( polyline2d(
[for(a = [120:60:180]) [for(a = [120:60:180])
[cell_radius * cos(a), cell_radius * sin(a)]], [cell_radius * cos(a), cell_radius * sin(a)]],
wall_thickness, wall_thickness,
startingStyle = "CAP_ROUND", endingStyle = "CAP_ROUND" startingStyle = "CAP_ROUND", endingStyle = "CAP_ROUND"
); );
} }
module up_right_wall() { module down_left_wall() {
polyline2d( polyline2d(
[for(a = [300:60:360]) [for(a = [180:60:240])
[cell_radius * cos(a), cell_radius * sin(a)]], [cell_radius * cos(a), cell_radius * sin(a)]],
wall_thickness, wall_thickness,
startingStyle = "CAP_ROUND", endingStyle = "CAP_ROUND" startingStyle = "CAP_ROUND", endingStyle = "CAP_ROUND"
); );
} }
module down_right_wall() { module up_right_wall() {
polyline2d( polyline2d(
[for(a = [0:60:60]) [for(a = [0:60:60])
[cell_radius * cos(a), cell_radius * sin(a)]], [cell_radius * cos(a), cell_radius * sin(a)]],
@@ -69,42 +60,59 @@ module hex_maze(y_cells, x_cells, maze_vector, cell_radius, wall_thickness) {
); );
} }
module down_right_wall() {
polyline2d(
[for(a = [300:60:360])
[cell_radius * cos(a), cell_radius * sin(a)]],
wall_thickness,
startingStyle = "CAP_ROUND", endingStyle = "CAP_ROUND"
);
}
module right_walls() { module right_walls() {
up_right_wall(); up_right_wall();
down_right_wall(); down_right_wall();
} }
module cell_border_wall() { module cell_border_wall() {
if(y_cell == 0 && x_cell % 2 == 0) {
if(x_cell != 0) {
up_left_wall();
}
up_right_wall();
}
if(x_cell == 0) { if(x_cell == 0) {
up_left_wall(); up_left_wall();
down_left_wall(); down_left_wall();
} }
if(y_cell == (y_cells - 1)) { if(x_cell == x_cells - 1 && y_cell == y_cells - 1) {
up_right_wall();
}
if(y_cell == 0) {
down_wall(); down_wall();
if(x_cell % 2 != 0) { if(x_cell % 2 == 0) {
down_left_wall(); if(x_cell != 0) {
down_left_wall();
}
down_right_wall();
} }
} }
if(y_cell == y_cells - 1 && x_cell % 2 != 0) {
up_left_wall();
}
} }
module cell_inner_wall() { module cell_inner_wall() {
if(style == "upper") { if(style == "upper") {
upper_wall(); upper_wall();
} else if(style == "rights") { if(x_cell % 2 != 0) {
right_walls(); up_right_wall();
} else if(style == "right") { }
if(x_cell % 2 == 0) { } else if(style == "right") {
right_walls();
} else {
if(x_cell % 2 == 0) {
down_right_wall();
}
else {
up_right_wall(); up_right_wall();
} else {
down_right_wall();
} }
} }
} }
@@ -127,18 +135,16 @@ module hex_maze(y_cells, x_cells, maze_vector, cell_radius, wall_thickness) {
cord = maze_vector[i]; cord = maze_vector[i];
x = (cord[0] - 1) ; x = (cord[0] - 1) ;
y = (cord[1] - 1); y = (cord[1] - 1);
v = cord[3]; v = cord[2];
if(v == 1 || v == 3) { if(v == 1 || v == 3) {
cell(x, y, "upper"); cell(x, y, "upper");
} }
if(v == 2 || v == 3) { if(v == 2 || v == 3) {
cell(x, y, "rights"); cell(x, y, "right");
} }
if(v == 0 || v == 1) {
cell(x, y, "right"); cell(x, y);
}
} }
} }
@@ -156,14 +162,15 @@ module hex_maze_stereographic_projection(x_cells, cell_radius, wall_thickness, f
pyramid_height = square_w / sqrt(2); pyramid_height = square_w / sqrt(2);
// create a maze // create a maze
maze_vector = go_maze(1, 1, y_cells, x_cells, init_maze(y_cells, x_cells)); maze_vector = go_maze(1, 1, starting_maze(y_cells, x_cells), y_cells, x_cells);
stereographic_extrude(square_w, $fn = fn) stereographic_extrude(square_w, $fn = fn)
translate([grid_w - square_w / 2, grid_h - square_w / 2, 0]) translate([grid_w - square_w / 2, grid_h - square_w / 2, 0])
hex_maze(y_cells, x_cells, maze_vector, cell_radius, wall_thickness); hex_maze(y_cells, x_cells, maze_vector, cell_radius, wall_thickness);
if(shadow == "YES") { if(shadow == "YES") {
color("black") linear_extrude(wall_height) color("black")
linear_extrude(wall_height)
translate([grid_w - square_w / 2, grid_h - square_w / 2, 0]) translate([grid_w - square_w / 2, grid_h - square_w / 2, 0])
hex_maze(y_cells, x_cells, maze_vector, cell_radius, wall_thickness); hex_maze(y_cells, x_cells, maze_vector, cell_radius, wall_thickness);
} }