bennyguitar / Colours

A beautiful set of predefined colors and a set of color methods to make your iOS/OSX development life easier.
MIT License
3.09k stars 300 forks source link

Odd behavior with darken/lighten #27

Closed jimbojsb closed 9 years ago

jimbojsb commented 9 years ago

Hi,

I think there is either a bug with darken or I'm misunderstanding how to use it. Given an existing UIColor, if I lighten it by 0.15f, it lightens correctly (albeit slightly more than I might expect, but other color libraries, such as the one in less.js, behave identically). However, darkening by any amount results in a color that is not exactly black, but essentially black. What's odd is that lightening by a negative float gives exactly the results I'd expect.

searchInput.backgroundColor = [[Colors teal] lighten:-0.15f]; // perfect
searchInput.backgroundColor = [[Colors teal] darken:0.15f]; // black

screen shot 2015-01-15 at 5 48 07 pm screen shot 2015-01-15 at 5 48 26 pm

bennyguitar commented 9 years ago

The way it works, is it takes the float you pass in and multiplies the brightness of the color (from the Hue, Saturation, Brightness color formulation) by that value. So a .15 will result in a color that is 15% as bright as it used to be.

This might be confusing, and I'll look at making it what seems the most common-sense way of doing it.

jimbojsb commented 9 years ago

Ah, I see. Darken by .85f gives me the result I was looking for. I think maybe just the method names are slightly confusing or even just updating the readme with with what you noted above is sufficient.

allaire commented 9 years ago

This is really confusing. I suggest we take inspiration from sass (http://sass-lang.com/documentation/Sass/Script/Functions.html#darken-instance_method)

darken(#ccc, 5%) makes #ccc 5% darker

bennyguitar commented 9 years ago

Ok, it makes sense now. If you do [[UIColor plumColor] darken:0.05] it makes a 5% darker color.

allaire commented 9 years ago

Works flawlessly @bennyguitar (currently using :head)