Skip to content

Commit

Permalink
forgot to edit examples in #144
Browse files Browse the repository at this point in the history
  • Loading branch information
gottadiveintopython committed Aug 29, 2024
1 parent 8de41e4 commit 7e68e3f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
4 changes: 3 additions & 1 deletion examples/moving_a_sprite_along_with_a_bezier_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ async def play_animation(self, *, draw_target, speed=1.0):
texture=texture,
)
PopMatrix()
async for t in ak.anim_with_ratio(duration=1.5 / speed):
async for t in ak.anim_with_ratio(base=1.5 / speed):
x, y = calc_position(factors, t)
translate.x = x
translate.y = y
rotate.angle = calc_angle(velocity_factors, t)
if t >= 1.0:
break
await ak.sleep(1)
finally:
draw_target.canvas.remove(root_group)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ async def play_animation(self, *, draw_target, speed=1.0):
)
PopMatrix()
await ak.sleep(1.0 / speed)
async for t in ak.anim_with_ratio(duration=2.0 / speed):
async for t in ak.anim_with_ratio(base=2.0 / speed):
x, y = calc_position(factors, t)
translate.x = x
translate.y = y
rotate.angle = calc_angle(velocity_factors, t)
if t >= 1.0:
break
await ak.sleep(1)
finally:
draw_target.canvas.remove(root_group)
Expand Down
20 changes: 14 additions & 6 deletions examples/moving_a_sprite_along_with_a_catmull_rom_spline.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,19 @@ async def play_animation(self, *, draw_target, speed=1.0, n_spline_segments):
color_inst3 = Color(1.0, 1.0, 1.0, 1.0)
point_inst = Point(pointsize=1.0)
flattened = array.array('f')
async for p in ak.anim_with_ratio(duration=n_segments * 2.0 / speed):
if p >= 1.0:
quit = False
async for p in ak.anim_with_ratio(base=2.0 / speed):
if p >= n_segments:
quit = True
f = interpolating_functions[-1]
t = 1.0
else:
idx, t = divmod(p * n_segments, 1.0)
idx, t = divmod(p, 1.0)
f = interpolating_functions[int(idx)]
flattened.extend(f[0](t))
point_inst.points = flattened
if quit:
break

# Fade-out the group1, and make the above points darker
await slp()
Expand All @@ -114,17 +118,21 @@ async def play_animation(self, *, draw_target, speed=1.0, n_spline_segments):
texture=texture,
)
PopMatrix()
async for p in ak.anim_with_ratio(duration=n_segments * 2.0 / speed):
if p >= 1.0:
quit = False
async for p in ak.anim_with_ratio(base=2.0 / speed):
if p >= n_segments:
quit = True
f = interpolating_functions[-1]
t = 1.0
else:
idx, t = divmod(p * n_segments, 1.0)
idx, t = divmod(p, 1.0)
f = interpolating_functions[int(idx)]
x, y = f[0](t)
translate.x = x
translate.y = y
rotate.angle = f[1](t)
if quit:
break
await ak.sleep(1)
finally:
draw_target.canvas.remove(root_group)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,21 @@ async def play_animation(self, *, draw_target, speed=1.0, n_spline_segments):
)
PopMatrix()
await ak.sleep(1.0 / speed)
async for p in ak.anim_with_ratio(duration=n_spline_segments * 2.0 / speed):
if p >= 1.0:
quit = False
async for p in ak.anim_with_ratio(base=2.0 / speed):
if p >= n_spline_segments:
quit = True
f = interpolating_functions[-1]
t = 1.0
else:
idx, t = divmod(p * n_spline_segments, 1.0)
idx, t = divmod(p, 1.0)
f = interpolating_functions[int(idx)]
x, y = f[0](t)
translate.x = x
translate.y = y
rotate.angle = f[1](t)
if quit:
break
await ak.sleep(1)
finally:
draw_target.canvas.remove(root_group)
Expand Down
6 changes: 4 additions & 2 deletions examples/popping_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ async def pop_widget(widget, *, height=300., duration=1., rotation_speed: degree
rotate = Rotate(origin=widget.center)
ig.add(translate)
ig.add(rotate)
async for dt, et, p in anim_with_dt_et_ratio(duration=duration):
p = p * 2. - 1. # convert range[0 to +1] into range[-1 to +1]
async for dt, et, p in anim_with_dt_et_ratio(base=duration / 2.):
p -= 1.
translate.y = (-(p * p) + 1.) * height
rotate.angle = et * rotation_speed
if p >= 1.:
break


KV_CODE = r'''
Expand Down

0 comments on commit 7e68e3f

Please sign in to comment.