j0h

spotify_cipher_wheel.scad

j0h
May 18th, 2025
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.84 KB | Source Code | 0 0
  1. $fn = 100;
  2. /*
  3. A spotify cipher wheel.
  4.  
  5. 0th=spotify logo.
  6. 1st=1
  7. 24th=1
  8. 12th=7
  9. should generate a "valid" code
  10.  
  11. */
  12.  
  13.  
  14. module arcz(radius = 10, angle = 90, thickness = 2, steps = 100, center = [0, 0]) {
  15.     r1 = radius;
  16.     r2 = radius - thickness;
  17.  
  18.     outer_points = [
  19.         for (i = [0 : steps])
  20.             let(a = -angle / 2 + i * angle / steps)
  21.             [r1 * cos(a), r1 * sin(a)]
  22.     ];
  23.  
  24.     inner_points = [
  25.         for (i = [steps : 0 : -1])
  26.             let(a = -angle / 2 + i * angle / steps)
  27.             [r2 * cos(a), r2 * sin(a)]
  28.     ];
  29.  
  30.     polygon_points = concat(outer_points, inner_points);
  31.     translate(center)
  32.         polygon(points = polygon_points);
  33. }
  34.  
  35. //--- Main difference block ---
  36. difference() {
  37.     // Background cylinder
  38.     cylinder(h = 10, r = 10, $fn = 100);
  39.  
  40.     // Arc 1
  41.     translate([-6, 0, 0])
  42.     linear_extrude(10)
  43.     difference() {
  44.         arcz(radius = 6, angle = 120, thickness = 2);
  45.         translate([-1, 0]) arcz(radius = 6, angle = 120, thickness = 2);
  46.     }
  47.  
  48.     // Arc 2
  49.     translate([-5, 0, 0])
  50.     linear_extrude(10)
  51.     difference() {
  52.         arcz(radius = 8, angle = 120, thickness = 2);
  53.         translate([-1, 0]) arcz(radius = 8, angle = 120, thickness = 2);
  54.     }
  55.  
  56.     // Arc 3
  57.     translate([-4, 0, 0])
  58.     linear_extrude(10)
  59.     difference() {
  60.         arcz(radius = 10, angle = 120, thickness = 2);
  61.         translate([-1, 0]) arcz(radius = 10, angle = 120, thickness = 2);
  62.     }
  63. }
  64.  
  65. module hullz(length = 1, w = 3, h = 1) {
  66.     radius = w / 2;
  67.  
  68.     hull() {
  69.         translate([-length / 2, 0, 0])
  70.             cylinder(h = h, r = radius, $fn = 32);
  71.         translate([length / 2, 0, 0])
  72.             cylinder(h = h, r = radius, $fn = 32);
  73.     }
  74. }
  75.  
  76.  
  77. module ringz(count, ring_width = 10, height = 10, margin = 0.3) {
  78.     for (i = [2 : count+1]) {
  79.         outer_radius = i * (ring_width + margin);
  80.         inner_radius = outer_radius - ring_width;
  81.         mid_radius = (outer_radius + inner_radius) / 2;
  82.  
  83.         difference() {
  84.             // Main ring body
  85.             cylinder(h = height, r = outer_radius, $fn = 100);
  86.             cylinder(h = height + 0.1, r = inner_radius, $fn = 100);
  87.  
  88.             // 8 slots per ring
  89.             for (j = [0 : 7]) {
  90.                 angle = j * 45;
  91.                 len = j + 2;
  92.  
  93.                 rotate([0, 0, angle])
  94.                     translate([mid_radius, 0, 0])
  95.                         rotate([0, 0, 90])
  96.                             hullz(length = len, w = 3 / sqrt(2), h = height + 0.5);
  97.             }
  98.         }
  99.     }
  100. }
  101.  
  102.  
  103. ringz(24);
  104.  
  105.  
  106. /*
  107. module hullz(length = 1, w = 3, h = 1) {
  108.     // Calculate radius to ensure total width is exactly 3 mm
  109.     radius = abs(width - length) / 2;
  110.  
  111.     if (radius <= 0) {
  112.         echo("Error: length must be less than or equal to width");
  113.     } else {
  114.         hull() {
  115.             translate([0, 0, 0])
  116.                 cylinder(h = height, r = w, $fn = 32);
  117.             translate([length, 0, 0])
  118.                 cylinder(h = height, r = w, $fn = 32);
  119.         }
  120.     }
  121. }
  122.  
  123.  
  124. module note(length){
  125.     for(i = [1:1:8]){
  126. translate([0,i*8,0]) hullz(length = i);
  127. }
  128.     }
  129.  
  130.  
  131. module ringz(count, ring_width = 10, height = 10, margin = 1) {
  132.     for (i = [2 : count]) {
  133.         outer_radius = i * (ring_width + margin);
  134.         inner_radius = outer_radius - ring_width;
  135.  
  136.         difference() {
  137.             cylinder(h = height, r = outer_radius, $fn = 100);
  138.             cylinder(h = height + 0.1, r = inner_radius, $fn = 100);
  139.         }
  140.     }
  141. }
  142.  
  143. module arcz(radius = 10, angle = 90, thickness = 2, steps = 100, center = [0, 0]) {
  144.     r1 = radius;                // outer radius
  145.     r2 = radius - thickness;   // inner radius
  146.  
  147.     outer_points = [
  148.         for (i = [0 : steps])
  149.             let(a = -angle / 2 + i * angle / steps)
  150.             [r1 * cos(a), r1 * sin(a)]
  151.     ];
  152.  
  153.     inner_points = [
  154.         for (i = [steps : 0 : -1])
  155.             let(a = -angle / 2 + i * angle / steps)
  156.             [r2 * cos(a), r2 * sin(a)]
  157.     ];
  158.  
  159.     polygon_points = concat(outer_points, inner_points);
  160.  
  161.     translate(center)
  162.         polygon(points = polygon_points);
  163. }
  164. //arcz();
  165. difference(){  
  166.  
  167. cylinder(10,22,22)
  168.  linear_extrude(10){
  169.     translate([-2,0,0]){
  170. difference(){
  171. arcz(radius = 6, angle = 120, thickness = 2, center = [0, 0]);
  172. translate([-1,0,0])
  173.     arcz(radius = 6, angle = 120, thickness = 2, center = [0, 0]);
  174. }}}
  175.  
  176. linear_extrude(10){
  177. translate([-1,0,0]){
  178. difference(){
  179. arcz(radius = 8, angle = 120, thickness = 2, center = [0, 0]);
  180. translate([-1,0,0])
  181.     arcz(radius = 8, angle = 120, thickness = 2, center = [0, 0]);
  182. }}}
  183.  
  184.  
  185. linear_extrude(10){
  186.     translate([0,0,0]){
  187. difference(){
  188. arcz(radius = 10, angle = 120, thickness = 2, center = [0, 0]);
  189. translate([-1,0,0])
  190.     arcz(radius = 10, angle = 120, thickness = 2, center = [0, 0]);
  191. }}}
  192. }
  193.  
  194.  
  195. */
Tags: 3D
Add Comment
Please, Sign In to add comment