From 61f7988820f39cf69d1babc703097a727e1b5442 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Thu, 29 Jul 2021 12:05:18 +0800 Subject: [PATCH] refactor --- examples/tiles/random_city.scad | 15 +++++++-- examples/tiles/tube_box.scad | 29 ++++++----------- src/experimental/tiles_wang_2e.scad | 49 ----------------------------- 3 files changed, 22 insertions(+), 71 deletions(-) delete mode 100644 src/experimental/tiles_wang_2e.scad diff --git a/examples/tiles/random_city.scad b/examples/tiles/random_city.scad index 907d13bb..912e7526 100644 --- a/examples/tiles/random_city.scad +++ b/examples/tiles/random_city.scad @@ -3,7 +3,7 @@ use ; use ; use ; use ; -use ; +use ; mask = [ [0, 1, 1, 0, 0, 0, 1, 1, 0], @@ -24,7 +24,18 @@ random_city(rows, columns, mask); module random_city(rows, columns, mask) { tile_width = 30; - tiles_wang_2e(rows, columns, tile_width, mask) { + + module tiles() { + for(tile = tile_w2e(rows, columns, mask)) { + x = tile[0]; + y = tile[1]; + i = tile[2]; + translate([x, y] * tile_width) + children(i); + } + } + + tiles() { tile00(); tile01(); tile02(); diff --git a/examples/tiles/tube_box.scad b/examples/tiles/tube_box.scad index 09485724..8fbfb528 100644 --- a/examples/tiles/tube_box.scad +++ b/examples/tiles/tube_box.scad @@ -1,4 +1,4 @@ -use ; +use ; use ; rows = 8; @@ -12,25 +12,14 @@ module tube_box(rows, columns, tile_width) { half_w = tile_width / 2; quarter_w = tile_width / 4; eighth_w = tile_width / 8; - - translate([eighth_w, eighth_w, -eighth_w]) - tiles_wang_2e(rows, columns, tile_width) { - tube_tile(0, tile_width); - tube_tile(1, tile_width); - tube_tile(2, tile_width); - tube_tile(3, tile_width); - tube_tile(4, tile_width); - tube_tile(5, tile_width); - tube_tile(6, tile_width); - tube_tile(7, tile_width); - tube_tile(8, tile_width); - tube_tile(9, tile_width); - tube_tile(10, tile_width); - tube_tile(11, tile_width); - tube_tile(12, tile_width); - tube_tile(13, tile_width); - tube_tile(14, tile_width); - tube_tile(15, tile_width); + + translate([eighth_w, eighth_w, -eighth_w] + [tile_width, tile_width] / 2) + for(tile = tile_w2e(rows, columns)) { + x = tile[0]; + y = tile[1]; + i = tile[2]; + translate([x, y] * tile_width) + tube_tile(i, tile_width); } box_extrude(height = tile_width, shell_thickness = eighth_w) diff --git a/src/experimental/tiles_wang_2e.scad b/src/experimental/tiles_wang_2e.scad deleted file mode 100644 index c4656ed1..00000000 --- a/src/experimental/tiles_wang_2e.scad +++ /dev/null @@ -1,49 +0,0 @@ -// wang tiles - 2 edges -module tiles_wang_2e(rows, columns, tile_width, mask, seed) { - edges = is_undef(seed) ? [ - for(y = [0:rows]) - [ - for(x = [0:columns]) - let(rs = rands(0, 1, 2)) - [round(rs[0]), round(rs[1])] - ] - ] : [ - for(y = [0:rows]) - [ - for(x = [0:columns]) - let(rs = rands(0, 1, 2, seed + y * columns + x)) - [round(rs[0]), round(rs[1])] - ] - ]; - - m = is_undef(mask) ? [ - for(y = [0:rows - 1]) - [for(x = [0:columns - 1]) 1] - ] : [ - for(y = rows - 1; y > -1; y = y - 1) - [for(x = [0:columns - 1]) mask[y][x]] - ]; - - /* - 1 - . - . - 8 | | 2 - . - . - 4 - */ - - half_w = tile_width / 2; - translate([half_w, half_w]) - for(y = [0:rows - 1]) { - for(x = [0:columns - 1]) { - if(m[y][x] == 1) { - i = (edges[y + 1][x][0] == 1 ? 1 : 0) + - (edges[y][x + 1][1] == 1 ? 2 : 0) + - (edges[y][x][0] == 1 ? 4 : 0) + - (edges[y][x][1] == 1 ? 8 : 0); - translate([x, y] * tile_width) - children(i); - } - } - } -} \ No newline at end of file