Skip to content

Instantly share code, notes, and snippets.

@deciob
Created April 3, 2012 08:33
Show Gist options
  • Save deciob/2290459 to your computer and use it in GitHub Desktop.
Save deciob/2290459 to your computer and use it in GitHub Desktop.
Linear scaling script
class Scaler
scale: (range, domain) =>
@rmax = domain[1]
@rmin = domain[0]
return (val) =>
position_in = @getPositionInDomain(val)
position_out = @getPositionInRange(range, position_in)
Math.ceil(position_out)
getPositionInDomain: (val) =>
abs_width = @rmax - @rmin
abs_val = @rmax - val
if abs_width == abs_val
return 100
else
return 100 - (abs_val * 100 / abs_width)
getPositionInRange: (range, pir) =>
abs_width = range[1] - range[0]
return range[0] + (abs_width * pir / 100)
scaler = new Scaler()
radius_range = @scaler.scale(
[6, 16], # range
[12, 456]) # domain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment