DiceTower.scad 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. y = 10;
  108. {
  109. intersection() {
  110. translate([-tower_radius, 0, 0]) rotate([0,0,exit]) scale([-1, 1, 1]) {
  111. difference() {
  112. cylinder(r=tower_radius + 2, h=tower_radius+y, center=false);
  113. translate([0,0,-1]) cylinder(r=tower_radius, h=tower_radius + 2+y, center=false);
  114. }
  115. }
  116. translate([0,0,-2]) cylinder(r=tower_radius - 2, h=tower_radius + 4 + y, center=false);
  117. }
  118. }
  119. }
  120. module bottom_stairs_and_banister() {
  121. difference() {
  122. union() {
  123. translate([-tower_radius, 0, 0]) rotate([0,0,exit]) scale([-1, 1, 1]) {
  124. difference() {
  125. stairs(tower_radius, bottom_stairs, twists=.14, step_height = 5.8, step_depth = 5);
  126. cylinder(r=5/2, h=bottom_stairs, center=false);
  127. }
  128. }
  129. }
  130. translate([0,0,bottom_stairs]) cylinder(r=tower_radius, h=tower_height, center=false);
  131. rotate([0,0,193]) translate([-10,0,0]) cube(size=[tower_radius + 10, tower_radius, bottom_stairs * 2], center=false);
  132. }
  133. difference() {
  134. union() {
  135. banister();
  136. }
  137. rotate([0,0,180]) translate([-10,0,0]) cube(size=[tower_radius + 10, tower_radius, bottom_stairs * 3], center=false);
  138. }
  139. }
  140. module double_stairs() {
  141. intersection() {
  142. cylinder(r=tower_radius - brick_depth / 2, h=tower_height, center=false);
  143. union() {
  144. translate([0,0,bottom_stairs]) {
  145. rotate([0,0,180]) stairs(tower_radius, tower_height - bottom_stairs, step_height = step_height, step_depth = step_depth, twists = twists, underslope = underslope);
  146. difference() {
  147. stairs(tower_radius, tower_height - bottom_stairs, step_height = step_height, step_depth = step_depth, twists = twists, underslope = underslope);
  148. //translate([0,0,-1]) cylinder(r=tower_radius, h=dungeon_extra + 1, center=false);
  149. // Banister
  150. translate([0,0,-1]) intersection() {
  151. translate([-tower_radius, 0, 0]) rotate([0,0,exit]) scale([-1, 1, 1]) {
  152. difference() {
  153. cylinder(r=tower_radius * 2, h=tower_radius, center=false);
  154. translate([0,0,-1]) cylinder(r=tower_radius, h=tower_radius + 2, center=false);
  155. }
  156. }
  157. translate([0,0,-2]) cylinder(r=tower_radius - 2, h=tower_radius + 4, center=false);
  158. }
  159. }
  160. }
  161. }
  162. }
  163. }
  164. module floor() {
  165. cylinder(r=tower_radius, h=2, center=false);
  166. }
  167. module dungeon_bars() {
  168. max=8;
  169. module loop(n) {
  170. if (n >= 0) {
  171. rotate([0,0,n * -14.5]) translate([0, tower_radius - (2.5 * 1.5), 0]) scale([1,1.25,1]) {
  172. bonus=sin((n/max) * 180) * 18.5 + 4;
  173. cylinder(r=2.5, h=dungeon_height + bonus, center=false);
  174. }
  175. loop(n - 1);
  176. }
  177. }
  178. rotate([0,0,exit + dungeon_angle]) loop(max);
  179. }
  180. module generic_neg(angle, size, ratio) {
  181. rotate([0,0,angle]) scale([1,1,ratio]) pinch(tower_radius + 10, size);
  182. }
  183. module generic_rim(angle, size, ratio, offset, border = 5) {
  184. rotate([0,0,angle]) difference() {
  185. translate([0,0,offset]) scale([1,1,ratio]) pinch(tower_radius + border, size + border);
  186. scale([1,1,ratio]) pinch(tower_radius + 10, size);
  187. }
  188. }
  189. module front_door_neg() {
  190. generic_neg(exit, tower_radius / 2, 2);
  191. }
  192. module front_door_rim() {
  193. generic_rim(exit, tower_radius / 2, 2, -4);
  194. }
  195. module dungeon_window_neg() {
  196. generic_neg(dungeon_angle, tower_radius);
  197. }
  198. module dungeon_window_rim() {
  199. generic_rim(dungeon_angle, tower_radius, 1, 2);
  200. }
  201. module window_neg(h, z) {
  202. difference() {
  203. translate([0,0,h]) rotate([0,0,exit+z])
  204. generic_neg(90, 10, 1.5);
  205. cylinder(r=tower_radius + 10, h);
  206. }
  207. }
  208. module window_rim(h, z) {
  209. difference() {
  210. translate([0,0,h]) rotate([0,0,exit+z])
  211. generic_rim(90, 10, 1.5, border=2);
  212. cylinder(r=tower_radius + 10, h);
  213. }
  214. translate([0,0,h])
  215. mirror([0,0,1])
  216. rotate([0,0,z - 121.5])
  217. linear_extrude(height=2, center=false, convexity=10, twist=0, scale=[.95,1]) {
  218. pie_slice(tower_radius + 2, -15.5, 15.5 );
  219. }
  220. }
  221. module detents(clearance = 0) {
  222. rotate([0,0,45]) {
  223. rotate([0,0,0]) translate([tower_radius - brick_depth / 2,0,0]) sphere(1.5 + clearance);
  224. rotate([0,0,180]) translate([tower_radius - brick_depth / 2,0,0]) sphere(1.5 + clearance);
  225. detent_r = pin_diameter / 2 + pin_clearance * 2;
  226. translate([0,0,pin_height - detent_r]) sphere(detent_r + clearance);
  227. }
  228. }
  229. //if (false)
  230. union() {
  231. color("grey") floor();
  232. color("grey") double_stairs();
  233. color("grey") difference() {
  234. tower(tower_radius, tower_height);
  235. front_door_neg();
  236. dungeon_window_neg();
  237. window_neg(100, 0);
  238. window_neg(100, 180);
  239. window_neg(75, 60);
  240. window_neg(75, 240);
  241. window_neg(50, 120);
  242. window_neg(50, 300);
  243. }
  244. color("grey") intersection() {
  245. //tower(tower_radius + 5, 60);
  246. difference() {
  247. cylinder(r=tower_radius + 5, h=60, center=false);
  248. cylinder(r=tower_radius + 5 - brick_depth, h=60, center=false);
  249. }
  250. union() {
  251. front_door_rim();
  252. dungeon_window_rim();
  253. }
  254. }
  255. color("grey") intersection() {
  256. //tower(tower_radius + 2, tower_height);
  257. difference() {
  258. cylinder(r=tower_radius + 2, h=tower_height, center=false);
  259. cylinder(r=tower_radius + 2 - brick_depth, h=tower_height, center=false);
  260. }
  261. union() {
  262. window_rim(100, 0);
  263. window_rim(100, 180);
  264. window_rim(75, 60);
  265. window_rim(75, 240);
  266. window_rim(50, 120);
  267. window_rim(50, 300);
  268. }
  269. }
  270. color("grey") dungeon_bars();
  271. color("grey") bottom_stairs_and_banister();
  272. color("grey") cylinder(r=pin_diameter / 2, h=tower_height + pin_height, center=false);
  273. color("red") translate([0,0,tower_height]) detents();
  274. }
  275. //$fn=25;
  276. //if (false)
  277. color("grey") translate([0,0,tower_height]) {
  278. radius = tower_radius + 5;
  279. difference() {
  280. union() {
  281. translate([0, 0, 20]) sphere(7);
  282. difference() {
  283. union() {
  284. tower(radius, 25);
  285. difference() {
  286. cylinder(r=radius - brick_depth / 2, h=2, center=false);
  287. linear_extrude(height=5, center=true) {
  288. pie_slice(tower_radius - brick_depth, -100, 45);
  289. }
  290. translate([0,0,2]) { // Grooves
  291. rotate_extrude(convexity=10) {
  292. translate([(radius - brick_depth / 2) * .25, 0, 0]) rotate([0,0,45]) square([groove,groove], center=true);
  293. translate([(radius - brick_depth / 2) * .5, 0, 0]) rotate([0,0,45]) square([groove,groove], center=true);
  294. translate([(radius - brick_depth / 2) * .75, 0, 0]) rotate([0,0,45]) square([groove,groove], center=true);
  295. }
  296. for (i=[1:5]) {
  297. rotate([0,90+180,45+180 + 35 * i]) rotate([0,0,45]) linear_extrude(height=tower_radius, center=false, convexity=10, twist=0) {
  298. square(groove, groove, center=true);
  299. }
  300. }
  301. }
  302. }
  303. rotate([0,0,-100]) translate([0, -2]) cube([radius - brick_depth / 2, 2, 20]);
  304. cylinder(r=pin_diameter / 2 + pin_clearance * 2 + 2, h=20, center=false);
  305. translate([0,0,25 - 3.5]) {
  306. difference() {
  307. rotate_extrude(convexity=10) {
  308. translate([radius - brick_depth / 2, 0, 0]) rotate([0,0,45]) square([7,7]);
  309. }
  310. }
  311. }
  312. }
  313. rampart_width = 15;
  314. ramparts = 8;
  315. translate([0,0,20]) {
  316. for (z = [0:ramparts - 1]) {
  317. rotate([0,0,360 / ramparts * z])
  318. linear_extrude(height=20, center=false, convexity=10, twist=0) {
  319. pie_slice(radius + 10, -rampart_width / 2, rampart_width / 2);
  320. }
  321. }
  322. }
  323. }
  324. translate([0,0,2]) { // Lip
  325. rotate([0,90+180,45+180]) rotate([0,0,45]) linear_extrude(height=tower_radius, center=false, convexity=10, twist=0) {
  326. square(groove, groove, center=true);
  327. }
  328. }
  329. translate([0,0,2]) { // Rim
  330. rotate_extrude(convexity=10) {
  331. translate([radius - .25, 0, 0]) circle(2, center=true);
  332. }
  333. }
  334. }
  335. color("red") detents(pin_clearance);
  336. cylinder(r=pin_diameter / 2 + pin_clearance * 2, h=pin_height + pin_clearance, center=true);
  337. rotate([0,0,-30]) translate([0,-.5, -1]) cube([10,2,10]);
  338. }
  339. }