mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-08 15:56:42 +02:00
refactor
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use <experimental/tiles_wang_2e.scad>;
|
use <experimental/tile_w2e.scad>;
|
||||||
use <arc.scad>;
|
use <arc.scad>;
|
||||||
|
|
||||||
rows = 10;
|
rows = 10;
|
||||||
@@ -7,51 +7,24 @@ tile_width = 10;
|
|||||||
tile_thickness = 2;
|
tile_thickness = 2;
|
||||||
$fn = 24;
|
$fn = 24;
|
||||||
|
|
||||||
tiles_wang_2e(rows, columns, tile_width) {
|
translate([tile_width, tile_width] / 2)
|
||||||
sample_tile(0, tile_width, tile_thickness);
|
for(tile = tile_w2e(rows, columns)) {
|
||||||
sample_tile(1, tile_width, tile_thickness);
|
x = tile[0];
|
||||||
sample_tile(2, tile_width, tile_thickness);
|
y = tile[1];
|
||||||
sample_tile(3, tile_width, tile_thickness);
|
i = tile[2];
|
||||||
sample_tile(4, tile_width, tile_thickness);
|
translate([x, y] * tile_width)
|
||||||
sample_tile(5, tile_width, tile_thickness);
|
sample_tile(i, tile_width, tile_thickness);
|
||||||
sample_tile(6, tile_width, tile_thickness);
|
}
|
||||||
sample_tile(7, tile_width, tile_thickness);
|
|
||||||
sample_tile(8, tile_width, tile_thickness);
|
|
||||||
sample_tile(9, tile_width, tile_thickness);
|
|
||||||
sample_tile(10, tile_width, tile_thickness);
|
|
||||||
sample_tile(11, tile_width, tile_thickness);
|
|
||||||
sample_tile(12, tile_width, tile_thickness);
|
|
||||||
sample_tile(13, tile_width, tile_thickness);
|
|
||||||
sample_tile(14, tile_width, tile_thickness);
|
|
||||||
sample_tile(15, tile_width, tile_thickness);
|
|
||||||
}
|
|
||||||
|
|
||||||
translate([0, tile_width * (rows + 1)]) {
|
|
||||||
color("LightGrey")
|
|
||||||
linear_extrude(tile_thickness / 2)
|
|
||||||
square([columns * tile_width, rows * tile_width]);
|
|
||||||
|
|
||||||
|
translate([0, tile_width * (rows + 1)] + [tile_width, tile_width] / 2)
|
||||||
color("green")
|
color("green")
|
||||||
linear_extrude(tile_thickness)
|
for(tile = tile_w2e(rows, columns)) {
|
||||||
tiles_wang_2e(rows, columns, tile_width) {
|
x = tile[0];
|
||||||
path_tile(0, tile_width);
|
y = tile[1];
|
||||||
path_tile(1, tile_width);
|
i = tile[2];
|
||||||
path_tile(2, tile_width);
|
translate([x, y] * tile_width)
|
||||||
path_tile(3, tile_width);
|
path_tile(i, tile_width);
|
||||||
path_tile(4, tile_width);
|
}
|
||||||
path_tile(5, tile_width);
|
|
||||||
path_tile(6, tile_width);
|
|
||||||
path_tile(7, tile_width);
|
|
||||||
path_tile(8, tile_width);
|
|
||||||
path_tile(9, tile_width);
|
|
||||||
path_tile(10, tile_width);
|
|
||||||
path_tile(11, tile_width);
|
|
||||||
path_tile(12, tile_width);
|
|
||||||
path_tile(13, tile_width);
|
|
||||||
path_tile(14, tile_width);
|
|
||||||
path_tile(15, tile_width);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module sample_tile(n, width, thickness) {
|
module sample_tile(n, width, thickness) {
|
||||||
half_w = width / 2;
|
half_w = width / 2;
|
||||||
|
46
src/experimental/tile_w2e.scad
Normal file
46
src/experimental/tile_w2e.scad
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
// wang tiles - 2 edges
|
||||||
|
|
||||||
|
function tile_w2e(rows, columns, mask, seed) =
|
||||||
|
let(
|
||||||
|
edges = is_undef(seed) ? [
|
||||||
|
for(y = [0:rows])
|
||||||
|
[
|
||||||
|
for(x = [0:columns])
|
||||||
|
let(rs = rands(0, 1, 2))
|
||||||
|
[round(rs[0]), round(rs[1])]
|
||||||
|
]
|
||||||
|
] : [
|
||||||
|
for(y = [0:rows])
|
||||||
|
[
|
||||||
|
for(x = [0:columns])
|
||||||
|
let(rs = rands(0, 1, 2, seed + y * columns + x))
|
||||||
|
[round(rs[0]), round(rs[1])]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
m = is_undef(mask) ? [
|
||||||
|
for(y = [0:rows - 1])
|
||||||
|
[for(x = [0:columns - 1]) 1]
|
||||||
|
] : [
|
||||||
|
for(y = rows - 1; y > -1; y = y - 1)
|
||||||
|
[for(x = [0:columns - 1]) mask[y][x]]
|
||||||
|
],
|
||||||
|
/*
|
||||||
|
1
|
||||||
|
. - .
|
||||||
|
8 | | 2
|
||||||
|
. - .
|
||||||
|
4
|
||||||
|
*/
|
||||||
|
tiles = [
|
||||||
|
for(y = [0:rows - 1])
|
||||||
|
for(x = [0:columns - 1])
|
||||||
|
if(m[y][x] == 1)
|
||||||
|
[x, y,
|
||||||
|
(edges[y + 1][x][0] == 1 ? 1 : 0) +
|
||||||
|
(edges[y][x + 1][1] == 1 ? 2 : 0) +
|
||||||
|
(edges[y][x][0] == 1 ? 4 : 0) +
|
||||||
|
(edges[y][x][1] == 1 ? 8 : 0)
|
||||||
|
]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
tiles;
|
Reference in New Issue
Block a user