Add rainbow surface generator

This commit is contained in:
Patrick Moessler 2023-02-19 16:02:49 +01:00
parent 0e567b36fd
commit 1a725e50a2

View file

@ -1,7 +1,7 @@
from dataclasses import dataclass from dataclasses import dataclass
import math import math
import random import random
from typing import Generator, Tuple from typing import Generator, Literal, Tuple
import pygame as pg 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 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( def transform_bounce(
bounds: pg.Rect, bounds: pg.Rect,
velocity: Tuple[int, int], velocity: Tuple[int, int],