Created
May 16, 2011 11:20
-
-
Save cwaring/974262 to your computer and use it in GitHub Desktop.
Stylus color mixing mixin
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
/** | |
* Colour mixer: mix source with a target colour by a % value | |
*/ | |
mix(source, target, ammount) | |
ammount = unit(ammount, '%') | |
unless source is a 'rgba' and target is a 'rgba' | |
error('mix() expects rgb colour values') | |
rs = red(source) | |
gs = green(source) | |
bs = blue(source) | |
rt = red(target) | |
gt = green(target) | |
bt = blue(target) | |
ammount-s = (100 - ammount) / 100 | |
ammount-t = ammount / 100 | |
r = round((rs * ammount-s) + (rt * ammount-t)) | |
g = round((gs * ammount-s) + (gt * ammount-t)) | |
b = round((bs * ammount-s) + (bt * ammount-t)) | |
rgb(r,g,b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment