tower.scad 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. module tower(radius, height) {
  2. // groove = .75;
  3. // target_brick_width = 10;
  4. // target_brick_height = 5;
  5. // brick_depth = 5;
  6. circum = 2 * radius * PI;
  7. bricks = floor(circum / target_brick_width);
  8. brick_width_deg = 360 / bricks;
  9. rings = floor(height / target_brick_height);
  10. brick_height = height / rings;
  11. $fn = bricks;
  12. module ring(n) {
  13. start_deg = 0;
  14. end_deg = brick_width_deg;
  15. translate([0, 0, -1]) {
  16. if (n > 1) {
  17. // Left groove
  18. for (i=[0:bricks]) {
  19. translate([radius * cos(brick_width_deg * i), radius * sin(brick_width_deg * i), 1]) {
  20. rotate([0, 0, 45 + brick_width_deg * i]) {
  21. cube(size=[groove, groove, brick_height], center=false);
  22. }
  23. }
  24. }
  25. }
  26. }
  27. // Bottom groove
  28. rotate_extrude() {
  29. translate([radius * cos(start_deg), radius * sin(start_deg)]) {
  30. rotate([0, 0, 45]) {
  31. square(size=[groove, groove], center=true);
  32. }
  33. }
  34. }
  35. }
  36. module loop(n) {
  37. if (n > 0) {
  38. union(){
  39. ring(n);
  40. rotate([0,0,brick_width_deg / 2]) {
  41. translate([0,0,brick_height]) {
  42. loop(n - 1);
  43. }
  44. }
  45. }
  46. }
  47. }
  48. difference() {
  49. cylinder(r=radius, h=height, center=false);
  50. translate([0,0,-1]) {
  51. cylinder(r=radius - brick_depth, h=height + 2, center=false);
  52. }
  53. if (!draft) {
  54. loop(rings + 1);
  55. }
  56. }
  57. }