tower.scad 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. {
  30. translate([radius * cos(start_deg), radius * sin(start_deg)]) {
  31. rotate([0, 0, 45]) {
  32. square(size=[groove, groove], center=true);
  33. }
  34. }
  35. }
  36. }
  37. module loop(n) {
  38. if (n > 0) {
  39. union(){
  40. ring(n);
  41. rotate([0,0,brick_width_deg / 2]) {
  42. translate([0,0,brick_height]) {
  43. loop(n - 1);
  44. }
  45. }
  46. }
  47. }
  48. }
  49. difference() {
  50. color("silver") cylinder(r=radius, h=height, center=false);
  51. translate([0,0,-1]) {
  52. cylinder(r=radius - brick_depth, h=height + 2, center=false);
  53. }
  54. if (!draft) {
  55. color("silver") loop(rings + 1);
  56. }
  57. }
  58. }