fix typing/flake issues
This commit is contained in:
parent
ea7b66d166
commit
5e73904b52
4 changed files with 28 additions and 20 deletions
|
@ -32,8 +32,8 @@ class BouncingSpot(Effect):
|
|||
image.fill(Colors.Black)
|
||||
image.set_colorkey(Colors.Black)
|
||||
super().__init__(
|
||||
image=image,
|
||||
rect=pg.Rect(
|
||||
image,
|
||||
pg.Rect(
|
||||
bounds.centerx - size / 2,
|
||||
bounds.centery - size / 2,
|
||||
size,
|
||||
|
@ -65,5 +65,5 @@ class BouncingSpot(Effect):
|
|||
((0, 0), self.rect.size),
|
||||
)
|
||||
|
||||
self.ticks += self.velocity / 180 * math.pi
|
||||
self.ticks += int(self.velocity / 180 * math.pi)
|
||||
self.velocity = random.randint(self.min_velocity, self.max_velocity)
|
||||
|
|
|
@ -2,11 +2,12 @@ from typing import Any, List, Tuple
|
|||
import pygame as pg
|
||||
from effects.effect import Effect, Colors
|
||||
import random
|
||||
import math
|
||||
from typing import Union, Generator
|
||||
|
||||
|
||||
def fade_statemachine(fade_in: int, hold: int, fade_out: int) -> Tuple[int, bool, bool]:
|
||||
def fade_statemachine(
|
||||
fade_in: int, hold: int, fade_out: int
|
||||
) -> Generator[Tuple[int, bool, bool], None, None]:
|
||||
for t in range(fade_in):
|
||||
yield 255 * t // fade_in, False, False
|
||||
for t in range(hold):
|
||||
|
@ -76,7 +77,7 @@ class DoubleSpot(Effect):
|
|||
|
||||
image = pg.Surface(size=bounds.size)
|
||||
image.set_colorkey(Colors.Black)
|
||||
super().__init__(image=image, rect=bounds, *groups)
|
||||
super().__init__(image, bounds, *groups)
|
||||
|
||||
self.update()
|
||||
|
||||
|
@ -85,7 +86,12 @@ class DoubleSpot(Effect):
|
|||
random.randint(0, self.randrange[0]) * self.radius * 2 + self.radius,
|
||||
random.randint(0, self.randrange[1]) * self.radius * 2 + self.radius,
|
||||
)
|
||||
while any(( (s.rect.centerx==position[0] and s.rect.centery==position[1] ) for s in self.spots)):
|
||||
while any(
|
||||
(
|
||||
(s.rect.centerx == position[0] and s.rect.centery == position[1])
|
||||
for s in self.spots
|
||||
)
|
||||
):
|
||||
position = (
|
||||
random.randint(0, self.randrange[0]) * self.radius * 2 + self.radius,
|
||||
random.randint(0, self.randrange[1]) * self.radius * 2 + self.radius,
|
||||
|
|
|
@ -23,7 +23,7 @@ class Colors:
|
|||
Magenta = pg.Color(255, 0, 255)
|
||||
|
||||
|
||||
def color_wheel(hue=0, increase=1) -> pg.Color:
|
||||
def color_wheel(hue=0, increase=1) -> Generator[pg.Color, None, None]:
|
||||
color = copy_color(Colors.Red)
|
||||
h, s, l, a = color.hsla
|
||||
h = hue
|
||||
|
@ -34,7 +34,7 @@ def color_wheel(hue=0, increase=1) -> pg.Color:
|
|||
h = (h + increase) % 360
|
||||
|
||||
|
||||
def color_randomize() -> pg.Color:
|
||||
def color_randomize() -> Generator[pg.Color, None, None]:
|
||||
color = copy_color(Colors.Red)
|
||||
h, s, l, a = color.hsla
|
||||
color.hsla = random.randint(0, 359), s, l, a
|
||||
|
@ -49,25 +49,27 @@ def transform_bounce(
|
|||
velocity: Tuple[int, int],
|
||||
x_factor: Tuple[int, int],
|
||||
y_factor: Tuple[int, int],
|
||||
):
|
||||
) -> Generator[Tuple[int, int], Tuple[int, int], None]:
|
||||
min_velocity = velocity[0]
|
||||
max_velocity = velocity[1]
|
||||
velocity = random.randint(min_velocity, max_velocity)
|
||||
current_velocity = random.randint(min_velocity, max_velocity)
|
||||
ticks = random.randint(0, 360)
|
||||
x_factor = random.uniform(x_factor[0], x_factor[1])
|
||||
y_factor = random.uniform(y_factor[0], y_factor[1])
|
||||
current_x_factor = random.uniform(x_factor[0], x_factor[1])
|
||||
current_y_factor = random.uniform(y_factor[0], y_factor[1])
|
||||
|
||||
size_x, size_y = yield (bounds.centerx, bounds.centery)
|
||||
while True:
|
||||
pos_x = (
|
||||
math.cos(x_factor * ticks) * (bounds.width - size_x) // 2 + bounds.centerx
|
||||
pos_x = int(
|
||||
math.cos(current_x_factor * ticks) * (bounds.width - size_x) // 2
|
||||
+ bounds.centerx
|
||||
)
|
||||
pos_y = (
|
||||
math.sin(y_factor * ticks) * (bounds.height - size_y) // 2 + bounds.centery
|
||||
pos_y = int(
|
||||
math.sin(current_y_factor * ticks) * (bounds.height - size_y) // 2
|
||||
+ bounds.centery
|
||||
)
|
||||
|
||||
ticks += velocity / 180 * math.pi
|
||||
velocity = random.randint(min_velocity, max_velocity)
|
||||
ticks += int(current_velocity / 180 * math.pi)
|
||||
current_velocity = random.randint(min_velocity, max_velocity)
|
||||
size_x, size_y = yield (pos_x, pos_y)
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from random import choice
|
||||
from typing import List
|
||||
from effects.effect import Effect, color_randomize, color_wheel, Colors
|
||||
from effects.effect import Effect, color_wheel, Colors
|
||||
from effects.bouncingspot import BouncingSpot
|
||||
from effects.doublespot import DoubleSpot
|
||||
import pygame as pg
|
||||
|
|
Loading…
Add table
Reference in a new issue