From 6d375e6480c4f4973b734d51c9a714bde661f60a Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sat, 16 Jan 2021 18:36:13 +0800 Subject: [PATCH] refactor --- examples/tile/tube_box.scad | 24 ++---------------------- src/experimental/2_edge_wang_tiles.scad | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 22 deletions(-) create mode 100644 src/experimental/2_edge_wang_tiles.scad diff --git a/examples/tile/tube_box.scad b/examples/tile/tube_box.scad index ee21a6e6..a0833768 100644 --- a/examples/tile/tube_box.scad +++ b/examples/tile/tube_box.scad @@ -1,3 +1,4 @@ +use ; use ; rows = 8; @@ -12,7 +13,7 @@ module tube_box(rows, columns, tile_width) { quarter_w = tile_width / 4; eighth_w = tile_width / 8; - two_edge_wang_tiles(rows, columns, tile_width) { + 2_edge_wang_tiles(rows, columns, tile_width) { tube_tile(0, tile_width); tube_tile(1, tile_width); tube_tile(2, tile_width); @@ -36,27 +37,6 @@ module tube_box(rows, columns, tile_width) { square([columns * tile_width + quarter_w, rows * tile_width + quarter_w]); } -module two_edge_wang_tiles(rows, columns, tile_width) { - edges = [ - for(y = [0:rows]) - [ - for(x = [0:columns]) - [round(rands(0, 1, 1)[0]), round(rands(0, 1, 1)[0])] - ] - ]; - - for(y = [0:rows - 1]) { - for(x = [0:columns - 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); - } - } -} - module tube_tile(n, width) { half_w = width / 2; quarter_w = width / 4; diff --git a/src/experimental/2_edge_wang_tiles.scad b/src/experimental/2_edge_wang_tiles.scad new file mode 100644 index 00000000..0b748571 --- /dev/null +++ b/src/experimental/2_edge_wang_tiles.scad @@ -0,0 +1,20 @@ +module 2_edge_wang_tiles(rows, columns, tile_width) { + edges = [ + for(y = [0:rows]) + [ + for(x = [0:columns]) + [round(rands(0, 1, 1)[0]), round(rands(0, 1, 1)[0])] + ] + ]; + + for(y = [0:rows - 1]) { + for(x = [0:columns - 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