1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-27 16:30:29 +02:00

add tile_w2c

This commit is contained in:
Justin Lin
2021-07-29 16:58:48 +08:00
parent 3f499ca32d
commit 021716cf80
2 changed files with 117 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
use <experimental/tile_w2c.scad>;
use <arc.scad>;
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);
}

View File

@@ -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;