Skip to content

Normalized Sliders in Grasshopper

March 24, 2014

Here is a simple trick I find new Grasshopper programmers often miss out on: Normalized Sliders.  Out of the box, Grasshopper provides a 0-1 slider.  Typically, after placing one in your program, the next step is to right click onto the slider, set its minimum and maximum values, set integer versus real range, etc, etc.  Any subsequent changes require going back in and changing those settings by hand as they cannot be updated automatically.  Furthermore, the settings are not visible to the user without deliberately accessing them again through the right-click menu – an easy to forget update.

At the top level, my normalized slider is converted to a 10-20 value range through the Normalizer component

At the top level, my normalized slider is converted to a 10-20 value range through the Normalizer component

Sliders are a critical feature in Grasshopper and I would love to sit down and develop a set of more sophisticated ones that better reflect my needs, but life is short. In the meantime, here is what I do: simply use the out-of-the box 0-1 slider – without any changes – and normalize the range over which it creates my actual parameter. Its a simple operation: if my range is from 10 to 20, I take the difference (20-10), multiply by the 0-1 slider value (say it’s at 0.47, so we have (20-10)*.47=4.7) and add that to the minimum number again: ((20-10)*0.47)+10=14.7  Wallah!  My normalized slider is now controlling a range between 10 and 20. The min and max values are visible to my program and can be driven by other program inputs.  With some cleverness and a little care at the endpoints, we can round the output to create integer values over the range or even valued numbers in the range, etc. This technique is particularly useful when setting up animations, when there is often a lot of back and forth between tweaking the range of values over which the animation will run and testing the animation results.

The top level screenshot above and the detail below show the calculation boxed into a “Normalizer” component for easy reuse.

Inside the Normalizer component, a simple calculation is used to generate the desired range value from the 0-1 input.

Inside the Normalizer component, a simple calculation is used to generate the desired range value from the 0-1 offset input.

Note that the Min value input to the component is first passed through a “Number” object and then fanned out to the two locations it is used in.  This allows the component to have a single input for “Min” connected internally instead of two which must be connected externally. Remember, the key to successful programming is to eliminate as many mistakes as possible before they happen instead of tracking them down later!

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: