Wednesday, July 22, 2009

04 - Deborah Kaiser

import maya.cmds as cmds
from math import*
from random import*

#create a locator in random position
x = uniform (10,30)
selLoc = cmds.spaceLocator( p=(x,x,2*x) )
#create a curve
def curves (amplitude):

#def initial variables
numPoints= 35

#create an empty list to store the points
points=[]

#loop and gather information
for i in range (1,numPoints,1):

#function of the spiral curve:
x=cos(i)*i
y=sin(i)*amplitude
z= i
myPoint= (x,y,z)

#store the points in the list
points.append(myPoint)
myCurve=cmds.curve(d=3, p=points)
return myCurve

#create an empty list to store the curves
myCurve=[]

#define number of curves
numCurves=5

#function to call the curves in a loop
for i in range(0,numCurves,1):
crv= curves (i)

#store the curve in the list
myCurve.append (crv)
print crv

#move the curves
cmds.move (10,5,5, crv)

#loft the curves
LoftSrf = cmds.loft(myCurve)

### Move Surface ###

# A) get all the vertices of the Surfaces
allCvs= cmds.ls("loftedSurface1.cv[:][:]", fl=1)
cmds.select (LoftSrf, r = True)

# B) define move cvs in surface randomly
def moveVertiRandomly(allCvs, minimum, maximum):
if minimum>= maximum:
print "hello!"
# B.1) start a loop through all cvs in z axis
else:
for i in allCvs:
x= 0
y= 0
z= uniform (minimum, maximum)
cmds.move (x,y,z,i,r=True)
# C) move cvs randomly
moveVertiRandomly (allCvs, 0, 10)

### Move Cvs of Surface according to Locator direction ###

#define coordinates between locator and CV in order to move CV
def distance1 (posPoint, posLoc, constantMin, constantMax):
#subtract both vectores
x1= posPoint[0]
y1= posPoint[1]
z1= posPoint[2]
x2= posLoc[0]
y2= posLoc[1]
z2= posLoc[2]
constant = uniform (constantMin, constantMax)
x= x1 + ((x2 - x1)/constant)
y= y1 + ((y2 - y1)/constant)
z= z1 + ((z2 - z1)/constant)
m= [x,y,z]
return m

#define moveToLocator function
def moveToLocator(selLoc):
#loop through cvs
for i in allCvs:
# refresh
cmds.refresh ()
posPoint= cmds.pointPosition(i)
posLoc= cmds.pointPosition (selLoc)
# randomly moving CVs towards the locator
d= distance1(posPoint, posLoc, 2,5)
cmds.move (d[0],d[1],d[2],i)

#call the function
moveToLocator(selLoc)


### Move Curves ###

# A) get all the cvsNames of a curve
crvCvs = cmds.ls("curve1.cv[:]", fl=1)

# B) define move cvs randomly
def moveVertRandomly (allCvs, minimum, maximum):
if minimum>= maximum:
print "hello!"
# B.1) start a loop through all cvs
else:
for cv in allCvs:
rx = uniform(minimum, maximum)
ry = uniform(minimum, maximum)
rz = uniform(minimum, maximum)
cmds.move (rx,ry,rz,cv,r=2)
# refresh
cmds.refresh ()
cmds.pause (sec=1)
# C) move cvs randomly
moveVertRandomly (crvCvs, 0, 17)


### Move Curve 5 according to Locator direction ####

def moveCrvFive (selLoc):
fiveCvs = cmds.ls("curve5.cv[:]", fl=1)
for j in fiveCvs:
posPoint= cmds.pointPosition(j)
posLoc= cmds.pointPosition (selLoc)
# randomly moving CVs towards the locator
d= distance1(posPoint, posLoc, 2,2)
cmds.move (d[0],d[1],d[2],j)
# refresh
cmds.refresh ()
cmds.pause (sec=1)

moveCrvFive (selLoc)

No comments:

Post a Comment