Created
May 12, 2019 21:59
-
-
Save obriencole11/45b1087e78bac252442dbfa74e0c88c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import time | |
import random | |
from maya import cmds | |
from maya import mel | |
### SETTINGS ### | |
targets = cmds.ls(selection=True) | |
attributes = ['ty'] | |
amplitude = 0.1 | |
frequency = 1.0 | |
looping = True | |
### MAIN ### | |
# Setup | |
cmds.refresh(su=True) | |
startTime = cmds.currentTime(q=True) | |
start = int(cmds.playbackOptions(minTime=True, q=True)) | |
end = int(cmds.playbackOptions(maxTime=True, q=True)) | |
duration = end - start | |
# Create Animation | |
for target in targets: | |
for attr in attributes: | |
seed = random.uniform(0,123456789) | |
for frame in range(start, end): | |
cmds.currentTime(frame) | |
value = float(frame - start) | |
if looping: | |
theta = (value / float(duration + 1)) * 2.0 * math.pi | |
x = math.cos(theta) * frequency | |
y = math.sin(theta) * frequency | |
value = mel.eval("noise <<%s, %s, %s>>" % (x, y, seed)) | |
else: | |
value = mel.eval("noise <<%s, %s, 0.0>>" % (value * frequency, seed)) | |
print value | |
value = (value) * amplitude | |
cmds.setAttr('%s.%s' % (target, attr), value) | |
cmds.setKeyframe(target, at=attr) | |
# Cleanup | |
cmds.currentTime(startTime) | |
cmds.refresh(su=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment