From 8829123ade16ea37d6510b30bb913c191140d245 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Fri, 30 Jul 2021 10:55:36 +0800 Subject: [PATCH] add tile_truchet --- examples/tiled_lines.scad | 37 +++++++++++------------------- src/experimental/tile_truchet.scad | 29 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 23 deletions(-) create mode 100644 src/experimental/tile_truchet.scad diff --git a/examples/tiled_lines.scad b/examples/tiled_lines.scad index d3b58079..0021d077 100644 --- a/examples/tiled_lines.scad +++ b/examples/tiled_lines.scad @@ -1,28 +1,19 @@ +use ; use ; -use ; - -module tiled_lines(size, step, line_width = 1) { - sizexy = is_num(size) ? [size, size] : size; - s = is_undef(step) ? line_width * 2 : step; - - module rand_diagonal_line(x, y, size) { - if(rand(0, 1) >= 0.5) { - line2d([x, y], [x + size, y + size], width = line_width); - } - else { - line2d([x + size, y], [x, y + size], width = line_width); - } - } - - for(x = [0:s:sizexy[0] - s]) { - for(y = [0:s:sizexy[1] - s]) { - rand_diagonal_line(x, y, s); - } - } -} size = [50, 25]; -step = 2; +tile_width = 5; line_width = 1; -tiled_lines(size, step, line_width); +for(tile = tile_truchet(size)) { + x = tile[0]; + y = tile[1]; + i = tile[2]; + + if(i <= 1) { + line2d([x, y] * tile_width , [x + 1, y + 1] * tile_width, width = line_width); + } + else { + line2d([x + 1, y] * tile_width, [x, y + 1] * tile_width, width = line_width); + } +} \ No newline at end of file diff --git a/src/experimental/tile_truchet.scad b/src/experimental/tile_truchet.scad new file mode 100644 index 00000000..859c55f1 --- /dev/null +++ b/src/experimental/tile_truchet.scad @@ -0,0 +1,29 @@ +use ; + +function tile_truchet(size, mask, seed) = + let( + rows = size[1], + columns = size[0], + y_range = [0:rows - 1], + x_range = [0:columns - 1], + nums = [0, 1, 2, 3], + m = is_undef(mask) ? [ + for(y = y_range) + [for(x = x_range) 1] + ] : [ + for(y = rows - 1; y > -1; y = y - 1) + [for(x = x_range) mask[y][x]] + ] + ) + is_undef(seed) ? [ + for(y = y_range) + for(x = x_range) + if(m[y][x] == 1) + [x, y, choose(nums)] + + ] : [ + for(y = y_range) + for(x = x_range) + if(m[y][x] == 1) + [x, y, choose(nums, x + y * rows + seed)] + ]; \ No newline at end of file