Skip to content

Instantly share code, notes, and snippets.

@bytezen
Created August 28, 2012 00:50
Show Gist options
  • Save bytezen/3493943 to your computer and use it in GitHub Desktop.
Save bytezen/3493943 to your computer and use it in GitHub Desktop.
Maya/Python - Generative Patterns
import maya.cmds as mc
import math
import random
def clr():
"""
helper function that will clear all primitives from the screen
"""
mc.select(all=True)
mc.delete()
def sineScale( n, maxRadius ):
"""
use the sin function to map 'n' spheres scale in size to 'maxRadius'
and then back down to radius=1
"""
pos = 0.
for i in range(n):
x = i / float(n)
r = math.sin( x * math.pi) * maxRadius
s = mc.polySphere(r=r)
pos = pos + r
mc.move( pos, 0. , 0., s[0] )
def powScale( n, maxRadius, power ):
'''
use the power function to change the size of 'n' spheres
'''
pos = 0.
for i in range(n):
x = (i + 1) / float(n)
r = math.pow( x, power) * maxRadius
s = mc.polySphere(r=r)
pos = pos + r
mc.move( pos, 0. , 0., s[0] )
pos = pos + r
def expScale( n, maxRadius, power ):
'''
use the exponent function to change the size of 'n' spheres
'''
pos = 0.
for i in range(n):
x = (i + 1) / float(n)
r = math.exp( -1*x*power) * maxRadius
s = mc.polySphere(r=r)
pos = pos + r
mc.move( pos, 0. , 0., s[0] )
pos = pos + r
def oneMinusExpScale( n, maxRadius, power ):
'''
use 1 - e^(-x*power) to change the size of 'n' spheres
'''
pos = 0.
for i in range(n):
x = (i + 1) / float(n)
r = (1. - math.exp( -1*x*power) ) * maxRadius
s = mc.polySphere(r=r)
pos = pos + r
mc.move( pos, 0. , 0., s[0] )
pos = pos + r
def taper(n):
"""
make 'n' spheres taper in size.
the max sphere radius is 1,
the minimum is 1/n
"""
pos = 0.
for i in range(n):
size = (n-i) / float(n) # taper
s = mc.polySphere(r=size)
name = s[0]
mc.setAttr("%s.tz" % name, pos)
pos = pos + size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment