Last active
July 29, 2025 03:56
-
-
Save juanbrujo/972ed5d1dd488605fe90 to your computer and use it in GitHub Desktop.
LESS mixin to get random from array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @blue: #009be1; | |
| @green: #64c200; | |
| @red: #ff1842; | |
| @orange: #ffbf00; | |
| @yellow: #ffd400; | |
| @colors: '@{green}','@{blue}','@{red}','@{orange}','@{yellow}'; | |
| .randomFromArray(@min: 1, @max: length(@colors), @int: 0) { | |
| @getNum: `Math.random() * (@{max} - @{min} + @{int})`; | |
| @base: unit(`@{int} == 1 ? Math.floor(@{getNum}) : @{getNum}`); | |
| @randNum: floor( @base + @min ); | |
| @color: e( extract(@colors, @randNum) ); | |
| } | |
| // USE | |
| body { | |
| .randomFromArray(); | |
| background-color: @color; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@geometry dash meltdown I can't find any errors.