mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-01-18 06:38:14 +01:00
add maze_masking
This commit is contained in:
parent
498b15c59d
commit
a1d17e5ec5
95
examples/maze/maze_masking.scad
Normal file
95
examples/maze/maze_masking.scad
Normal file
@ -0,0 +1,95 @@
|
||||
use <maze/mz_blocks.scad>;
|
||||
use <maze/mz_square_walls.scad>;
|
||||
use <maze/mz_initialize.scad>;
|
||||
use <voxel/vx_contour.scad>;
|
||||
|
||||
start = [2, 2];
|
||||
mask = [
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
|
||||
[0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
|
||||
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0],
|
||||
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
|
||||
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
|
||||
[0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0],
|
||||
[0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0],
|
||||
[0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
|
||||
[0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
|
||||
];
|
||||
|
||||
block_width = 3;
|
||||
wall_thickness = 1;
|
||||
wall_height = 2;
|
||||
base_height = 1;
|
||||
contour = true;
|
||||
base = true;
|
||||
|
||||
module maze_masking(start, mask, block_width, wall_thickness, wall_height, base_height, contour, base) {
|
||||
rows = len(mask);
|
||||
columns = len(mask[0]);
|
||||
|
||||
blocks = mz_blocks(
|
||||
start,
|
||||
rows, columns,
|
||||
mz_initialize(mask = mask)
|
||||
);
|
||||
|
||||
pts = vx_contour([
|
||||
for(y = [0:rows - 1])
|
||||
for(x = [0:columns - 1])
|
||||
if(mask[y][x] == 1)
|
||||
[x, rows - y - 1]
|
||||
]);
|
||||
|
||||
walls = mz_square_walls(blocks, rows, columns, block_width);
|
||||
|
||||
color("gray")
|
||||
linear_extrude(wall_height)
|
||||
intersection() {
|
||||
union() {
|
||||
for(wall = walls) {
|
||||
for(i = [0:len(wall) - 2]) {
|
||||
if(wall[i][0] != 0 && wall[i][1] != 0) {
|
||||
hull() {
|
||||
translate(wall[i])
|
||||
square(wall_thickness);
|
||||
translate(wall[i + 1])
|
||||
square(wall_thickness);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for(y = [0:rows - 1]) {
|
||||
for(x = [0:columns - 1]) {
|
||||
if(mask[rows - y - 1][x] == 0) {
|
||||
translate([x * block_width + wall_thickness, y * block_width + wall_thickness])
|
||||
square(block_width);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(contour) {
|
||||
translate([wall_thickness * 2, wall_thickness * 2])
|
||||
polygon(pts * block_width);
|
||||
}
|
||||
}
|
||||
|
||||
if(base) {
|
||||
if(contour) {
|
||||
translate([0, 0, -base_height])
|
||||
linear_extrude(base_height)
|
||||
translate([wall_thickness * 2, wall_thickness * 2])
|
||||
polygon(pts * block_width);
|
||||
}
|
||||
else {
|
||||
translate([0, 0, -base_height])
|
||||
linear_extrude(base_height)
|
||||
translate([wall_thickness, wall_thickness])
|
||||
square([columns, rows] * block_width);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
maze_masking(start, mask, block_width, wall_thickness, wall_height, base_height, contour, base);
|
Loading…
x
Reference in New Issue
Block a user