diff --git a/examples/tiles/2_corner_wang_tiles_basic.scad b/examples/tiles/2_corner_wang_tiles_basic.scad new file mode 100644 index 00000000..e311d572 --- /dev/null +++ b/examples/tiles/2_corner_wang_tiles_basic.scad @@ -0,0 +1,71 @@ +use ; +use ; + +rows = 10; +columns = 15; +tile_width = 10; +tile_thickness = 2; +$fn = 24; + +translate([tile_width, tile_width] / 2) + for(tile = tile_w2c(rows, columns)) { + x = tile[0]; + y = tile[1]; + i = tile[2]; + translate([x, y] * tile_width) + sample_tile(i, tile_width, tile_thickness); + } + +module sample_tile(n, width, thickness) { + half_w = width / 2; + + diff_polygons = [ + [[]], + [[[0, 0], [half_w, 0], [half_w, half_w], [0, half_w]]], + [[[0, 0], [0, -half_w], [half_w, -half_w], [half_w, 0]]], + [[[0, -half_w], [half_w, -half_w], [half_w, half_w], [0, half_w]]], + [[[0, 0], [-half_w, 0], [-half_w, -half_w], [0, -half_w]]], + [ + [[0, 0], [half_w, 0], [half_w, half_w], [0, half_w]], + [[0, 0], [-half_w, 0], [-half_w, -half_w], [0, -half_w]] + ], + [[[-half_w, 0], [-half_w, -half_w], [half_w, -half_w], [half_w, 0]]], + [ + [[0, 0], [half_w, 0], [half_w, half_w], [0, half_w]], + [[-half_w, 0], [-half_w, -half_w], [half_w, -half_w], [half_w, 0]] + ], + [[[0, 0], [0, half_w], [-half_w, half_w], [-half_w, 0]]], + [[[half_w, 0], [half_w, half_w], [-half_w, half_w], [-half_w, 0]]], + [ + [[0, 0], [0, -half_w], [half_w, -half_w], [half_w, 0]], + [[0, 0], [0, half_w], [-half_w, half_w], [-half_w, 0]] + ], + [ + [[half_w, 0], [half_w, half_w], [-half_w, half_w], [-half_w, 0]], + [[0, 0], [0, -half_w], [half_w, -half_w], [half_w, 0]] + ], + [[[0, half_w], [-half_w, half_w], [-half_w, -half_w], [0, -half_w]]], + [ + [[0, half_w], [-half_w, half_w], [-half_w, -half_w], [0, -half_w]], + [[0, 0], [half_w, 0], [half_w, half_w], [0, half_w]] + ], + [ + [[-half_w, 0], [-half_w, -half_w], [half_w, -half_w], [half_w, 0]], + [[0, 0], [0, half_w], [-half_w, half_w], [-half_w, 0]] + ], + [[[half_w, half_w], [-half_w, half_w], [-half_w, -half_w], [half_w, -half_w]]] + ]; + + color("blue") + linear_extrude(thickness) + difference() { + square(width, center = true); + for(diff_polygon = diff_polygons[n]) { + offset(0.01) polygon(diff_polygon); + } + } + + color("yellow") + linear_extrude(thickness / 2) + square(width, center = true); +} \ No newline at end of file diff --git a/src/experimental/tile_w2c.scad b/src/experimental/tile_w2c.scad new file mode 100644 index 00000000..eb7897ea --- /dev/null +++ b/src/experimental/tile_w2c.scad @@ -0,0 +1,46 @@ +// wang tiles - 2 corners + +function tile_w2c(rows, columns, mask, seed) = + let( + y_range = [0:rows - 1], + x_range = [0:columns - 1], + corners = is_undef(seed) ? [ + for(y = y_range) + [ + for(x = x_range) + round(rands(0, 1, 1)[0]) + ] + ] : [ + for(y = y_range) + [ + for(x = x_range) + round(rands(0, 1, 1, seed + y * columns + x)[0]) + ] + ], + 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]] + ], + /* + 8 1 + . - . + | | + . - . + 4 2 + */ + tiles = [ + for(y = y_range) + for(x = x_range) + if(m[y][x] == 1) + [x, y, + (corners[(y + 1) % rows][(x + 1) % columns] == 1 ? 1 : 0) + + (corners[y][(x + 1) % columns] == 1 ? 2 : 0) + + (corners[y][x] == 1 ? 4 : 0) + + (corners[(y + 1) % rows][x] == 1 ? 8 : 0) + ] + ] + ) + tiles; \ No newline at end of file