GEBCube2.frink

Download or view GEBCube2.frink in plain text format


/** This makes a cube that projects a different silhouette
    along 3 axes, and renders it in Waveform .obj format for 3-D printing.
    This version can take text for each axis. (They can
    be different sizes; this resizes them to 200x200 pixels.) The white
    parts will be "cut out" of the cube.
*/


// Y axis
gr = new graphics
//gr.font["FreeSans Bold", 10]
gr.font["Cantarell Extra Bold", 10]
//gr.rotate[-90 deg]
//gr.scale[-1,1]
gr.text["L",0,0]
i1 = new image[gr, 400, 400].autocrop[]
i1 = i1.resize[200,200]
//i1.show[]   
[w1, h1] = i1.getSize[]

v = newJava["frink.graphics.VoxelArray", [w1,h1,h1,true]]

for x=0 to w1-1
   for y=0 to h1-1
   {
      [r,g,b] = i1.getPixel[x,y]
      if (r+g+b) > 2.9
         v.setRange[x,x,0,h1-1,h1-1-y,h1-1-y,false]
   }

// Z axis   
gr = new graphics
gr.font["FreeSans Bold", 10]
gr.rotate[90 deg]
//gr.scale[-1,1]
gr.text["A",0,0]
i2 = new image[gr, 400, 400].autocrop[]
i2 = i2.resize[200,200]
//i2.show[]   
[w1, h1] = i2.getSize[]

for x=0 to w1-1
   for y=0 to h1-1
   {
      [r,g,b] = i2.getPixel[x,y]
      if (r+g+b) > 2.9
         v.setRange[y,y,x,x,0,h1-1,false]
   }

// X axis   
gr = new graphics
//gr.font["Cantarell Extra Bold", 10]
gr.font["FreeSans Bold", 10]
gr.rotate[0 deg]   
gr.text["K",0,0]
i3 = new image[gr, 400, 400].autocrop[]
i3 = i3.resize[200,200]
//i3.show[]   
[w1, h1] = i3.getSize[]

for x=0 to w1-1
   for y=0 to h1-1
   {
      [r,g,b] = i3.getPixel[x,y]
      if (r+g+b) > 2.9
         v.setRange[0,w1-1,y,y,x,x,false]
   }

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


Download or view GEBCube2.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 19972 days, 14 hours, 14 minutes ago.