6/1/2018 - 7:34 AM

Randomise the color of rotosplines

Randomise the color of rotosplines to make them easier to distinguish.


  • extend to run on the knobChanged callback, and maybe pull colors from the active viewer to identify color parameters that would be easy to see on the BG.
  • seed the colors based off of the spline name, so that it stays the same every time
import random
import colorsys

def gaussian_rand(mean, max_deviance):
  Generate a random number that falls in a gaussian 
  distribution around a specific value, with a control 
  for the maximum difference from that value.
  # generate value
  val = random.gauss(mean, max_deviance/3.2)  # 99.9% of all random numbers fall within 3.2 standard deviations
  # clamp value to range
  val = min(val, mean + max_deviance)
  val = max(val, mean - max_deviance)
  return val

rp = nuke.selectedNode()
for element in rp['curves'].rootLayer:
    if isinstance(element, nuke.rotopaint.Shape):
        hue = gaussian_rand(.75, 0.25) % 1
        sat = random.uniform(0.5, 0.85)
        val = random.uniform(0.5, 1)
        color = colorsys.hsv_to_rgb(hue, sat, val)
        attrs = element.getAttributes()
        attrs.set("ro", color[0])
        attrs.set("go", color[1])
        attrs.set("bo", color[2])
        attrs.set("ao", 1)  # values below 0.004 use the default color

rp['curves'].changed()  # kick in pants to update viewer