diff --git a/util/transform.py b/util/transform.py index a333ad1..8736bd9 100644 --- a/util/transform.py +++ b/util/transform.py @@ -52,18 +52,31 @@ def transform_bounce( def transform_oscillate( bounds: pg.Rect, period: int, - initial_pos: XYCoord = (-1, -1), + initial_pos: XYCoord = (0, 0), + auto_period: int = 0, ) -> PositionGenerator: - pos_x = float(initial_pos[0] if initial_pos[0] > 0 else bounds.left) - pos_y = float(initial_pos[1] if initial_pos[1] > 0 else bounds.top) + pos_x = float(initial_pos[0]) + pos_y = float(initial_pos[1]) direction = "+" + last_period = 0 + while True: - (size_x, size_y), _ = yield (int(pos_x), int(pos_y)) + (size_x, size_y), is_beat = yield ( + int(pos_x + bounds.left), + int(pos_y + bounds.top), + ) range_x = bounds.width - size_x range_y = bounds.height - size_y + if auto_period: + if is_beat: + period = last_period * auto_period + last_period = 0 + else: + last_period += 1 + inc_x = range_x / period inc_y = range_y / period