31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
from .GameChild import GameChild
|
|
from .extension import get_random_hsla_color, get_range_steps, get_hsla_color
|
|
|
|
class Gradient(GameChild):
|
|
|
|
def __init__(self, parent, rect, granularity, start=None, end=None):
|
|
GameChild.__init__(self, parent)
|
|
if start is None:
|
|
start = get_random_hsla_color()
|
|
self.start = start
|
|
if end is None:
|
|
end = get_random_hsla_color()
|
|
self.end = end
|
|
self.rect = rect
|
|
self.granularity = granularity
|
|
|
|
def update(self):
|
|
ds = self.get_display_surface()
|
|
y = self.rect.top
|
|
hues = list(get_range_steps(self.start.hsla[0], self.end.hsla[0],
|
|
self.granularity))
|
|
saturations = list(get_range_steps(self.start.hsla[1], self.end.hsla[1],
|
|
self.granularity))
|
|
lightnesses = list(get_range_steps(self.start.hsla[2], self.end.hsla[2],
|
|
self.granularity))
|
|
for index in range(len(hues)):
|
|
h = self.rect.h // self.granularity
|
|
ds.fill(get_hsla_color(int(hues[index]), int(saturations[index]), int(lightnesses[index])),
|
|
(self.rect.left, y, self.rect.w, h))
|
|
y += h
|