mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-06 14:56:47 +02:00
add tile_hitomezashi
This commit is contained in:
43
examples/tiles/hitomezashi_stitching.scad
Normal file
43
examples/tiles/hitomezashi_stitching.scad
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
use <line2d.scad>;
|
||||||
|
use <experimental/tile_hitomezashi.scad>;
|
||||||
|
use <experimental/choose_children.scad>;
|
||||||
|
|
||||||
|
size = [50, 25];
|
||||||
|
tile_width = 5;
|
||||||
|
line_width = 1;
|
||||||
|
|
||||||
|
for(tile = tile_hitomezashi(size)) {
|
||||||
|
x = tile[0];
|
||||||
|
y = tile[1];
|
||||||
|
i = tile[2];
|
||||||
|
choose_children(i) {
|
||||||
|
tile00(x, y, tile_width, line_width);
|
||||||
|
tile01(x, y, tile_width, line_width);
|
||||||
|
tile02(x, y, tile_width, line_width);
|
||||||
|
tile03(x, y, tile_width, line_width);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
module tile00(x, y, tile_width, line_width) {
|
||||||
|
// nope
|
||||||
|
}
|
||||||
|
|
||||||
|
// _
|
||||||
|
module tile01(x, y, tile_width, line_width) {
|
||||||
|
translate([x, y] * tile_width)
|
||||||
|
line2d([0, 0], [tile_width, 0], line_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
// |_
|
||||||
|
module tile02(x, y, tile_width, line_width) {
|
||||||
|
translate([x, y] * tile_width)
|
||||||
|
line2d([0, 0], [0, tile_width], line_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
// |
|
||||||
|
module tile03(x, y, tile_width, line_width) {
|
||||||
|
translate([x, y] * tile_width) {
|
||||||
|
line2d([0, 0], [0, tile_width], line_width);
|
||||||
|
line2d([0, 0], [tile_width, 0], line_width);
|
||||||
|
}
|
||||||
|
}
|
31
src/experimental/tile_hitomezashi.scad
Normal file
31
src/experimental/tile_hitomezashi.scad
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
function tile_hitomezashi(size, mask, seed) =
|
||||||
|
let(
|
||||||
|
rows = size[1],
|
||||||
|
columns = size[0],
|
||||||
|
rx = is_undef(seed) ? [for(r = rands(0, 1, columns)) round(r)] : [for(r = rands(0, 1, columns, seed + columns)) round(r)],
|
||||||
|
ry = is_undef(seed) ? [for(r = rands(0, 1, rows)) round(r)] : [for(r = rands(0, 1, rows, seed + rows)) round(r)],
|
||||||
|
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]]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
[
|
||||||
|
for(y = y_range)
|
||||||
|
for(x = x_range)
|
||||||
|
if(m[y][x] == 1)
|
||||||
|
let(
|
||||||
|
wx = ry[y] == 0 && x % 2 == 1 ? 1 :
|
||||||
|
ry[y] == 1 && x % 2 == 0 ? 1 : 0,
|
||||||
|
wy = rx[x] == 1 && y % 2 == 0 ? 1 :
|
||||||
|
rx[x] == 0 && y % 2 == 1 ? 1 : 0
|
||||||
|
)
|
||||||
|
[x, y, wx + wy * 2]
|
||||||
|
|
||||||
|
];
|
||||||
|
|
Reference in New Issue
Block a user