Render.ru

Куб(кирпич) Гильберта

igorznag

Мастер
Рейтинг
103
#2
В книге The Algorithmic Beauty of Plants на странице 20 есть алгоритм. Пример скрипта:
Код:
it=3; dist=200
ar=#("A")
sa="B-F+CFC+F-D&F^D-F+&&CFC+F+B//"
sb="A&F^CFB^F^D^^-F-D^|F^B|FC^F^A//"
sc="|D^|F^B-F+C^F^A&&FA&F^C+F+B^F^D//"
sd="|CFB-F+B|FA&F^A&&FB-F+B|FC//"
a=#();b=#();c=#();d=#();
for i=1 to sa.count do append a sa[i]
for i=1 to sb.count do append b sb[i]
for i=1 to sc.count do append c sc[i]
for i=1 to sd.count do append d sd[i]
for i=1 to it do
(
art=#()
for r in ar do
(
if r=="A" or r=="B" or r=="C" or r=="D" then
(
if r=="A" then join art a 
if r=="B" then join art b 
if r=="C" then join art c 
if r=="D" then join art d
)
else append art r
)--for r in ar do
ar=art
)--for i=1 to it do

with redraw off 
(
t=dummy();new_spline=splineShape();addNewSpline new_spline
addKnot new_spline 1 #corner  #line t.pos
for i=1 to ar.count do
(
if ar[i]=="+" do in coordsys local rotate t (eulerangles 0 0 90)
if ar[i]=="-" do in coordsys local rotate t (eulerangles 0 0 -90)
if ar[i]=="&" do in coordsys local rotate t (eulerangles 0 90 0)
if ar[i]=="^" do in coordsys local rotate t (eulerangles 0 -90 0)
if ar[i]=="/" do in coordsys local rotate t (eulerangles -90 0 0)
if ar[i]=="|" do in coordsys local rotate t (eulerangles 0 0 180)
if ar[i]=="F" do 
(
in coordsys local move t [dist/(pow it 2),0,0]
addKnot new_spline 1 #corner  #line t.pos
)
)--for i=1 to ar.count do
updateShape new_spline; delete t;
new_spline.render_displayRenderMesh=true
new_spline.render_renderable=true
new_spline.render_rectangular=false
new_spline.render_useViewportSettings=false
new_spline.render_thickness=dist/(pow it 2)*0.2
new_spline.render_sides=3
select new_spline;max zoomext sel;
)--with redraw off
redrawviews()
 
Сверху