fponticelli / thx.color

General purpose color library for Haxe
http://thx-lib.org
MIT License
38 stars 4 forks source link

Use base color class ( a concrete class) rather than an interface #1

Closed jdonaldson closed 11 years ago

jdonaldson commented 11 years ago

Hi Franco,

Here's an update that implements a base "Color" class. The Color class can actually provide the functionality for toString and toHex by itself, so classes only need to override it if they do something different, or have some sort of optimization for it.

I've added in a mostly untested HSV class as well. This brings up a small problem. Hsv doesn't have a css syntax for it yet. So, toString() will use the rgb method. This works properly in css, etc. but it hides the fact that it is referring to an hsv object.

This may not be a big deal, but it might be an argument for the toString() object to simply dump the values of any internal variables (e.g. a simple object dump). This should be sufficient to distinguish the colors from each other. We could provide the current toString method as a toCss method.

Let me know if this makes sense!

Edit: toRgb64() is a clone() in the Rgb64 class. Can it just return "this" instead?

-Justin

fponticelli commented 11 years ago

I like it. About The toString(), I would keep something that is always symmetrical and that we can reverse from a parse function (to do). Cmyk suffers from the same issue. Maybe adding toCss to Color makes sense after all ... Maybe it could be toCss3 to be even more specific in the intent ... The alternative would be to have some helper class for that.

jdonaldson commented 11 years ago

the json stringify method should work for toString, if you wanted something readable that could be parsed back to raw data.

I don't think it hurts to add a toCss and toCss3 method... I'll check back in later on after I've poked around some more.

fponticelli commented 11 years ago

At this point I also wonder if Rgb8 should be renamed to Rgb. I still think we need IRgb even if it doesn't excite me.

On Mon, Dec 31, 2012 at 1:06 AM, Justin Donaldson notifications@github.comwrote:

the json stringify method should work for toString, if you wanted something readable that could be parsed back to raw data.

I don't think it hurts to add a toCss and toCss3 method... I'll check back in later on after I've poked around some more.

— Reply to this email directly or view it on GitHubhttps://github.com/fponticelli/thx.color/pull/1#issuecomment-11773813.