Random Background #94
-
Hello 👋 I was wondering if the genColor and drawBackground constructors can be setup to never use the same color code more than once? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
hi, it's possible to do something like this, sure! Although, the difference of even |
Beta Was this translation helpful? Give feedback.
hi, it's possible to do something like this, sure!
A possible approach would be to maintain a
new Set()
of colors, then each time the color is randomly selected, check first that it is not already in the Set [otherwise pick again], then add it to the set after using it.Although, the difference of even
1
for any RGB value would be considered unique, while visually looking identical to another color. More care and finesse would need to be added to crates steps of noticeably different colors