fix transform_oscillate offset
This commit is contained in:
parent
b91e2d76b8
commit
bb29fcac7b
1 changed files with 17 additions and 4 deletions
|
@ -52,18 +52,31 @@ def transform_bounce(
|
||||||
def transform_oscillate(
|
def transform_oscillate(
|
||||||
bounds: pg.Rect,
|
bounds: pg.Rect,
|
||||||
period: int,
|
period: int,
|
||||||
initial_pos: XYCoord = (-1, -1),
|
initial_pos: XYCoord = (0, 0),
|
||||||
|
auto_period: int = 0,
|
||||||
) -> PositionGenerator:
|
) -> PositionGenerator:
|
||||||
pos_x = float(initial_pos[0] if initial_pos[0] > 0 else bounds.left)
|
pos_x = float(initial_pos[0])
|
||||||
pos_y = float(initial_pos[1] if initial_pos[1] > 0 else bounds.top)
|
pos_y = float(initial_pos[1])
|
||||||
direction = "+"
|
direction = "+"
|
||||||
|
|
||||||
|
last_period = 0
|
||||||
|
|
||||||
while True:
|
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_x = bounds.width - size_x
|
||||||
range_y = bounds.height - size_y
|
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_x = range_x / period
|
||||||
inc_y = range_y / period
|
inc_y = range_y / period
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue