Hey all,
Not sure if CleverCSS is still active or not, but I forked it in my
local repo to add the following bit of functionality.
This is a patch against clevercss/clevercss...@b2aea937f5bb.
It adds the ability to do the following:
Color.saturate(10) # Changes the saturation
Color.shift(30) # Changes the hue of a color
You can also do negative values:
Color.saturate(-60)
Color.shift(-80)
I think CleverCSS should come out of the pocoo sandbox. I find this
insanely useful.
939,940c939
<
< def brighten_color(color, context, amount=None):
---
> def adjust_color(color, amount=None, attribute=None):
943c942,943
< hue, lightness, saturation = rgb_to_hls(*color.value)
---
> hls = {}
> hls['hue'], hls['lightness'], hls['saturation'] = rgb_to_hls(*color.value)
948c948
< lightness *= 1.0 + amount.value / 100.0
---
> hls[attribute] *= amount.value / 100.0
953,956c953,965
< lightness += (amount.value / 100.0)
< if lightness > 1:
< lightness = 1.0
< return Color(hls_to_rgb(hue, lightness, saturation))
---
> hls[attribute] += (amount.value / 100.0)
>
> if attribute == 'hue':
> while hls[attribute] < 0 or hls[attribute] > 1.0:
> if hls[attribute] < 0:
> hls[attribute] += 1.0
> elif hls[attribute] > 0:
> hls[attribute] -= 1.0
> else:
> if hls[attribute] < 0:
> hls[attribute] = 0.0
> elif hls[attribute] > 1:
> hls[attribute] = 1.0
957a967,970
> return Color(hls_to_rgb(hls['hue'], hls['lightness'], hls['saturation']))
>
> def brighten_color(color, context, amount=None):
> return adjust_color(color, amount, 'lightness')
960,975c973,980
< if amount is None:
< amount = Value(10.0, '%')
< hue, lightness, saturation = rgb_to_hls(*color.value)
< if isinstance(amount, Value):
< if amount.unit == '%':
< if not amount.value:
< return color
< lightness *= amount.value / 100.0
< else:
< raise EvalException(self.lineno, 'invalid unit %s for
color '
< 'calculations.' % amount.unit)
< elif isinstance(amount, Number):
< lightness -= (amount.value / 100.0)
< if lightness < 0:
< lightness = 0.0
< return Color(hls_to_rgb(hue, lightness, saturation))
---
> # Since we are darkening, this is a sign flip on the value
> if isinstance(amount, Number):
> amount.value *= -1
>
> return adjust_color(color, amount, 'lightness')
>
> def saturate_color(color, context, amount=None):
> return adjust_color(color, amount, 'saturation')
976a982,983
> def shift_color(color, context, amount=None):
> return adjust_color(color, amount, 'hue')
983a991,992
> 'shift': shift_color,
> 'saturate': saturate_color,
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pocoo-libs?hl=en
-~----------~----~----~----~------~----~------~--~---