# ShapeOko 2 tutorial – Dominion turntable – part 2

If you missed part 1, please find it here.

OpenSCAD is a software for creating solid 3D CAD objects. It is free software and available for Linux/UNIX, MS Windows and Mac OS X. Take a good look at the homepage where you’ll find tutorials, cheat sheets and other documentation.

When you open OpenSCAD it will already contain an empty drawing. If not, please create a new drawing by pressing <Ctrl>+N or by clicking File -> New in the menus.

First of all the turntable is a very low cylinder with radius 274 mm and height 26 mm: The following code will create just that:

`cylinder(h=26,r=274);`

Press F6 to make OpenSCAD compile and render the drawing. Furthermore, I like to have the upper surface located at (0,0,0), so we will translate the cylinder along the z-axis by -26 mm because the cylinder-command draws the cylinder above z=0 by default. The code will look like this:

```translate(v=[0,0,-26])
{
cylinder(h=26,r=274);
}```

To compile and render your drawing, press F6. Our drawing is just a cylinder at the moment with no space for the cards. We’ll change that by subtracting a set of boxes from our cylinder but first we will make a function (called a module in OpenSCAD) that can draw a box with a given set of dimensions. Our module called box looks like this:

```module box(xdim, ydim, zdim)
{
translate(v=[0,0,-zdim/2])
{
cube([xdim, ydim, zdim], center = true);
}
}```

The built-in function cube draws the box given a vector of x-, y- and z-dimensions. The parameter center=true will make OpenSCAD draw our box centered around (0,0,0), so we translate the box along the z-axis by half the given height (the parameter zdim).

Our box (or actually holes for the cards) will have the dimensions 94x62x15 mm, so we need to draw the cylinder, draw the box and make OpenSCAD subtract the box from the cylinder to create the effect that we want. The keyword for subtracting one solid from another is difference so our code put together looks like this:

```difference()
{
translate(v=[0,0,-26])
{
cylinder(h=26,r=274);
}
box(94,62,15);
}

module box(xdim, ydim, zdim)
{
translate(v=[0,0,-zdim/2])
{
cube([xdim, ydim, zdim], center = true);
}
}```

After compiling and rendering the drawing looks like this:

We want 8 holes for the stacks of cards in the center: 5 holes 15 mm deep and 3 holes 5 mm deep. Furthermore, we want the walls between the holes to be 12 mm so we’ll translate them (94 + 12)/2 = 53 mm (and – 53 mm) along the x-axis and (62 + 12)/2 = 37 mm (or i*74 + 37 mm for some value i ) along the y-axis. Thus we add another module (called boxes) to draw the holes and to translate them to the right positions. It looks like this:

```module boxes()
{
for (i=[-2,1])
{
translate(v=[53, i*74 + 37, 0])
{
box(94,62,15);
}
}
for (i=[-1,1])
{
translate(v=[53, i*37, 0])
{
box(94,62,5);
}
}
for (i=[-1:1])
{
translate(v=[-53, i*74 + 37, 0])
{
box(94,62,15);
}
}
for (i=[-2])
{
translate(v=[-53, i*74 + 37, 0])
{
box(94,62,5);
}
}
}```

The construction for (i=[-2,1]) makes i take the values -2 and 1 during the two loops, while the construction for (i=[-1:1]) makes i take the values -1, 0 and 1 during the three loops. Thus the four loops will draw 8 boxes all together. We then change the first code to:

```difference()
{
translate(v=[0,0,-26])
{
cylinder(h=26,r=274);
}
boxes();
}```

and press F6 to compile and render the drawing again. We now have:

Much better! But there is a problem: It’s almost impossible to get a card from the stack in the holes, so we’ll have to add some space for the players fingers in the walls between the holes. We’ll makes this space by subtracting boxes with dimensions 40x24x18 mm and translate them into their right positions in a new module named fingerholes.

```module fingerholes()
{
for (i=[-2:2])
{
translate(v=[53, i*74, 0])
{
box(40,24,18);
}
translate(v=[-53, i*74, 0])
{
box(40,24,18);
}
}
}```

Again we’ll add a call to our new module in the code making the subtraction:

```difference()
{
translate(v=[0,0,-26])
{
cylinder(h=26,r=274);
}
boxes();
fingerholes();
}```

Press F6 to compile and render:

To finish the center of the turntable we’ll add four holes for coins and tokens. These holes will be the shape of a drop (sort of) and be created by subtracting a convex hull constructed over two spheres with radius 16 and 32 mm translated to the places outside the 8 holes already created. Thus we add a new module called holes:

```module holes()
{
hull()
{
translate(v=[138, -32, 20])
{
sphere(r=32, center=true);
}
translate(v=[127, -87, 4])
{
sphere(r=16, center=true);
}
}
hull()
{
translate(v=[-138, -32, 20])
{
sphere(r=32, center=true);
}
translate(v=[-127, -87, 4])
{
sphere(r=16, center=true);
}
}
hull()
{
translate(v=[138, 32, 20])
{
sphere(r=32, center=true);
}
translate(v=[127, 87, 4])
{
sphere(r=16, center=true);
}
}
hull()
{
translate(v=[138, -32, 20])
{
sphere(r=32, center=true);
}
translate(v=[127, -87, 4])
{
sphere(r=16, center=true);
}
}
}```

We’ll add a call to our newly created module to the code at the beginning of our file:

```difference()
{
translate(v=[0,0,-26])
{
cylinder(h=26,r=274);
}
boxes();
fingerholes();
holes();
}```

After compile and render our drawing looks like this:

Now we’re almost done. All we need is to create a ring of 16 holes at the perimeter of our turntable but these holes will not be regular boxes: we want the holes to have a slope towards the center of the turntable by making them have a depth of 5 mm farthest away from the center and a depth of 8 mm closest to the center. In other words we’ll subtract a ring of wedges from our cylinder.

Furthermore, we would like to make a notch (in the shape of a quarter sphere) at the edge of the cylinder in each hole so the stack of cards can easily be removed all at once. The wedge and the corresponding sphere are created by the following module:

```module wedge()
{
translate(v=[0,-94,0])
{
polyhedron(points = [
[-31,0,-5],
[31,0,-5],
[31,94,-8],
[-31,94,-8],
[-31,0,0],
[31,0,0],
[31,94,0],
[-31,94,0]
],
faces = [
[0,1,2,3],
[1,5,6,2],
[0,4,5,1],
[0,3,7,4],
[2,6,7,3],
[4,7,6,5]
]
);
translate(v=[0,0,-5])
{
sphere(r=10);
}
}
}```

A wedge is drawn using the command polyhedron that takes a list of points and a list of faces. The wedge is constructed from 8 points and 6 faces, where each face is defined as a list of points listed clockwise seen from the outside of the wedge (take a look at the documentation: they explain it much better than I can). At the end we add a sphere with radius 10 mm.

The code above defines a wedge with 5 mm depth in one end and 8 mm depth in the opposite end. The deep end is located at (0,0,0). To make it a ring of 16 wedges we then create the following module that creates the wedges, translates them -180 mm along the y-axis and finally rotate them i*1/16 + 1/32 of a full circle, for i = 1, 2, … , 16:

```module wedgering()
{
for (i=[1:16])
{
rotate(i*360/16 + 360/32,[0,0,1])
{
translate(v=[0,-180,0])
{
vedge();
}
}
}
}```

Finally, we create the entire drawing as a module and replace the code in the start with a call to that module:

```drawing();

module drawing()
{
difference()
{
translate(v=[0,0,-26])
{
cylinder(h=26,r=274);
}
boxes();
fingerholes();
holes();
wedgering();
}
}```

We then add the value 1 to an internal variable \$fa at the very top of the file. This value will cause OpenSCAD to make a smoother drawing:

```\$fa=1;

drawing();```

After compile and rendering (which takes quite some time) we have the final drawing:

To export the drawing as an STL-file (which we will need in the next step), select File -> Export -> Export as STL. This will give us a STL-file of the entire turntable but since the ShapeOko 2 has a work area of 300×300 mm we need to break it down into smaller pieces. We do this by adding a little more code to the OpenSCAD file:

```intersection()
{
rotate(0,[0,0,1])
{
translate(v=[0,0,-20])
{
cube([300,300,40]);
}
}
drawing();
}```

By using rotate(0,[0,0,1]), rotate(90,[0,0,1]), rotate(180,[0,0,1]) and rotate(270,[0,0,1]) we get the following four quarter circles: