Skip to content

Instantly share code, notes, and snippets.

@AndersDeleuran
Last active June 2, 2020 11:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndersDeleuran/82fa2a8a69ec10ac68176e1b848fdeea to your computer and use it in GitHub Desktop.
Save AndersDeleuran/82fa2a8a69ec10ac68176e1b848fdeea to your computer and use it in GitHub Desktop.
import Rhino as rc
def mapValuesAsColors(values,srcMin,srcMax,targetMin,targetMax):
""" Make a list of HSL colors where the values are mapped onto a
targetMin-targetMax hue domain. Meaning that low values will be red, medium
values green and large values blue if targetMin: 0.0 and targetMax: 0.7 """
# Remap numbers into new numeric domain
remappedValues = []
for v in values:
if srcMax-srcMin > 0:
rv = ((v-srcMin)/(srcMax-srcMin))*(targetMax-targetMin)+targetMin
else:
rv = (targetMin+targetMax)/2
remappedValues.append(rv)
# Make colors and return
colors = []
for v in remappedValues:
c = rc.Display.ColorHSL(v,1.0,0.5).ToArgbColor()
colors.append(c)
return colors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment