>
with(plottools):
with(geom3d):
with(JavaViewLib):
>
# A variation on Sierpinski Gasket
#
# This code will allow the recursive construction of a cube with the
# middle thirds removed. Actual structure of the cube is determined
# by the alteration variable entered to the procedure. Interesting
# variations on this can be created by changing this structure.
#
# Author: K G Hare
# Original Designer: Sierpinski (?)
global_var := 1:
Cubes := proc(x_pos,y_pos,z_pos,radius,level,alterations)
option remember:
local new_radius,new_level,picture,silly,temp,s,Silly:
global global_var:
if level = 0 then
silly := global_var: global_var := global_var + 1:
cube(cat(`t`,silly),point(o,x_pos,y_pos,z_pos),evalf(radius)):
RETURN ({cat(`t`,silly)}):
fi;
new_radius := radius / 3:
new_level := level-1:
temp := map(proc(d,x_pos,y_pos,z_pos,new_radius,new_level)
Cubes(x_pos+new_radius*d[1],
y_pos+new_radius*d[2],
z_pos+new_radius*d[3],
new_radius*d[4],new_level) end,
alteration,
x_pos,y_pos,z_pos,new_radius,new_level):
Silly := {}:
for s in temp do
Silly := s union Silly:
od:
RETURN (Silly):
end:
>
lvl:=2:
alteration := {[1/sqrt(3)*2,1/sqrt(3)*2,-1/sqrt(3)*2,1],
[1/sqrt(3)*2,1/sqrt(3)*2,1/sqrt(3)*2,1],
[1/sqrt(3)*2,-1/sqrt(3)*2,-1/sqrt(3)*2,1],
[1/sqrt(3)*2,-1/sqrt(3)*2,1/sqrt(3)*2,1],
[-1/sqrt(3)*2,1/sqrt(3)*2,-1/sqrt(3)*2,1],
[-1/sqrt(3)*2,1/sqrt(3)*2,1/sqrt(3)*2,1],
[-1/sqrt(3)*2,-1/sqrt(3)*2,-1/sqrt(3)*2,1],
[-1/sqrt(3)*2,-1/sqrt(3)*2,1/sqrt(3)*2,1],
[0,-1/sqrt(3)*2,-1/sqrt(3)*2,1],
[0,-1/sqrt(3)*2,1/sqrt(3)*2,1],
[0,1/sqrt(3)*2,-1/sqrt(3)*2,1],
[0,1/sqrt(3)*2,1/sqrt(3)*2,1],
[-1/sqrt(3)*2,0,-1/sqrt(3)*2,1],
[-1/sqrt(3)*2,0,1/sqrt(3)*2,1],
[1/sqrt(3)*2,0,-1/sqrt(3)*2,1],
[1/sqrt(3)*2,0,1/sqrt(3)*2,1],
[-1/sqrt(3)*2,-1/sqrt(3)*2,0,1],
[-1/sqrt(3)*2,1/sqrt(3)*2,0,1],
[1/sqrt(3)*2,-1/sqrt(3)*2,0,1],
[1/sqrt(3)*2,1/sqrt(3)*2,0,1]}:
> draw(Cubes(0,0,0,4,lvl,alteration),view=[-4..4,-4..4,-4..4],style=patch ,lightmodel=light1);
Use JavaView to group all of the small constituent boxes into one geometry and merge the verticies.
JavaView Control Panel (ctrl+c) :
inspector => display | Merge Visible
method => modelling => Identify Verticites | set tolerance | identify
file => export => mpl | save as "smserp.mpl" (400k b4 compresssion)
> runJavaView(%);
You can now easily display this light, single geometry using the light version of JavaView. For a pedagogical demonstration, you might want to manually construct the next level of the serpinsky fractal. Do this in realtime right off of the web.
> set(w=1000,h=1000,axes=off,dc=off):
> runApplet("c:\\temp\\smserp.mpl");