/ examples / maze / rock_theta_maze.scad
rock_theta_maze.scad
 1  use <along_with.scad>
 2  use <polyhedron_hull.scad>
 3  use <maze/mz_theta.scad>
 4  use <maze/mz_theta_get.scad>
 5  
 6  rings = 4;
 7  begining_columns = 6;
 8  cell_width = 12;
 9  rock_size = 4;
10  height_scale = 3;
11  flat_base = false;
12  
13  rock_theta_maze(rings, begining_columns, cell_width, rock_size, height_scale, flat_base);
14  
15  module rock(width = 1) {
16  	n = 15 * rands(1, 1.25, 1)[0];
17  	r = width / 2 * rands(1, 1.25, 1)[0];
18      theta = rands(0, 359, n);
19  	phi = rands(0, 359, n);
20  	
21  	scale([1, 1.25, 2])
22  	polyhedron_hull([
23  	    for(i = [0:n - 1]) [r * cos(theta[i]), r * sin(theta[i]), r * cos(phi[i])]]);
24  }
25  
26  module rock_wall(p1, p2, size) {
27      dvt = p2 - p1;
28      leng = norm(dvt);
29  	uvt = dvt / leng;
30  	
31      along_with([for(i = [0:3:leng]) p1 + uvt * i], method = "EULER_ANGLE")
32  	    rock(size);
33  		
34  	translate([0, 0, 1.2])
35      along_with([for(i = [0:4:leng - 1]) p1 + uvt * i], method = "EULER_ANGLE")
36  	    rock(size * 0.875);
37  }
38  
39  module rock_theta_maze(rings, begining_columns, cell_width, rock_size, height_scale, flat_base) {
40  	function vt_from_angle(theta, r) = [r * cos(theta), r * sin(theta)];
41  
42  	maze = mz_theta(rings, begining_columns);
43  
44  	scale([1, 1, height_scale]) 
45  	difference() {
46  		union() {
47  			for(rings = maze, cell = rings) {	
48  				ri = mz_theta_get(cell, "r");
49  				ci = mz_theta_get(cell, "c");
50  				if([ri, ci] != [0, 0]) {
51  					wallType = mz_theta_get(cell, "t");
52  					thetaStep = 360 / len(maze[ri]);
53  					innerR = (ri + 1) * cell_width;
54  					outerR = (ri + 2) * cell_width;
55  					theta1 = thetaStep * ci;
56  					theta2 = thetaStep * (ci + 1);
57  					
58  					innerVt1 = vt_from_angle(theta1, innerR);
59  					innerVt2 = vt_from_angle(theta2, innerR);
60  					outerVt2 = vt_from_angle(theta2, outerR);
61  					
62  					if(wallType == "INWARD_WALL" || wallType == "INWARD_CCW_WALL") {
63  						rock_wall(innerVt1, innerVt2, rock_size);
64  					}
65  
66  					if(wallType == "CCW_WALL" || wallType == "INWARD_CCW_WALL") {
67  						rock_wall(innerVt2, outerVt2, rock_size);
68  					}
69  				}
70  			}
71  			
72  			thetaStep = 360 / len(maze[rings - 1]);
73  			r = cell_width * (rings + 1);
74  			for(theta = [0:thetaStep:360 - thetaStep * 2]) {
75  				vt1 = vt_from_angle(theta, r);
76  				vt2 = vt_from_angle(theta + thetaStep, r);
77  				rock_wall(vt1, vt2, rock_size);
78  			} 
79  		}
80  		if(flat_base) {
81  			translate([0, 0, -cell_width * rings * 2])
82  				cube(cell_width * rings * 4, center = true);
83  		}
84  	}
85  }