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:
33
src/maze/_impl/_mz_wang_tiles_impl.scad
Normal file
33
src/maze/_impl/_mz_wang_tiles_impl.scad
Normal 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;
|
46
src/maze/mz_wang_tiles.scad
Normal file
46
src/maze/mz_wang_tiles.scad
Normal 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)]
|
||||
];
|
Reference in New Issue
Block a user