dreidel.frink

Download or view dreidel.frink in plain text format


/** This constructs a dreidel for 3-D printing.  It tests extrusion of text,
    rotation of VoxelArrays, tapered cylinders, rounded cubes,
    and constructive solid geometry.

    The shaft of the dreidel is not generated in this file; it would be
    hard to print in one piece.  The shaft program is located in the file
    dreidelShaft.frink

    You may have to adjust the fonts in the text[] function to match the
    fonts available on your operating system.  On Fedora Linux, one of the
    few fonts that has classic Hebrew characters is "Liberation Serif".  You
    may have to find a font on your system that has agreeable Hebrew characters.
*/


r = 254*2 / in

sideHeight = 1 in
sideWidth = 1 in
textDepth = 2 mm

pointLength = 6 mm

shaftHoleDepth = 3 mm
shaftHoleDiam = 1.2 cm

// Rounded cube body centered at [0,0,0]
v = roundedCube[-sideWidth/2 r, sideWidth/2 r, -sideHeight/2 r, sideHeight/2 r, -sideWidth/2 r, sideWidth/2 r, sideWidth/10 r]

// Top side, gimel
t1 = text["\u05d2", sideHeight r, textDepth r]  // HEBREW LETTER GIMEL
t1.translate[0, 0, sideHeight/2 r]
v.remove[t1]

// Right side, nun
t2 = text["\u05e0", sideHeight r, textDepth r]  // HEBREW LETTER NUN
t2.translate[0, 0, sideHeight/2 r]
t2 = t2.rotateXYZ[0,0,0, 0 deg, 90 deg, 0 deg]
v.remove[t2]

// Left side, hey
t3 = text["\u05d4", sideHeight r, textDepth r]  // HEBREW LETTER HE/HEY/HEI
t3.translate[0, 0, sideHeight/2 r]
t3 = t3.rotateXYZ[0,0,0, 0 deg, -90 deg, 0 deg]
v.remove[t3]

// Bottom side, shin
t4 = text["\u05e9", sideHeight r, textDepth r]  // HEBREW LETTER SHIN
t4.translate[0, 0, sideHeight/2 r]
t4 = t4.rotateXYZ[0,0,0, 0 deg, 180 deg, 0 deg]
v.remove[t4]

// Point
point = taperedCylinder[0, -(sideWidth/2 + pointLength) r, 0,
                        0, -(sideWidth/2) r, 0,
                        0, pointLength r]

v = v.union[point]

// Shaft
/*
shaft = taperedCylinder[0, (sideWidth/2) r, 0,
                        0, (sideWidth/2 + 1.5 cm)  r, 0,
                        3/2 mm r, 2/2 mm r]
v = v.union[shaft]
*/


// Shaft hole (so different shafts can be tried independently)
shaftHole = cylinder[0, (sideWidth/2 - shaftHoleDepth) r, 0,
                     0, (sideWidth/2) r, 0,
                     shaftHoleDiam/2 r]
v.remove[shaftHole]

v.projectX[undef].show["X"]
v.projectY[undef].show["Y"]
v.projectZ[undef].show["Z"]

filename = "dreidel.obj"
print["Writing $filename..."]
w = new Writer[filename]
w.println[v.toObjFormat["dreidel", 1/(r mm)]]
w.close[]
println["done."]

/** Extrude text and create a VoxelArray of it. */
text[str, textHeight, depth] :=
{
   g = new graphics
   g.font["Liberation Serif", 10]  // This has serif characters
   //g.font["Serif", 10]
   g.text[str, 0, 0]
   img = g.toImage[undef, round[textHeight]].autocrop[]
   //img.show[]
   
   return callJava["frink.graphics.VoxelArray", "extrudeZ", [img, depth]]
}

/** Create a rounded cube. */
roundedCube[xmin, xmax, ymin, ymax, zmin, zmax, radius] :=
{
   return callJava["frink.graphics.VoxelArray", "makeRoundedCube", [xmin, xmax, ymin, ymax, zmin, zmax, radius]]
}

/** Create a cylinder */
cylinder[x1, y1, z1, x2, y2, z2, radius] :=
{
   return callJava["frink.graphics.VoxelArray", "makeCylinder", [x1, y1, z1,
                                                                 x2, y2, z2,
                                                                 radius]]
}

/** Create a tapered cylinder */
taperedCylinder[x1, y1, z1, x2, y2, z2, radius1, radius2] :=
{
   return callJava["frink.graphics.VoxelArray", "makeTaperedCylinder",
            [x1, y1, z1,
             x2, y2, z2,
             radius1,
             radius2]]
}


Download or view dreidel.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 19971 days, 21 hours, 30 minutes ago.