mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-27 08:25:45 +02:00
add tile_w2c
This commit is contained in:
71
examples/tiles/2_corner_wang_tiles_basic.scad
Normal file
71
examples/tiles/2_corner_wang_tiles_basic.scad
Normal 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);
|
||||
}
|
46
src/experimental/tile_w2c.scad
Normal file
46
src/experimental/tile_w2c.scad
Normal 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;
|
Reference in New Issue
Block a user