-
-
Save alexh225/02bdcaa3e069972f5d07a0a2c0a22ef7 to your computer and use it in GitHub Desktop.
Quick linear scale inspired by d3.js scales, based on the processing.org map() function.
takes in an object with a domain array and a rage array, gives you back a function that receives a value and returns the scaled value.
This file contains hidden or 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
| // based on http://processing.org/reference/javadoc/core/processing/core/PApplet.html#map(float, float, float, float, float) | |
| var scale = function(opts){ | |
| var istart = opts.domain[0], | |
| istop = opts.domain[1], | |
| ostart = opts.range[0], | |
| ostop = opts.range[1]; | |
| return function scale(value) { | |
| return ostart + (ostop - ostart) * ((value - istart) / (istop - istart)); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment