Advertisement
yOPERO

Untitled

Jan 3rd, 2014
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. /*******MODULE TO GENERATE A GRID**************
  2.  
  3.  * num = Number of points for the grid, it will generate a
  4.  *      matrix[num][num]
  5.  * space = space between points
  6.  * elem = within showGrid() you can create the shape for the
  7.  *      dots to be shown in the grid.
  8.  * zAxis = grid will move this value along the  z Axis
  9.  *      */
  10. module showGrid(num=10, space=10, elem=0,zAxis=0){
  11.     grid(num, space, elem, zAxis) {
  12.         color("plum")sphere(.4);                    //child(0)
  13.         color("OrangeRed")cube(.1,center=true);     //child(1)
  14.         color("Lime")cylinder(h = .1, r=.1,$fn=28); //child(2)
  15.     }
  16. }
  17. module grid(num, space, elem, zAxis) {
  18.     translate([-space*(num-1)/2,-space*(num-1)/2, zAxis])  
  19.     for (i = [0 : num-1])
  20.         for (j = [0 : num-1])
  21.             translate([ space*i, space*j, zAxis ]) child(elem);
  22.     //origin, comment if not needed
  23.     translate([0,0,0])child(elem);
  24.  }
  25. //dummy value  
  26. gap = 10;
  27.  
  28. /* Example1: GRID WITH DEFAULT SETTINGS*/
  29. *showGrid();
  30.  
  31. /* Example2: GRID WITH A GAP SPACE USING ELEM(1) */
  32. //dummy height
  33. myHeight =5;
  34. *showGrid(space=gap, elem=1,zAxis=-myHeight/2);
  35.  
  36. /* Example3: MOVE GRID ON Z AXIS  USING ELEM(2) */ 
  37.  
  38. *showGrid(elem=2,zAxis=myHeight/2);
  39.    
  40. //dummy shape  
  41. translate([gap*2,0,0])
  42.     cube(10,center= true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement