Created
March 6, 2020 18:10
-
-
Save GordeyChernyy/6a6df8f82459bd4cda3ef34728aaa6e0 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
from random import shuffle | |
from random import randrange | |
import random | |
import math | |
from math import cos | |
from math import sin | |
node = hou.pwd() | |
geo = node.geometry() | |
p=hou.parm('../python1/folder0'); | |
mc = hou.parmTuple('../python1/mainColor').eval() | |
colorSeed = hou.parm('../python1/seed').eval() | |
button = hou.parm('../python1/newparameter').eval() | |
interpolationIndex = hou.parm('../python1/newparameter3').eval() | |
colValSeed = hou.parm('../python1/newparameter8').eval() | |
colValMin = hou.parm('../python1/newparameter4').eval() | |
colValMax = hou.parm('../python1/newparameter5').eval() | |
satValMin = hou.parm('../python1/newparameter6').eval() | |
satValMax = hou.parm('../python1/newparameter7').eval() | |
customAngle = hou.parm('../python1/newparameter10').eval() | |
randAngleOffset = hou.parm('../python1/newparameter11').eval() | |
isRandomHue = hou.parm('../python1/newparameter12').eval() | |
isRandomColorOrder = hou.parm('../python1/newparameter13').eval() | |
interpolations = [hou.rampBasis.Constant, hou.rampBasis.BSpline,hou.rampBasis.CatmullRom ,hou.rampBasis.MonotoneCubic , hou.rampBasis.Bezier , hou.rampBasis.BSpline , hou.rampBasis.Hermite] | |
glob = 1 | |
def appendColor(colorCounter): | |
# set angle | |
angle = 0.0 | |
if button == 0: | |
angle = math.radians(60) | |
if button == 1: | |
angle = math.radians(120) | |
if button == 2: | |
angle = math.radians(customAngle) | |
triad = angle *colorCounter + angleOffset | |
colorSat = random.uniform(colValMin, colValMax) | |
colorVal = random.uniform(satValMin, satValMax) | |
color.setHSV((math.degrees(triad), colorVal, colorSat)) | |
newCol = color.rgb() | |
# Setup Color Point | |
colorPoint = {} | |
colorPoint['hue'] = triad | |
colorPoint['color'] = newCol | |
colorPoints.append(colorPoint) | |
# Set Color Seed | |
random.seed(colorSeed) | |
angleOffset = math.radians(randAngleOffset) | |
if(isRandomHue==1): | |
angleOffset = random.uniform(0.1, math.radians(360)) | |
# Setup Color Points for creating visualization | |
colorPoints = [] | |
colorCounter = 0; | |
# Collect Colors | |
for v in list(p.multiParmInstances()): | |
c = hou.node(v.eval()) | |
if(c == None): | |
continue | |
parmRamp = c.parm("ramp") | |
parmColorType = c.parm("colortype") | |
colorType = parmColorType.eval() | |
ramp = parmRamp.eval(); | |
values = list(ramp.values()) | |
color = hou.Color() | |
# Color Ramp | |
if(colorType == 3): | |
for v in values: | |
appendColor(colorCounter) | |
colorCounter+=1 | |
# Color | |
else: | |
appendColor(colorCounter) | |
colorCounter+=1 | |
# Shuffle color | |
colorPointsTemp = colorPoints[:] | |
randColorPoints = colorPointsTemp[:] # copy array | |
if(isRandomColorOrder): | |
for i in range(0, len(randColorPoints)): | |
index = int(random.random()*(len(colorPointsTemp))) | |
randColorPoints[i] = colorPointsTemp[index] | |
del colorPointsTemp[index] | |
# Set Colors | |
colorCounter = 0 | |
for v in list(p.multiParmInstances()): | |
c = hou.node(v.eval()) | |
if(c == None): | |
continue | |
parmRamp = c.parm("ramp") | |
parmColor = c.parmTuple("color") | |
parmColorType = c.parm("colortype") | |
colorType = parmColorType.eval() | |
ramp = parmRamp.eval(); | |
values = list(ramp.values()) | |
keys = list(ramp.keys()) | |
# Set Color Wheel Values | |
newValues = [] | |
# Color Ramp | |
if(colorType == 3): | |
for v in values: | |
color = randColorPoints[colorCounter]['color'] | |
newValues.append(color) | |
colorCounter+=1 | |
# interpolation in gradient | |
newBasis = [] | |
for i in ramp.basis(): | |
newBasis.append(interpolations[interpolationIndex]) | |
# Set values | |
ramp = hou.Ramp(newBasis, keys, newValues) | |
parmRamp.set(ramp) | |
# Color | |
else: | |
color = randColorPoints[colorCounter]['color'] | |
colorCounter+=1 | |
parmColor.set(color) | |
# Create points | |
poly = geo.createPolygon() | |
j = 0 | |
colorAttrib = geo.addAttrib(hou.attribType.Point, "Cd", [.0, .0, .0]) | |
k = 0 | |
for i in randColorPoints: | |
x = cos(i['hue']) | |
y = sin(i['hue']) | |
p = geo.createPoint() | |
p.setPosition(hou.Vector3(x, j, y)) | |
p.setAttribValue(colorAttrib, i['color']) | |
k+=1 | |
j+=0.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment