Closed saivan closed 5 years ago
I think we dnt need a random
option. Just calling the constructor without any parameters could result in a random color instead. Or do you think it should default to black?
var random = new SVG.Color() // done
Not a bad plan! I like that idea. But is there never a case where you would change an existing SVG.Color(), or do we treat them as though they were immutable?
Immutability is a thing which is on the list to discuss ("stuff to think about") :D. I am a fan of immutable data structures. However - it is almost always slower. But I think it might pay off.
Anyway: why would it not be possible to change a color? That change only affects the construction of the color object and nothing else. You still just can change the properties if the object, can't you?
You can change the properties, but how do you make those properties propagate? Eg: If I change the color property in a color object, does a fill that uses this color automatically update?
No - Ofc not. I would also not expect this to happen. You paassed a color to fill()
- what you do after this should habe no effect at all.
At least that's my strong opinion
I worked on a random color generator on chance js which allows you to do ranges of random colors, such as if you want only light colors or dark colors. Essentially it lets you send min and max values for RGBA. This allows you some flexibility in getting the kind of random colors you want. I really had needed this at the time to generate dark colors for light text or light text for dark backgrounds. I would say feel free to grab bits and pieces if you need. https://github.com/chancejs/chancejs/blob/master/chance.js Line 1204
Thanks! We will take a look :)
My two cents: please don't generate a random color when the constructor receives no arguments. I do not expect this behavior and never encountered it in other libs. IMHO people will pull their hair not understanding why their "simple" code has a non-reproducible behavior...
I for one am all for explicit, fluent API such as a "random" method.
@oparisy you have a very good point! I think thats a good plan!
@saivan Great! Re-reading your initial proposal, and having a look at your fluent API style, I guess a randomize()
method would indeed be a better fit since it is a verb.
Is anyone working on this? Otherwise I'd like to contribute.
You're welcome to have a crack :) of course! We always welcome prs
So I did this in #923
Add
random
option andrandomize()
method toSVG.Color
. Should use lab space by default so wait for #790 first.