Random walk pyramids in Python
April 2nd, 2009Here’s a Python version of the first random pyramids code, for Maya:
I know I’m converting now-deprecated MEL code here, but I can use the practice.
# start: triangle face growth from pymel import * import random # make a cone cone = polyCone(r = 1, h = 1.414214, sx = 3)[0] for i in range(0,500): # get the number of faces of the cone (always 4) n = len(cone.f) # pick a random face sel = cone.f[random.randint(0,n-1)] # find approximate center of face bb = exactWorldBoundingBox(sel) fc = [(bb[3]+bb[0])/2, (bb[4]+bb[1])/2, (bb[5]+bb[2])/2] # instance cone cone = instance(cone)[0] # move instance to face cone.t = (fc[0]-.125, fc[1]+.175, fc[2]) setKeyframe(cone, attribute = "visibility", v = 0, t = 0) setKeyframe(cone, attribute = "visibility", v = 1, t = i) # end
Hoo boy. A random function in an index! And that instance line? The MEL elves are out cold.
« previously: Random walk keyframed blocks in Python | Home | next: Aligned faces pyramid worm in Python »