From 3c70c23afa8058c0ce26c4c515b46f7bd4d2dc07 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sun, 11 Sep 2022 13:07:12 +0800 Subject: [PATCH] add island_maze --- examples/maze/island_maze.scad | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 examples/maze/island_maze.scad diff --git a/examples/maze/island_maze.scad b/examples/maze/island_maze.scad new file mode 100644 index 00000000..fb49de75 --- /dev/null +++ b/examples/maze/island_maze.scad @@ -0,0 +1,58 @@ +use +use +use +use +use + +rows = 30; +columns = 30; +cell_width = 3; +wall_thickness = 1.5; +moutain_height = 30; +base_height = 3; +seed = 35; +smoothness = 25; + +island_maze(); + +module island_maze() { + dirs = function(x, y, cells, seed) + let( + nz = nz_perlin2(x * cell_width / smoothness, y * cell_width / smoothness, seed), + sd = y * len(cells[0]) + x + seed, + h = choose([[0, 2], [2, 0]], seed = sd), + v = choose([[1, 3], [3, 1]], seed = sd) + ) + nz > 0 ? concat(h, v) : concat(v, h); + + cells = mz_square(rows, columns, seed = seed, directions = dirs); + walls = mz_squarewalls(cells, cell_width); + + color("green") + for(wall = walls) { + for(i = [0:len(wall) - 2]) { + p1 = wall[i]; + p2 = wall[i + 1]; + h1 = nz_perlin2(p1.x / smoothness , p1.y / smoothness , seed); + h2 = nz_perlin2(p2.x / smoothness , p2.y / smoothness , seed); + hull() { + linear_extrude(h1 > 0 ? h1 * moutain_height + base_height : base_height) + translate(p1) + square(wall_thickness); + + linear_extrude(h2 > 0 ? h2 * moutain_height + base_height : base_height) + translate(p2) + square(wall_thickness); + } + } + } + + if($preview) { + color("blue") + translate([wall_thickness, wall_thickness] / 2) + for(wall = walls) { + linear_extrude(base_height) + polyline2d(wall, wall_thickness, joinStyle = "JOIN_MITER"); + } + } +} \ No newline at end of file