|
- from random import random
-
- from colors import Colors
- import colors
-
-
- def clamp8(v):
- return 255 if v >= 255 else 0 if v <= 0 else round(v)
-
- class Gradient:
- def __init__(self, rgb_colors):
- self.colors = rgb_colors[::-1]
-
- def at(self, x):
- i_left = int(x * len(self.colors))
- i_right = i_left + 1 if i_left < len(self.colors) - 1 else 0
- ratio = (x * len(self.colors)) - i_left
- return tuple(clamp8(left + ratio * (right - left)) for (left, right) in zip(self.colors[i_left], self.colors[i_right]))
-
- def from_dict(dict):
- if 'preset' in dict:
- return getattr(Gradients, dict['preset'])
- return Gradient([getattr(Colors, color) if isinstance(color, str) else color for color in dict['colors']])
-
-
- rainbow = Gradient([
- Colors.red,
- Colors.orange,
- Colors.yellow,
- Colors.green,
- Colors.blue,
- Colors.purple
- ])
-
-
- class Gradients:
- # Gradient Presets
-
- # Fun
-
- rainbow = rainbow
-
- dark_rainbow = Gradient([
- Colors.dark_red,
- Colors.dark_orange,
- Colors.dark_yellow,
- Colors.dark_green,
- Colors.dark_blue,
- Colors.dark_purple
- ])
-
- pale_rainbow = Gradient([
- Colors.pale_red,
- Colors.pale_orange,
- Colors.pale_yellow,
- Colors.pale_green,
- Colors.pale_blue,
- Colors.pale_purple
- ])
-
- random = Gradient([Colors.black if i % 2 else rainbow.at(random()) for i in range(0, 100)])
-
- pusheen = Gradient([
- Colors.teal,
- Colors.pink
- ])
-
- peacock = Gradient([
- Colors.teal,
- Colors.black,
- Colors.purple,
- Colors.blue,
- ])
-
-
- # Sports
-
- kraken = Gradient([
- ( 0, 1, 3), # Navy blue
- ( 24, 60, 48), # Light blue
- ( 0, 1, 3), # Navy blue (again)
- ( 10, 25, 25), # Blue (greenish)
- ])
-
-
- # Holiday
-
- love = Gradient([
- Colors.pink,
- Colors.black,
- Colors.red,
- Colors.black
- ])
-
- beads = Gradient([
- Colors.purple,
- Colors.black,
- Colors.green,
- Colors.yellow,
- Colors.black
- ])
-
- irish = Gradient([
- Colors.dark_green,
- Colors.black,
- Colors.green,
- Colors.black,
- ])
-
- bunny = Gradient([
- Colors.pink,
- Colors.pale_purple,
- Colors.black,
- Colors.pale_yellow,
- Colors.pale_green,
- Colors.black,
- ])
-
- patriot = Gradient([
- Colors.red,
- Colors.black,
- Colors.black,
- Colors.white,
- Colors.black,
- Colors.black,
- Colors.blue,
- Colors.black,
- Colors.black,
- ])
-
- pumpkin = Gradient([
- Colors.orange,
- Colors.black,
- Colors.purple,
- Colors.black,
- Colors.green,
- Colors.black,
- ])
-
- turkey = Gradient([
- Colors.orange,
- Colors.black,
- Colors.dark_green,
- Colors.black,
- Colors.brown,
- Colors.black,
- Colors.dark_yellow,
- Colors.black,
- ])
-
- mazel = Gradient([
- Colors.blue,
- Colors.black,
- Colors.white,
- Colors.black,
- ])
-
- santa = Gradient([
- Colors.red,
- Colors.white,
- Colors.green,
- Colors.black,
- ])
|