From 1a725e50a276f4be76414d3a541fceaad42caeef Mon Sep 17 00:00:00 2001 From: Patrick Moessler Date: Sun, 19 Feb 2023 16:02:49 +0100 Subject: [PATCH] Add rainbow surface generator --- effects/effect.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/effects/effect.py b/effects/effect.py index 1c25936..889f598 100644 --- a/effects/effect.py +++ b/effects/effect.py @@ -1,7 +1,7 @@ from dataclasses import dataclass import math import random -from typing import Generator, Tuple +from typing import Generator, Literal, Tuple import pygame as pg @@ -42,6 +42,23 @@ def color_randomize() -> Generator[pg.Color, None, None]: color.hsla = random.randint(0, 359), s, l, a +def rainbow_surface( + image: pg.Surface, + orientation: Literal["h", "v"] = "h", + hue: int = 0, + increase: int = 1, +): + wheel = color_wheel(hue, increase) + if orientation == "h": + h = image.get_height() + for x in range(image.get_width()): + pg.draw.line(image, next(wheel), (x, 0), (x, h)) + elif orientation == "v": + w = image.get_width() + for y in range(image.get_height()): + pg.draw.line(image, next(wheel), (0, y), (w, y)) + + def transform_bounce( bounds: pg.Rect, velocity: Tuple[int, int],