Skip to content

Commit 68038ac

Browse files
committed
Merge branch 'pr/saraaldosari/307' into main
2 parents 61cc03d + 71d4535 commit 68038ac

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

examples/basic/easing_functions.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from pgzero.builtins import *
2+
from pgzero import animation
3+
import itertools
4+
5+
WIDTH = 800
6+
HEIGHT = 800
7+
#print(animation.TWEEN_FUNCTIONS
8+
MARGIN = 20
9+
10+
def position_for_block(i):
11+
BLOCK_POSITIONS = [[(150, (i * 50 + i * MARGIN)), (WIDTH - 150, (i * 50 + i * MARGIN))] for i in range(len(animation.TWEEN_FUNCTIONS))]
12+
return BLOCK_POSITIONS[i]
13+
14+
15+
16+
positions = [itertools.cycle(position_for_block(i)) for i in range(len(animation.TWEEN_FUNCTIONS))]
17+
blocks = [Actor('block', center=next(positions[i])) for i in range(len(animation.TWEEN_FUNCTIONS))]
18+
19+
line_centers = [(WIDTH/2, i * (50 + MARGIN)) for i in range(len(animation.TWEEN_FUNCTIONS))]
20+
21+
def draw():
22+
screen.clear()
23+
#[block.draw() for block in blocks]
24+
for i, easing_f_name in enumerate(animation.TWEEN_FUNCTIONS):
25+
block = blocks[i]
26+
screen.draw.text(easing_f_name, line_centers[i])
27+
block.draw()
28+
29+
30+
def move_blocks():
31+
for i, easing_f_name in enumerate(animation.TWEEN_FUNCTIONS):
32+
animate(
33+
blocks[i],
34+
easing_f_name,
35+
duration=5,
36+
pos = next(positions[i])
37+
38+
)
39+
40+
"""
41+
def move_block():
42+
animate(
43+
block,
44+
'bounce_end',
45+
duration=1,
46+
pos=next(block_positions)
47+
)
48+
""";
49+
50+
move_blocks() # start one move now
51+
clock.schedule_interval(move_blocks, 6)
52+

src/pgzero/animation.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# http://www.clutter-project.org/docs/clutter/stable/ClutterAlpha.html
33

44

5-
from math import sin, pow, pi
5+
from math import sin, cos, pow, pi
66

77
from .clock import each_tick, unschedule
88
from .spellcheck import suggest
@@ -75,6 +75,22 @@ def in_out_elastic(n):
7575
return pow(2, -10 * q) * sin((q - s) * (2.0 * pi) / p) * .5 + 1.0
7676

7777

78+
@tweener
79+
def out_sine(n):
80+
return sin(n * pi/2)
81+
82+
@tweener
83+
def in_sine(n):
84+
return 1 - cos(n * pi/2)
85+
86+
@tweener
87+
def in_out_sine(n):
88+
return -(cos(pi * n) - 1)/2
89+
90+
@tweener
91+
def out_expo(n):
92+
return 1 if n == 1 else 1 - pow(2, -10 * n)
93+
7894
def _out_bounce_internal(t, d):
7995
p = t / d
8096
if p < (1.0 / 2.75):

0 commit comments

Comments
 (0)