Download or view GEBCube.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.
It takes 3 square black-and-white images, one for each axis. (They can
be different sizes; this resizes them to 200x200 pixels.) The white
parts will be "cut out" of the cube.
You will probably want to provide your own images, but here are the ones
I used for the letters A, B, E:
https://frinklang.org/frinksamp/A400x400.png
https://frinklang.org/frinksamp/B400x400.png
https://frinklang.org/frinksamp/E400x400.png
*/
// This sets the resolution of the final object in voxels.
w = h = 400
i1 = new image["file:E400x400.png"]
i1 = i1.resize[w,h]
[w1, h1] = i1.getSize[]
v = newJava["frink.graphics.VoxelArray", [w1,h1,h1,true]]
// Carve along Y axis
for x=0 to w1-1
for y=0 to h1-1
{
[r,g,b] = i1.getPixel[x,y]
if (r+g+b) > 1.5
v.setRange[x,x,0,h1-1,h1-1-y,h1-1-y,false]
}
i2 = new image["file:A400x400.png"]
i2 = i2.resize[w,h]
[w1, h1] = i2.getSize[]
// Carve along Z axis
for x=0 to w1-1
for y=0 to h1-1
{
[r,g,b] = i2.getPixel[x,y]
if (r+g+b) > 1.5
v.setRange[y,y,x,x,0,h1-1,false]
}
i3 = new image["file:B400x400.png"]
i3 = i3.resize[w,h]
[w1, h1] = i3.getSize[]
// Carve along X axis
for x=0 to w1-1
for y=0 to h1-1
{
[r,g,b] = i3.getPixel[x,y]
if (r+g+b) > 1.5
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"]
filename = "ABEcube.obj"
print["Writing $filename..."]
w = new Writer[filename]
w.println[v.toObjFormat["test", 1/10]]
w.close[]
println["done."]
Download or view GEBCube.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 20145 days, 11 hours, 55 minutes ago.