D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
st44100
Full window
Github gist
// source http://jsbin.com/tusehi
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JS Bin</title> </head> <body> <script id="jsbin-javascript"> var mix, rgb, shade, tint; mix = function(src, target, mix) { return [Math.floor(target[0] + (src - target[0]) * mix), Math.floor(target[1] + (src - target[1]) * mix), Math.floor(target[2] + (src - target[2]) * mix)]; }; shade = function(target, m) { return mix(0, target, m); }; tint = function(target, m) { return mix(255, target, m); }; rgb = [255, 10, 10]; console.log(shade(rgb, 0.1)); console.log(tint(rgb, 0.1)); </script> <script id="jsbin-source-javascript" type="text/javascript"> mix = (src, target, mix) -> [ Math.floor(target[0] + (src - target[0]) * mix) Math.floor(target[1] + (src - target[1]) * mix) Math.floor(target[2] + (src - target[2]) * mix) ] shade = (target, m) -> mix 0, target, m tint = (target, m) -> mix 255, target, m # Test rgb = [ 255 10 10 ] console.log shade(rgb, 0.1) console.log tint(rgb, 0.1) </script></body> </html>