DiceTower.scad 14 KB

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