Fix color copying for color_*()
This commit is contained in:
parent
f2f8ccaf56
commit
e5a0dcaf61
1 changed files with 12 additions and 11 deletions
|
@ -2,11 +2,15 @@ from dataclasses import dataclass
|
|||
from enum import Enum
|
||||
import math
|
||||
import random
|
||||
from typing import Tuple
|
||||
from typing import Generator, Tuple
|
||||
import pygame as pg
|
||||
from abc import abstractmethod
|
||||
|
||||
|
||||
def copy_color(source: pg.Color) -> pg.Color:
|
||||
return pg.Color(source.r, source.g, source.b, source.a)
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class Colors:
|
||||
Black = pg.Color(0, 0, 0)
|
||||
|
@ -20,19 +24,18 @@ class Colors:
|
|||
|
||||
|
||||
def color_wheel(hue=0, increase=1) -> pg.Color:
|
||||
color = Colors.Red
|
||||
color = copy_color(Colors.Red)
|
||||
h, s, l, a = color.hsla
|
||||
color.hsla = hue, s, l, a
|
||||
h = hue
|
||||
|
||||
while True:
|
||||
yield color
|
||||
h, s, l, a = color.hsla
|
||||
h = (h + increase) % 360
|
||||
color.hsla = h, s, l, a
|
||||
yield color
|
||||
h = (h + increase) % 360
|
||||
|
||||
|
||||
def color_randomize() -> pg.Color:
|
||||
color = Colors.Red
|
||||
color = copy_color(Colors.Red)
|
||||
h, s, l, a = color.hsla
|
||||
color.hsla = random.randint(0, 359), s, l, a
|
||||
|
||||
|
@ -57,12 +60,10 @@ def transform_bounce(
|
|||
size_x, size_y = yield (bounds.centerx, bounds.centery)
|
||||
while True:
|
||||
pos_x = (
|
||||
math.cos(x_factor * ticks) * (bounds.width - 2 * size_x) // 2
|
||||
+ bounds.centerx
|
||||
math.cos(x_factor * ticks) * (bounds.width - size_x) // 2 + bounds.centerx
|
||||
)
|
||||
pos_y = (
|
||||
math.sin(y_factor * ticks) * (bounds.height - 2 * size_y) // 2
|
||||
+ bounds.centery
|
||||
math.sin(y_factor * ticks) * (bounds.height - size_y) // 2 + bounds.centery
|
||||
)
|
||||
|
||||
ticks += velocity / 180 * math.pi
|
||||
|
|
Loading…
Reference in a new issue