-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Random colour generator / random item selector #732
Conversation
I just realised that the 'pick from params' version of this function is completely general - since it just returns one of whatever you passed in, it doesn't care what they are, so you could use it for all sorts of things, not just colours. Polymorphism FTW! Because of that I've amended my code to split it out as a separate function and amended the description above. |
It's a fun feature but unless I'm missing something it would rely on using less.js client-side. |
Not necessarily; I'm intending to use it for generating per-user styles server-side (every user gets their own LESS stylesheet). |
Gotcha! Like I said I think it's a fun feature but I don't believe it belongs in LESS proper. LESS should work the same whether it's parsed on the client, dynamically on the server or compiled as part of a build process. A given LESS stylesheet as an input should have one CSS output. |
It does work identically in all environments; the only thing that's different is what you do with the resulting CSS - on the server-side you usually keep it for a while; client side you tend to throw it away. In my case I'm not that interested in client-side, but I'm planning on regular server-side recompilation. |
I'm pro this one as well - but have no strong opinions at-all. alternatively close and continue working towards being able to inject/plugin functions easily. what do you think? |
I'd forgotten about this one; It is kind of harmless 😄 |
It feels kinda ugly, especially a magic |
Let's close it then and leave for future work with plugins |
Since we closed this I have seen bugs from 2 different people using javascript just to generate random numbers. |
How's the plugin work going? |
Adds two very simple functions,
randomcolor
andpickrandom
.randomcolor
generates a completely random opaque colour.pickrandom
selects a random item (of any kind) from a list.Usage is like this:
output from this might be:
There are no test cases for these functions because, by definition, the output is not predictable! I foresee
randomcolor
function being useful in generating random colour palettes, where an initial random colour can be used to derive others via LESS's existing colour manipulation functions and my contrast function in #730.pickrandom
has all kinds of uses since it can randomise anything you put into it.