Sunday, May 24, 2009

01B - Mircea+Alexandra - Recursion squares-Script


#assignment o1B_A+M

#create an initial square
#get the coordinates of the points on each line, depending on the percentage ( in this case the percenatege is a subdivison)
#create a new square with the center in each point we get in the previous step
#rotate the squares with an angle
#scale the initial square
#recursion (by each iteration a new square is created, and along the lines other squares are created and rotated in the same time)


import maya.cmds as cmds

#create one initial square
x=10
y=10
mySquare = cmds.nurbsSquare(sl1=x, sl2=y)


def recursion( iterations , amt , percentage):
it=iterations
pp=percentage

#select the square
cmds.select( mySquare, r=1 )
isSides = cmds.filterExpand( sm=9 )
print isSides

#go through all the lines of the square
for i in range(0, len(isSides), 1):
print i
line = isSides[i]
#get the coordinates on the lines depending on the percentages
for j in range(1, pp+1, 1):
procent = j/float(pp)
poc = cmds.pointOnCurve(line,pr=procent,top=True,p=True)
#create a new square with the center in each point;
#the side of the squares created either can have decreasing values or the same length
#newSquare = cmds.nurbsSquare(c=poc, sl1=1/float(x/pp), sl2=1/float(y/pp))
newSquare = cmds.nurbsSquare(c=poc, sl1=2, sl2=2)
#rotate squares with an angle
cmds.rotate(0,0,it*amt*2, newSquare, pivot=poc)

if iterations == 0:
return "Done."
else:
iterations -= 1
percentage -= 1
#scale the initial square
cmds.scale( 1/float( x/pp),1/float( x/pp), 1/float( x/pp) , mySquare, pivot=(0, 0, 0), absolute=True )
recursion(iterations, amt, percentage)


recursion(4,10,4)



No comments:

Post a Comment