Advertisement
KeithFromCanada

Parametric Die Model

Dec 28th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.02 KB | None | 0 0
  1. //--------------------------------
  2. // Parametric Die Model
  3. // Keith Olson
  4. // OpenSCAD
  5. //--------------------------------
  6.  
  7. // OpenSCAD uses millimeters (mm) for units.
  8. // Distance functions are both for conversion and to state plainly that a number is a
  9. //    measurement, not just a value.
  10. // Fractions are interpreted as formulas: '1 3/4"' = inches(1+3/4) = 1.75
  11. function mm(x = 1) = x;
  12. function cm(x = 1) = x * 10;
  13. function inches(x = 1) = x * 25.40000;  
  14. function feet(x = 1) = x * 25.40000 * 12;  
  15.  
  16. $fn=72; // (Circles are divided in $fn line segments.)
  17.  
  18. dieScale=mm(20);
  19. dieSize=[dieScale,dieScale,dieScale];
  20.  
  21. pipWidth=dieScale/6;
  22. pipHeight=pipWidth/2;
  23. pipSpacing=dieScale/4;
  24.  
  25. pipPatterns=[[0,0,0,
  26.                 1,
  27.               0,0,0], //1
  28.              
  29.              [1,0,0,
  30.                 0,
  31.               0,0,1], //2
  32.              
  33.              [1,0,0,
  34.                 1,
  35.               0,0,1], //3
  36.              
  37.              [1,1,0,
  38.                 0,
  39.               0,1,1], //4
  40.              
  41.              [1,1,0,
  42.                 1,
  43.               0,1,1], //5
  44.              
  45.              [1,1,1,
  46.                 0,
  47.               1,1,1]  //6
  48.             ];
  49.              
  50. pipPlacement=[[0,0,0],          [2,0,0],
  51.               [0,1,0], [1,1,0], [2,1,0],
  52.               [0,2,0],          [2,2,0]
  53.              ];
  54.              
  55. pipRotation=[[+0,+0,+0], //1
  56.              [+0,-1,+0], //2
  57.              [+1,+0,+0], //3
  58.              [-1,+0,+0], //4
  59.              [+0,+1,+0], //5
  60.              [+2,+0,+0]  //6
  61.             ];
  62.            
  63. difference(){
  64.     cube(dieSize,center=true);
  65.  
  66.     for (pip=[1:6]){
  67.             rotate(pipRotation[pip-1]*90)
  68.                 translate([-dieScale/4,-dieScale/4,dieScale/2-pipHeight+0.01])
  69.                     DisplayPips(pip);
  70.     }
  71. }
  72.  
  73. module DisplayPips(pipVal){
  74.    
  75.     for (jj=[0:6]){
  76.         if (pipPatterns[pipVal-1][jj]){
  77.             translate(pipPlacement[jj]*pipSpacing)
  78.                 cylinder(d1=0,d2=pipWidth, h=pipHeight);
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement