Created
September 17, 2019 09:30
-
-
Save jackersson/92102a6d21913beeac46630485506851 to your computer and use it in GitHub Desktop.
This file contains 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
class ColorPicker: | |
def __init__(self, channels: int = 4): | |
self._color_by_id = {} | |
self._channels = channels | |
def get(self, idx): | |
if idx not in self._color_by_id: | |
self._color_by_id[idx] = self._generate_color(channels=self._channels) | |
return self._color_by_id[idx] | |
@staticmethod | |
def _generate_color(low: int = 0, high: int = 255, channels: int = 4): | |
if channels == 4: | |
return (random.randint(low, high), random.randint(low, high), random.randint(low, high), 255) | |
return (random.randint(low, high), random.randint(low, high), random.randint(low, high)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment