A Python script from Kekol:
import Blender
from Blender import NMesh,Draw,BGL
print "----------------------"
print "Iniciando Copos Test"
print "----------------------"
current=2
Nivel=Draw.Create(2)
Radio=Draw.Create(1.0)
Relacion=Draw.Create(0.5)
TRAZO=Draw.Create(current+1)
bts = [[Draw.Create(0.),Draw.Create(0.),Draw.Create(0.)],[Draw.Create(0.),Draw.Create(0.),Draw.Create(0.)],
[Draw.Create(0.),Draw.Create(0.),Draw.Create(0.)],[Draw.Create(0.),Draw.Create(0.),Draw.Create(0.)],
[Draw.Create(0.),Draw.Create(0.),Draw.Create(0.)],[Draw.Create(0.),Draw.Create(0.),Draw.Create(0.)]]
tortuga=[0.,0.,0.]
recorrido1=[[0.,1.,0.]]
recorrido2=[[-1.,0.,0.],[1.,0.,0.]]
recorrido3=[[0.,1.,0.],[1.,0.,0.],[-1.,0.,0.]]
recorrido4=[[0.,1.,0.],[0.,-1.,0.],[1.,0.,0.],[-1.,0.,0.]]
recorrido5=[[0.,1.,0.],[0.,-1.,0.],[1.,0.,0.],[-1.,0.,0.],[0.,0.,1.]]
recorrido6=[[0.,1.,0.],[0.,-1.,0.],[1.,0.,0.],[-1.,0.,0.],[0.,0.,1.],[0.,0.,-1.]]
recorridos=[recorrido1,recorrido2,recorrido3,recorrido4,recorrido5,recorrido6]
obj=Blender.Object.GetSelected()[0]
md=obj.getData()
for i in range(len(recorridos[current])):
bts[i][0].val=recorridos[current][i][0]
bts[i][1].val=recorridos[current][i][1]
bts[i][2].val=recorridos[current][i][2]
def reset():
tortuga=[0.,0.,0.]
def avanzar(desp,rel):
global tortuga
tortuga[0]+=desp[0]*rel
tortuga[1]+=desp[1]*rel
tortuga[2]+=desp[2]*rel
def retroceder(desp,rel):
global tortuga
tortuga[0]-=desp[0]*rel
tortuga[1]-=desp[1]*rel
tortuga[2]-=desp[2]*rel
def generaCopo(nivel,radio,rel):
if (nivel==0):
drawCopo(radio)
else:
generaCopo(nivel-1,radio,rel)
for i in range(len(recorridos[current])):
avanzar(recorridos[current][i],radio*(1+rel))
generaCopo(nivel-1,radio*rel,rel)
retroceder(recorridos[current][i],radio*(1+rel))
def drawCopo(r):
no = Blender.NMesh.PutRaw(md)
no.setLocation(tortuga[0],tortuga[1],tortuga[2])
no.setSize(r,r,r)
def check():
global bts,recorridos,current
for i in range(len(recorridos[current])):
bts[i][0].val=recorridos[current][i][0]
bts[i][1].val=recorridos[current][i][1]
bts[i][2].val=recorridos[current][i][2]
def draw():
global Radio,Nivel,Relacion,TRAZO,bts
BGL.glClearColor(0.5, 0.5, 0.6, 1)
BGL.glColor3f(1.,1.,1.)
BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
Nivel=Draw.Number("Nivel=",2,10,79,100,18,Nivel.val,0,5,"Nivel de recurrencia")
Radio=Draw.Number("Radio=",2,111,79,100,18,Radio.val,0.1,10.0,"Radio del Mesh")
Relacion=Draw.Number("Relacion=",2,212,79,115,18,Relacion.val,0.01,1.0,"Relacion radial respecto del anterior")
copos=["1 Vertice","2 Vertices","3 Vertices","4 Vertices","5 Vertices","6 Vertices"]
menuText=''
for i in range(len(copos)):
menuText+="|"+copos[i]+"%x"+str(i+1)
TRAZO=Draw.Menu("Copos%t"+menuText,3,10\
,50,85,20,TRAZO.val,"Distintos trazos de la tortuga")
posy = 140
for i in range(len(recorridos[current])):
bts[i][0]=Draw.Number("x:",1,10,posy,75,20,bts[i][0].val,-5.,5.,"coordenada x")
bts[i][1]=Draw.Number("y:",1,87,posy,75,20,bts[i][1].val,-5.,5.,"coordenada y")
bts[i][2]=Draw.Number("z:",1,164,posy,75,20,bts[i][2].val,-5.,5.,"coordenada z")
posy+=20
BGL.glRasterPos2i(10,posy+20)
Draw.Text("Las coordenadas indican donde ubicar la siguiente camada",'normal')
Draw.Button("Generar Copo!",10,10,12,160,28)
Draw.Button("Exit",99,180,15,30,22)
def event(evt,val):
if evt==Draw.ESCKEY: Draw.Exit()
def bevent(evt):
global current,bts,recorridos
if evt==3:
current=TRAZO.val-1
if current>=len(recorridos):
current=0
check()
if evt==10:
reset()
for i in range(len(recorridos[current])):
recorridos[current][i][0]=bts[i][0].val
recorridos[current][i][1]=bts[i][1].val
recorridos[current][i][2]=bts[i][2].val
generaCopo(Nivel.val,Radio.val,Relacion.val)
if evt==99:
print "-----------------------"
print "Terminando Copos Test"
print "-----------------------"
Draw.Exit()
Blender.Redraw()
Draw.Register(draw,event,bevent)
Run it from the Text Editor with Alt-P.
%<