Skip to content

Instantly share code, notes, and snippets.

@cwaring
Created May 16, 2011 11:20
Show Gist options
  • Save cwaring/974262 to your computer and use it in GitHub Desktop.
Save cwaring/974262 to your computer and use it in GitHub Desktop.
Stylus color mixing mixin
/**
* 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