mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-06 14:56:47 +02:00
add doc
This commit is contained in:
@@ -251,7 +251,7 @@ These examples incubate dotSCAD and dotSCAD refactors these examples. See [examp
|
|||||||
- [mz_square_get](https://openhome.cc/eGossip/OpenSCAD/lib2x-mz_square_get.html)
|
- [mz_square_get](https://openhome.cc/eGossip/OpenSCAD/lib2x-mz_square_get.html)
|
||||||
- [mz_square_walls](https://openhome.cc/eGossip/OpenSCAD/lib2x-mz_square_walls.html)
|
- [mz_square_walls](https://openhome.cc/eGossip/OpenSCAD/lib2x-mz_square_walls.html)
|
||||||
- [mz_hex_walls](https://openhome.cc/eGossip/OpenSCAD/lib2x-mz_hex_walls.html)
|
- [mz_hex_walls](https://openhome.cc/eGossip/OpenSCAD/lib2x-mz_hex_walls.html)
|
||||||
- mz_square_initialize
|
- [mz_square_initialize](https://openhome.cc/eGossip/OpenSCAD/lib2x-mz_square_initialize.html)
|
||||||
- mz_hamiltonian
|
- mz_hamiltonian
|
||||||
|
|
||||||
----
|
----
|
||||||
|
BIN
docs/images/lib2x-mz_square_initialize-1.JPG
Normal file
BIN
docs/images/lib2x-mz_square_initialize-1.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 43 KiB |
BIN
docs/images/lib2x-mz_square_initialize-2.JPG
Normal file
BIN
docs/images/lib2x-mz_square_initialize-2.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
BIN
docs/images/lib2x-mz_square_initialize-3.JPG
Normal file
BIN
docs/images/lib2x-mz_square_initialize-3.JPG
Normal file
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
84
docs/lib2x-mz_square_initialize.md
Normal file
84
docs/lib2x-mz_square_initialize.md
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
# mz_square_initialize
|
||||||
|
|
||||||
|
It's a helper for initializing cell data of a maze.
|
||||||
|
|
||||||
|
**Since:** 2.5
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
- `rows` : The rows of the maze.
|
||||||
|
- `columns` : The columns of the maze.
|
||||||
|
- `mask` : The mask for a maze. A list of 0s and 1s. Cells makred as 0 won't be traveled.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
use <maze/mz_square_initialize.scad>;
|
||||||
|
use <maze/mz_square_cells.scad>;
|
||||||
|
use <maze/mz_square_walls.scad>;
|
||||||
|
use <polyline2d.scad>;
|
||||||
|
|
||||||
|
rows = 10;
|
||||||
|
columns = 10;
|
||||||
|
cell_width = 5;
|
||||||
|
wall_thickness = 2;
|
||||||
|
|
||||||
|
init_cells = mz_square_initialize(rows, columns);
|
||||||
|
cells = mz_square_cells(rows, columns, init_cells = init_cells);
|
||||||
|
walls = mz_square_walls(cells, rows, columns, cell_width);
|
||||||
|
|
||||||
|
for(wall = walls) {
|
||||||
|
polyline2d(wall, wall_thickness, joinStyle = "JOIN_MITER");
|
||||||
|
}
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
use <maze/mz_square_cells.scad>;
|
||||||
|
use <maze/mz_square_walls.scad>;
|
||||||
|
use <maze/mz_square_initialize.scad>;
|
||||||
|
use <polyline2d.scad>;
|
||||||
|
|
||||||
|
mask = [
|
||||||
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||||
|
[0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0],
|
||||||
|
[0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0],
|
||||||
|
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
|
||||||
|
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
|
||||||
|
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
|
||||||
|
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
|
||||||
|
[0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
|
||||||
|
[0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
|
||||||
|
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||||
|
];
|
||||||
|
start = [3, 3];
|
||||||
|
cell_width = 5;
|
||||||
|
wall_thickness = 2;
|
||||||
|
|
||||||
|
rows = len(mask);
|
||||||
|
columns = len(mask[0]);
|
||||||
|
init_cells = mz_square_initialize(mask = mask);
|
||||||
|
cells = mz_square_cells(rows, columns, start, init_cells);
|
||||||
|
walls = mz_square_walls(cells, rows, columns, cell_width, false, false);
|
||||||
|
|
||||||
|
// Maze
|
||||||
|
for(wall = walls) {
|
||||||
|
polyline2d(wall, wall_thickness, joinStyle = "JOIN_MITER");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mask
|
||||||
|
mask_width = cell_width + wall_thickness;
|
||||||
|
translate([-wall_thickness / 2, -wall_thickness / 2])
|
||||||
|
for(i = [0:rows - 1]) {
|
||||||
|
for(j = [0:columns - 1]) {
|
||||||
|
if(mask[i][j] == 0) {
|
||||||
|
translate([cell_width * j, cell_width * (rows - i - 1)])
|
||||||
|
square(mask_width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
I provide a tool [img2binary](https://github.com/JustinSDK/img2binary) for converting an image into 0 and 1. 0 is for black and 1 is for white. You may use it to create a mask from an image. The mask of [maze_masking](https://github.com/JustinSDK/dotSCAD/blob/master/examples/maze/maze_masking.scad) is an example.
|
||||||
|
|
||||||
|

|
@@ -1,3 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* mz_square_initialize.scad
|
||||||
|
*
|
||||||
|
* @copyright Justin Lin, 2020
|
||||||
|
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||||
|
*
|
||||||
|
* @see https://openhome.cc/eGossip/OpenSCAD/lib2x-mz_square_initialize.html
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
use <_impl/_mz_initialize.scad>;
|
use <_impl/_mz_initialize.scad>;
|
||||||
|
|
||||||
function mz_square_initialize(rows, columns, mask) =
|
function mz_square_initialize(rows, columns, mask) =
|
||||||
|
Reference in New Issue
Block a user