cwisbg

colorRandomizer v_0.2

Jan 24th, 2012
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.69 KB | None | 0 0
  1.  
  2. """___________________
  3.    colorRandomizer
  4.    version_0.2
  5.    
  6.    cwisbg
  7.    Brandon Gillespie
  8.    1/25/2012
  9. ______________________      
  10. """
  11. from pymel.core import*
  12. import maya.cmds as mc
  13. import random as r
  14.  
  15.  
  16.  
  17. def shading(a): # a = selection
  18.     shadingNode('lambert',asShader=1, n = 'colorShift_{0}'.format(a))
  19.     shadingNode('singleShadingSwitch', au=1, n = 'colorSwitch_{0}'.format(a))
  20.     shadingNode('ramp', at=1, n = 'ramp_{0}'.format(a))
  21.     connectAttr('colorSwitch_{0}.output'.format(a), 'ramp_{0}.vCoord'.format(a), f=1)
  22.     connectAttr('ramp_{0}.outColor'.format(a), 'colorShift_{0}.color'.format(a))
  23.     connectAttr('colorSwitch_{0}.output'.format(a), 'ramp_{0}.vCoord'.format(a))
  24.  
  25.    
  26. def cuber(a): # a = range/ how manny cubes
  27.     shadingNode('singleShadingSwitch', au=1, n = 'colorSwitch_TEST')
  28.     connectAttr('colorSwitch_TEST.output', 'ramp2.vCoord', f=1)  
  29.     z = 0
  30.     moveX = 0
  31.     cubeRange = int(a)
  32.     normlizedList = []
  33.     dummy = [polyCube(n = 'Im_a_dummy', h=.5, w=.5, d=.5)[0]]
  34.     for i in range(1,cubeRange):
  35.         normlizedList.append(i)
  36.         refresh(cw=1)
  37.         randoC = r.random()
  38.         cuby = [polyCube(n = 'cube_{0}'.format(i), ch=0)][0]
  39.         addAttr('cube_{0}'.format(i), ln = 'color', at='double', min=0, max=1)
  40.         setAttr('cube_{0}.color'.format(i), randoC)
  41.         setAttr('cube_{0}.color'.format(i),e=1, keyable=1)
  42.         move(cuby[0], 0,0,moveX, ws=1)
  43.         parent(cuby[0], dummy[z])
  44.         dummy.append(cuby[0])
  45.         hyperShade('cube_{0}'.format(i), a='color')
  46.         moveX += 2
  47.         z += 1
  48.     return dummy, normlizedList
  49. def connecter(a):    
  50.     z = 1
  51.     connectFlip = a
  52.     zz = connectFlip
  53.     #while connectFlip > 0:
  54.     for i in range(1,a):
  55.         #print connectFlip, connectFlip,z
  56.         connectAttr(dummy[z]+".color","colorSwitch_TEST.input[{0}].inSingle".format(connectFlip-2),f=1)
  57.         connectFlip -= 1  
  58.         z +=1
  59.    
  60. def normList(L, normalizeTo=1):
  61.     '''normalize values of a list to make its max = normalizeTo'''
  62.  
  63.     vMax = max(L)
  64.     return [ x/(vMax*1.0)*normalizeTo for x in L]
  65.  
  66. def selector(a):
  67.     x = 0
  68.     slRange = int(a)
  69.     for i in range (1,slRange):
  70.         sl = select(dummy[x],add=1)
  71.         print x  
  72.         x -= 1
  73. def norSl(a,b):# a = dummy list, b = nor numbers
  74.     x = 0
  75.     z = 0
  76.     for cube in a:
  77.         if x == 0:
  78.             x += 1
  79.             pass
  80.         else:
  81.             setAttr(cube+'.color', b[z])
  82.             z += 1
  83.      
  84. sl = selected()  
  85.  
  86. #range = int(11)  
  87. #shading(sl[0])
  88. #dummy,normlizedList = cuber(100)
  89. #selector(100)
  90. connecter(100)
  91. #xx= normList(normlizedList, normalizeTo=1)
  92. #norSl(dummy, xx)
Advertisement
Add Comment
Please, Sign In to add comment