Random Color
It would be useful to be able to get a random (non-ugly) colour like https://github.com/davidmerfield/randomColor
There is already a random function (which I'm now seeing is undocumented): https://github.com/bgrins/TinyColor/blob/4d2e9f73365eb6a637ee770626c3ac519205a0a3/tinycolor.js#L510. We could probably add parameters into that function to specify different things about it.
What do you think the API should look like? Should this be parameters into the existing random function, a new function, or what?
Before reading your response to this, I actually implemented a different random, instead picking from the list of named colours that tinycolor exposes. That might be another feature that could be added? On 3 Sep 2014 14:26, "Brian Grinstead" [email protected] wrote:
There is already a random function (which I'm now seeing is undocumented): https://github.com/bgrins/TinyColor/blob/4d2e9f73365eb6a637ee770626c3ac519205a0a3/tinycolor.js#L510. We could probably add parameters into that function to specify different things about it.
What do you think the API should look like? Should this be parameters into the existing random function, a new function, or what?
— Reply to this email directly or view it on GitHub https://github.com/bgrins/TinyColor/issues/59#issuecomment-54295799.
I think adding parameters to random would be the right way to go.
I think it might be acceptable to default a new call to random with "pretty" colours as I doubt there's anyone relying on having the full 256^3 colours as potential responses. On 3 Sep 2014 14:44, "Sam Gaus" [email protected] wrote:
Before reading your response to this, I actually implemented a different random, instead picking from the list of named colours that tinycolor exposes. That might be another feature that could be added? On 3 Sep 2014 14:26, "Brian Grinstead" [email protected] wrote:
There is already a random function (which I'm now seeing is undocumented): https://github.com/bgrins/TinyColor/blob/4d2e9f73365eb6a637ee770626c3ac519205a0a3/tinycolor.js#L510. We could probably add parameters into that function to specify different things about it.
What do you think the API should look like? Should this be parameters into the existing random function, a new function, or what?
— Reply to this email directly or view it on GitHub https://github.com/bgrins/TinyColor/issues/59#issuecomment-54295799.
instead picking from the list of named colours that tinycolor exposes. That might be another feature that could be added?
Sure, that could be an optional parameter to the function.
I think adding parameters to random would be the right way to go.
Here's one way it could look: there could be string parameters, I guess. You'd have to consult the documentation to make sure you got the string right, plus we'd have to decide what happens with an invalid parameter (should it throw or just return as if nothing was passed in?).
tinycolor.random(); // "Pretty" color
tinycolor.random("all"); // 256^3
tinycolor.random("named") // List of named colors
...
// Maybe other stuff like:
tinycolor.random("dark");
tinycolor.random("light");
Is there a better API to expose this?
I think that's a great way of doing it. Invalid parameter being equivalent to no parameter would be what I would expect.
Actually, I think calling tinycolor.random() with no parameter (or invalid parameter) should stick with our current - actual random - set just so that it does what it says it is doing. Then we can have things like "pretty", "named", etc.
Are you interested in helping to implement this? We could always start with the "named" set since it would be easier to implement but help us get the API and docs for it sorted out.