Skip to content

Instantly share code, notes, and snippets.

@wheeyls
Created December 12, 2012 14:09
Show Gist options
  • Save wheeyls/4267990 to your computer and use it in GitHub Desktop.
Save wheeyls/4267990 to your computer and use it in GitHub Desktop.
Playing around with scaling a domain against a range. Dropped it into firebug console for a quick and dirty visualization.
var range = [0, 1000],
domain = [0, 25],
power = 2;
function calc(v) {
var normal_domain = domain[1] - domain[0]
, normal_range = range[1] - range[0]
, normal_num = v - domain[0]
, inter = normal_num / normal_domain
;
return range[0] + (normal_range * Math.pow(inter, power));
}
$('body').html('');
var $div;
for (var i = 0, ii = domain[1]; i < ii; i++) {
$div = $('<div>&nbsp;</div>');
$div.css({
background: 'red',
height: '20px',
width: calc(i, power) + 'px',
margin: '1px'
});
$('body').append($div);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment