diff --git a/README.md b/README.md index f2cabb39..b4729de6 100644 --- a/README.md +++ b/README.md @@ -248,10 +248,10 @@ These examples incubate dotSCAD and dotSCAD refactors these examples. See [examp ### Maze - [mz_square_cells](https://openhome.cc/eGossip/OpenSCAD/lib2x-mz_square_cells.html) -- mz_square_get -- mz_square_initialize +- [mz_square_get](https://openhome.cc/eGossip/OpenSCAD/lib2x-mz_square_get.html) - mz_square_walls - mz_hex_walls +- mz_square_initialize - mz_hamiltonian ---- diff --git a/docs/images/lib2x-mz_square_get-1.JPG b/docs/images/lib2x-mz_square_get-1.JPG new file mode 100644 index 00000000..7c0ccb16 Binary files /dev/null and b/docs/images/lib2x-mz_square_get-1.JPG differ diff --git a/docs/lib2x-mz_square_get.md b/docs/lib2x-mz_square_get.md new file mode 100644 index 00000000..1ec6de27 --- /dev/null +++ b/docs/lib2x-mz_square_get.md @@ -0,0 +1,44 @@ +# mz_square_get + +It's a helper for getting data from a maze cell. + +**Since:** 2.5 + +## Parameters + +- `cell` : A maze cell. +- `query` : Accepts `"x"`, `"y"` or `"t"`. `"x"` for the cell's x coordinate. `"y"` for the cell's y coordinate. `"t"` for the cell's type. The returned type will be `"NO_WALL"`, `"TOP_WALL"`, `"RIGHT_WALL"`, `"TOP_RIGHT_WALL"` or `"MASK"`. + +## Examples + + use ; + use ; + use ; + + rows = 10; + columns = 10; + cell_width = 5; + wall_thickness = 2; + + cells = mz_square_cells(rows, columns); + + for(cell = cells) { + x = mz_square_get(cell, "x"); + y = mz_square_get(cell, "y"); + type = mz_square_get(cell, "t");; + + translate([x, y] * cell_width) { + if(type == "TOP_WALL" || type == "TOP_RIGHT_WALL") { + line2d([0, cell_width], [cell_width, cell_width], wall_thickness); + } + + if(type == "RIGHT_WALL" || type == "TOP_RIGHT_WALL") { + line2d([cell_width, cell_width], [cell_width, 0], wall_thickness); + } + } + } + + line2d([0, 0], [cell_width * rows, 0], wall_thickness); + line2d([0, 0], [0, cell_width * columns], wall_thickness); + +![mz_square_get](images/lib2x-mz_square_get-1.JPG) \ No newline at end of file diff --git a/src/maze/mz_square_get.scad b/src/maze/mz_square_get.scad index b12728f9..db76b482 100644 --- a/src/maze/mz_square_get.scad +++ b/src/maze/mz_square_get.scad @@ -1,3 +1,13 @@ +/** +* mz_square_get.scad +* +* @copyright Justin Lin, 2020 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib2x-mz_square_get.html +* +**/ + function mz_square_get(cell, query) = let( i = search(query, [