jfairbank / chroma

Ruby gem for color manipulation and palette generation
ISC License
232 stars 29 forks source link

regenerating a palette #23

Closed seiferteric closed 8 years ago

seiferteric commented 8 years ago

If I generate a custom palette, say "user_palette", then later, I want to regenerate it, I get:

Chroma::Errors::PaletteDefinedError (Palette `user_palette' already exists):

Is there a way to support regenerating an already existing palette?

seiferteric commented 8 years ago

I did try some simple changes and it seems to work. See here: https://github.com/jfairbank/chroma/compare/master...seiferteric:eric-wip?expand=1

Not sure if there is more I need to do though for a pull request, or if there was a reason redefining the palette was disallowed in the first place.

jfairbank commented 8 years ago

Hi, @seiferteric.

Honestly, I can't remember why I decided to prevent redefining palettes besides that use case didn't make sense to me. I'm curious why you want to redefine a palette, but I'm not necessarily opposed to opening it up to redefinition.

seiferteric commented 8 years ago

Not sure if I am just using it incorrectly, but I just wanted to create a palette to get N unique colors (starting from a base color and rotate 360/N for each). N may increase, and I have no need for the old palette, so I just redefine the palette for the new N.

jfairbank commented 8 years ago

Sorry I'm lagging on responses. I've been out for conferences and other things.

I'm not fully opposed to this change, but I do like the "staticness" of setting it once. I'm curious how you're wanting to call it, and if maybe defining palettes and using them at the same time would work better?

Some new feature like:

'red'.paint.custom_palette do
  spin 60
  spin 180
end

However if you need to reuse it in other places, then that may not be as nice. Again, I'm open to removing the error entirely since there isn't a strong reason to really have it there.

seiferteric commented 8 years ago

That could work... Would just be more efficient to avoid redefining the palette each time it is needed. To further clarify what I am doing, I have a web application where each user needs a unique color. The only time the palette will change is when a new user is added, or one removed (fairly rare, since this is for a small business). So I (re)create a user_palette anytime a change in the users count happens. Using your suggested code above though, I could just store the color in the user model and not keep the palette around at all.

jfairbank commented 8 years ago

Cool. I'm on vacation through the rest of the week, but I can dive into adding a new feature like this when I get back home. I'm not ultimately opposed to dropping the error anyway, but this at least avoids bumping the major version.

jfairbank commented 8 years ago

@seiferteric Finally got the custom_palette method implemented in the latest release. Try it out and let me know if you have any issues. Closing this issue. Thanks!