1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-11 17:24:20 +02:00

add height_scale

This commit is contained in:
Justin Lin
2021-02-28 17:34:44 +08:00
parent 9fa4c7b6dc
commit 508a91174b

View File

@@ -5,10 +5,11 @@ use <maze/mz_theta_get.scad>;
rows = 4; rows = 4;
begining_columns = 6; begining_columns = 6;
cell_width = 10; cell_width = 12;
rock_size = 4; rock_size = 4;
height_scale = 3;
rock_theta_maze(rows, begining_columns, cell_width); rock_theta_maze(rows, begining_columns, cell_width, rock_size, height_scale);
module rock(width = 1) { module rock(width = 1) {
n = 15 * rands(1, 1.25, 1)[0]; n = 15 * rands(1, 1.25, 1)[0];
@@ -21,58 +22,64 @@ module rock(width = 1) {
for(i = [0:n - 1]) [r * cos(theta[i]), r * sin(theta[i]), r * cos(phi[i])]]); for(i = [0:n - 1]) [r * cos(theta[i]), r * sin(theta[i]), r * cos(phi[i])]]);
} }
module rock_wall(p1, p2) { module rock_wall(p1, p2, size) {
dvt = p2 - p1; dvt = p2 - p1;
leng = norm(dvt); leng = norm(dvt);
uvt = dvt / leng; uvt = dvt / leng;
along_with([for(i = [0:3:leng]) p1 + uvt * i], method = "EULER_ANGLE") along_with([for(i = [0:3:leng]) p1 + uvt * i], method = "EULER_ANGLE")
rock(rock_size); rock(size);
translate([0, 0, 1.2]) translate([0, 0, 1.2])
along_with([for(i = [0:4:leng - 1]) p1 + uvt * i], method = "EULER_ANGLE") along_with([for(i = [0:4:leng - 1]) p1 + uvt * i], method = "EULER_ANGLE")
rock(rock_size * 0.875); rock(size * 0.875);
} }
module rock_theta_maze(rows, begining_columns, cell_width) { module rock_theta_maze(rows, begining_columns, cell_width, rock_size, height_scale) {
function vt_from_angle(theta, r) = [r * cos(theta), r * sin(theta)]; function vt_from_angle(theta, r) = [r * cos(theta), r * sin(theta)];
maze = mz_theta_cells(rows, begining_columns); maze = mz_theta_cells(rows, begining_columns);
{ scale([1, 1, height_scale])
for(rows = maze) { difference() {
for(cell = rows) { union() {
ri = mz_theta_get(cell, "r"); for(rows = maze) {
ci = mz_theta_get(cell, "c"); for(cell = rows) {
wallType = mz_theta_get(cell, "t");
thetaStep = 360 / len(maze[ri]); ri = mz_theta_get(cell, "r");
innerR = (ri + 1) * cell_width; ci = mz_theta_get(cell, "c");
outerR = (ri + 2) * cell_width; if([ri, ci] != [0, 0]) {
theta1 = thetaStep * ci; wallType = mz_theta_get(cell, "t");
theta2 = thetaStep * (ci + 1); thetaStep = 360 / len(maze[ri]);
innerR = (ri + 1) * cell_width;
innerVt1 = vt_from_angle(theta1, innerR); outerR = (ri + 2) * cell_width;
innerVt2 = vt_from_angle(theta2, innerR); theta1 = thetaStep * ci;
outerVt2 = vt_from_angle(theta2, outerR); theta2 = thetaStep * (ci + 1);
if(wallType == "INWARD_WALL" || wallType == "INWARD_CCW_WALL") { innerVt1 = vt_from_angle(theta1, innerR);
innerVt2 = vt_from_angle(theta2, innerR);
rock_wall(innerVt1, innerVt2); outerVt2 = vt_from_angle(theta2, outerR);
}
if(wallType == "INWARD_WALL" || wallType == "INWARD_CCW_WALL") {
rock_wall(innerVt1, innerVt2, rock_size);
}
if(wallType == "CCW_WALL" || wallType == "INWARD_CCW_WALL") { if(wallType == "CCW_WALL" || wallType == "INWARD_CCW_WALL") {
rock_wall(innerVt2, outerVt2); rock_wall(innerVt2, outerVt2, rock_size);
} }
}
}
}
thetaStep = 360 / len(maze[rows - 1]);
r = cell_width * (rows + 1);
for(theta = [0:thetaStep:360 - thetaStep * 2]) {
vt1 = vt_from_angle(theta, r);
vt2 = vt_from_angle(theta + thetaStep, r);
rock_wall(vt1, vt2, rock_size);
} }
} }
translate([0, 0, -cell_width * rows * 2])
thetaStep = 360 / len(maze[rows - 1]); cube(cell_width * rows * 4, center = true);
r = cell_width * (rows + 1);
for(theta = [0:thetaStep:360 - thetaStep]) {
vt1 = vt_from_angle(theta, r);
vt2 = vt_from_angle(theta + thetaStep, r);
rock_wall(vt1, vt2);
}
} }
} }