DiceTower.scad 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. include <config.scad>;
  2. include <pie_slice.scad>;
  3. include <tower.scad>;
  4. include <pinch.scad>;
  5. module step(radius, angle, height, overhang = 2, underslope = 45) {
  6. step_depth = (PI * radius) * (angle / 360);
  7. echo("step_depth", step_depth);
  8. union() {
  9. difference() {
  10. linear_extrude(height=height * 2, center=true) {
  11. pie_slice(radius, 0, angle);
  12. }
  13. rotate([0,90,0]) translate([height,0,radius]) {
  14. rotate([0,0,0])
  15. rotate([0,180,-underslope]) translate([0,0,0])
  16. cube([step_depth * 4,step_depth * 4,radius], center=false);
  17. }
  18. }
  19. if (!draft) {
  20. translate([0,0,height - overhang / 2]) rotate([0,90,0]){
  21. cylinder(r=overhang / 2, h=radius + 1, center=false, $fn=8);
  22. }
  23. }
  24. }
  25. }
  26. /*
  27. module step() {
  28. union() {
  29. linear_extrude(height=actual_step_height * 2, center=true) {
  30. pie_slice(radius + 1, 0, step_depth_deg);
  31. }
  32. rotate([0,90,0]) translate([step_height * 2,0,radius]) {
  33. rotate([0,0,0])
  34. for (s = [0,10]) {
  35. translate([0,-step_depth * 2,s * 10])
  36. cube([5,5,5], center=false);
  37. }
  38. }
  39. if (!draft) {
  40. translate([0,0,step_height - overhang / 2]) rotate([0,90,0]){
  41. cylinder(r=overhang / 2, h=radius + 1, center=false, $fn=8);
  42. }
  43. }
  44. }
  45. }
  46. //*/
  47. module stairs(radius, height, twists = 1, step_height = 1, step_depth = 1, overhang = 2, underslope = 45) {
  48. steps = floor((PI * radius * twists) / step_depth);
  49. step_depth_deg = (360 * twists) / steps;
  50. actual_step_height = height / floor(height / step_height);
  51. actual_step_depth = (step_depth_deg / 360) * (PI * radius * 2);
  52. floor_degree = atan2(actual_step_height, actual_step_depth);
  53. /*
  54. module step() {
  55. union() {
  56. linear_extrude(height=actual_step_height * 2, center=true) {
  57. pie_slice(radius + 1, 0, step_depth_deg);
  58. }
  59. rotate([0,90,0]) translate([step_height * 2,0,radius]) {
  60. rotate([0,0,0])
  61. for (s = [0,10]) {
  62. translate([0,-step_depth * 2,s * 10])
  63. cube([5,5,5], center=false);
  64. }
  65. }
  66. if (!draft) {
  67. translate([0,0,step_height - overhang / 2]) rotate([0,90,0]){
  68. cylinder(r=overhang / 2, h=radius + 1, center=false, $fn=8);
  69. }
  70. }
  71. }
  72. }
  73. // */
  74. module underside() {
  75. // linear_extrude(
  76. // height = height,
  77. // center = false,
  78. // twist = -twists * 360 - step_depth_deg,
  79. // $fn = 250
  80. // ) {
  81. // pie_slice(radius * 2, 0, 90, $fn=16);
  82. // }
  83. }
  84. module all_steps() {
  85. for (s = [0:steps]) {
  86. translate([0, 0, s * actual_step_height]) {
  87. rotate([0, 0, step_depth_deg * s]) {
  88. step(radius, step_depth_deg, actual_step_height, 2, underslope);
  89. }
  90. }
  91. }
  92. }
  93. intersection() {
  94. cylinder(r=radius, h=height, center=false, $fn=256);
  95. difference() {
  96. all_steps();
  97. if (!draft) {
  98. rotate([0,0,step_depth_deg / 2]) {
  99. underside();
  100. }
  101. }
  102. }
  103. }
  104. }
  105. module banister() {
  106. // Banister
  107. intersection() {
  108. translate([-tower_radius, 0, 0]) rotate([0,0,exit]) scale([-1, 1, 1]) {
  109. difference() {
  110. cylinder(r=tower_radius + 2, h=tower_radius, center=false);
  111. translate([0,0,-1]) cylinder(r=tower_radius, h=tower_radius + 2, center=false);
  112. }
  113. }
  114. translate([0,0,-2]) cylinder(r=tower_radius - 2, h=tower_radius + 4, center=false);
  115. }
  116. }
  117. module bottom_stairs_and_banister() {
  118. difference() {
  119. union() {
  120. translate([-tower_radius, 0, 0]) rotate([0,0,exit]) scale([-1, 1, 1]) {
  121. difference() {
  122. stairs(tower_radius, bottom_stairs, twists=.14, step_height = 5.8, step_depth = 5);
  123. cylinder(r=5/2, h=bottom_stairs, center=false);
  124. }
  125. }
  126. }
  127. translate([0,0,bottom_stairs]) cylinder(r=tower_radius, h=tower_height, center=false);
  128. rotate([0,0,193]) translate([-10,0,0]) cube(size=[tower_radius + 10, tower_radius, bottom_stairs * 2], center=false);
  129. }
  130. difference() {
  131. union() {
  132. banister();
  133. }
  134. rotate([0,0,180]) translate([-10,0,0]) cube(size=[tower_radius + 10, tower_radius, bottom_stairs * 2], center=false);
  135. }
  136. }
  137. module double_stairs() {
  138. intersection() {
  139. cylinder(r=tower_radius - brick_depth / 2, h=tower_height, center=false);
  140. union() {
  141. translate([0,0,bottom_stairs]) {
  142. stairs(tower_radius, tower_height - bottom_stairs, step_height = step_height, step_depth = step_depth, twists = twists, underslope = underslope);
  143. rotate([0,0,180]) stairs(tower_radius, tower_height - bottom_stairs, step_height = step_height, step_depth = step_depth, twists = twists, underslope = underslope);
  144. }
  145. }
  146. }
  147. }
  148. module floor() {
  149. cylinder(r=tower_radius, h=2, center=false);
  150. }
  151. module dungeon_bars() {
  152. max=8;
  153. module loop(n) {
  154. if (n >= 0) {
  155. rotate([0,0,n * -14.5]) translate([0, tower_radius - (2.5 * 1.5), 0]) scale([1,1.25,1]) {
  156. bonus=sin((n/max) * 180) * 18.5 + 4;
  157. cylinder(r=2.5, h=dungeon_height + bonus, center=false);
  158. }
  159. loop(n - 1);
  160. }
  161. }
  162. rotate([0,0,exit + dungeon_angle]) loop(max);
  163. }
  164. module front_door_neg() {
  165. scale([1,1,2]) rotate([90,0,exit]) cylinder(r=tower_radius / 2, h=100, center=false);
  166. }
  167. module front_door_rim() {
  168. // Front door rim
  169. intersection() {
  170. cylinder(r=tower_radius + 10, h=60, center=false);
  171. difference() {
  172. intersection() {
  173. scale([1,1,2]) rotate([90,0,exit]) cylinder(r=tower_radius / 2 + 5, h=90, center=false);
  174. cylinder(r=tower_radius + 10, h=tower_height, center=false);
  175. }
  176. // Front door
  177. scale([1,1,2]) rotate([90,0,exit]) cylinder(r=tower_radius / 2, h=100, center=false);
  178. // Inner tower
  179. cylinder(r=tower_radius - groove, h=tower_height, center=true);
  180. }
  181. }
  182. }
  183. module dungeon_window_neg() {
  184. rotate([0,0,dungeon_angle]) rotate([90,0,0]) translate([0,0,tower_radius]) cylinder(r=tower_radius, h=42, center=true);
  185. }
  186. module dungeon_window_rim() {
  187. rotate([0,0,dungeon_angle]) intersection() {
  188. //cyl(tower_radius + 10, 50, center=false);
  189. union() {
  190. intersection() {
  191. cylinder(r=tower_radius + 10, h=100, center=true);
  192. linear_extrude(height=tower_height, center=false, convexity=10, twist=0) {
  193. pie_slice(tower_radius + 10, 180 + 90 - 59.5, 180 + 90 + 59.5);
  194. }
  195. difference() {
  196. rotate([90,0,0]) translate([0,0,tower_radius]) cylinder(r=tower_radius + 5, h=42, center=true);
  197. difference() {
  198. rotate([0,0,-dungeon_angle]) scale([1,0.9,1]) dungeon_window_neg();
  199. linear_extrude(height=50, center=false) {
  200. pie_slice(tower_radius + 10, 180 + 90 - 59.5, 180 + 90 - 59.5 + 360 * (3 / (tower_radius * PI)));
  201. pie_slice(tower_radius + 10, 180 + 90 + 59.5, 180 + 90 + 59.5 - 360 * (3 / (tower_radius * PI)));
  202. }
  203. }
  204. }
  205. }
  206. // intersection() {
  207. // linear_extrude(height=50, center=false) {
  208. // pie_slice(tower_radius + 10, 180 + 90 - 59.5, 180 + 90 - 59.5 + 360 * (3 / (tower_radius * PI)));
  209. // pie_slice(tower_radius + 10, 180 + 90 + 59.5, 180 + 90 + 59.5 - 360 * (3 / (tower_radius * PI)));
  210. // }
  211. // rotate([90,0,0]) translate([0,0,tower_radius]) cylinder(r=tower_radius + 5, h=42, center=true);
  212. // }
  213. }
  214. }
  215. }
  216. //*
  217. union() {
  218. floor();
  219. double_stairs();
  220. difference() {
  221. tower(tower_radius, tower_height);
  222. front_door_neg();
  223. dungeon_window_neg();
  224. }
  225. intersection() {
  226. tower(tower_radius + 5, 60);
  227. union() {
  228. front_door_rim();
  229. dungeon_window_rim();
  230. }
  231. }
  232. dungeon_bars();
  233. bottom_stairs_and_banister();
  234. cylinder(r=pin_diameter / 2, h=tower_height + pin_height, center=false);
  235. }