1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-09 00:06:42 +02:00

add mz_wang_tiles

This commit is contained in:
Justin Lin
2021-12-26 18:50:16 +08:00
parent cc15a7df8b
commit cd4dda3b39
2 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
use <../../util/has.scad>;
function _mz_wang_tiles_top(x, y) =
let(
nx = x * 2,
ny = y * 2
)
[[nx + 1, ny + 2]];
function _mz_wang_tiles_right(x, y) =
let(
nx = x * 2,
ny = y * 2
)
[[nx + 2, ny + 1]];
function _mz_wang_tiles_top_right(x, y) =
let(
nx = x * 2,
ny = y * 2
)
[[nx + 1, ny + 2], [nx + 2, ny + 1]];
function _mz_wang_tile_type(dots, x, y) =
let(
px = x * 2 + 1,
py = y * 2 + 1,
c1 = !has(dots, [px, py + 1], sorted = true) ? 1 : 0,
c2 = !has(dots, [px + 1, py], sorted = true) ? 2 : 0,
c3 = !has(dots, [px, py - 1], sorted = true) ? 4 : 0,
c4 = !has(dots, [px - 1, py], sorted = true) ? 8 : 0
)
c1 + c2 + c3 + c4;

View File

@@ -0,0 +1,46 @@
/**
* mz_wang_tiles.scad
*
* @copyright Justin Lin, 2020
* @license https://opensource.org/licenses/lgpl-3.0.html
*
* @see https://openhome.cc/eGossip/OpenSCAD/lib3x-mz_wang_tiles.html
*
**/
use <_impl/_mz_wang_tiles_impl.scad>;
use <mz_square_cells.scad>;
use <mz_square_get.scad>;
use <../util/sort.scad>;
use <../util/dedup.scad>;
function mz_wang_tiles(rows, columns, start = [0, 0], init_cells, seed) =
let(
cells = mz_square_cells(
rows, columns,
init_cells = init_cells,
seed = seed
),
all = concat(
[
for(cell = cells)
let(
x = mz_square_get(cell, "x"),
y = mz_square_get(cell, "y"),
type = mz_square_get(cell, "t"),
pts = type == "TOP_WALL" ? _mz_wang_tiles_top(x, y) :
type == "RIGHT_WALL" ? _mz_wang_tiles_right(x, y) :
type == "TOP_RIGHT_WALL" || type == "MASK" ? _mz_wang_tiles_top_right(x, y) : []
)
each pts
],
[for(x = [0:columns - 1]) [x * 2 + 1, 0]],
[for(y = [0:rows - 1]) [0, y * 2 + 1]]
),
dot_pts = dedup(sort(all, by = "vt"))
)
[
for(y = [0:rows - 1])
for(x = [0:columns - 1])
[x, y, _mz_wang_tile_type(dot_pts, x, y)]
];