Created
May 29, 2012 23:31
-
-
Save lachie/2831460 to your computer and use it in GitHub Desktop.
This file contains 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
define [ | |
"easel" | |
"easel_filters" | |
], ({}, {ColourFilter}) -> | |
# tint helper | |
# pass in r,g,b or a HEX value | |
# HEX value in this form: 0xFFFFFF | |
# red : 0 - 255 | |
# green : 0 - 255 | |
# blue : 0 - 255 | |
# strength : 0 - 1 | |
tint = (red, green = 1, blue = null, strength = null) -> | |
if (red != null && blue == null) | |
if green == null then green = 1 | |
strength = green | |
console.log strength | |
b = (red&0xFF) * strength | |
g = (red>>8&0xFF) * strength | |
r = (red>>16&0xFF) * strength | |
else | |
r = red*strength | |
g = green*strength | |
b = blue*strength | |
t = 1 - strength | |
console.log r, g, b, strength | |
cf = new ColourFilter(t, t, t, 1, r, g, b, 0) | |
return cf | |
# This fills the entire object with a solid colour, as opposed to simply tinting it. | |
# Usage: object = FillColour(object, "0xFF0000") | |
# Best done before the addChild call. | |
fillColour = (object, red, green, blue, strength) -> | |
console.log "FillColour(#{object}) called" | |
colourFilter = tint(red, green, blue, strength) | |
object2 = object.clone() | |
object2.filters = [colourFilter] | |
img = object2.image | |
object2.cache(0, 0, img.width, img.height) | |
return object2 | |
# API | |
tint: tint | |
fillColour: fillColour |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment