In [1]:
##########
# Optional:
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
##########
import re
import pytweening
def find_tweens_from_module(pytweening):
return (
name for name in dir(pytweening)
if name == 'linear' or name.startswith('ease')
)
def organize_names(names):
unique = []
ease = {}
regex = re.compile(r'^ease(InOut|In|Out)(.+)$')
for fullname in names:
match = regex.match(fullname)
if match:
direction = match.group(1)
kind = match.group(2)
item = ease.get(kind, {'In': None, 'Out': None, 'InOut': None})
item[direction] = fullname
ease[kind] = item
else:
unique.append(fullname)
unique.sort()
table = []
table.append(unique)
table.extend(
[item['In'], item['Out'], item['InOut']]
for kind,item in sorted(ease.items())
)
return table
In [2]:
%matplotlib inline
%config InlineBackend.figure_format = 'svg'
from numpy import linspace
from matplotlib import pyplot
table = organize_names(find_tweens_from_module(pytweening))
rows = len(table)
cols = max(len(row) for row in table)
fig, ax = pyplot.subplots(rows, cols, sharex=True, sharey=True, figsize=(3 * cols, 3 * rows), dpi=96)
fig.tight_layout(h_pad=0, w_pad=0)
fig.subplots_adjust(hspace=0, wspace=0)
ax[0,0].set_xticks(linspace(0, 1, 11))
ax[0,0].set_xticklabels([])
X = linspace(0, 1, 256)
for i, row in enumerate(table):
for j, col in enumerate(row):
if col:
func = getattr(pytweening, col)
Y = [func(x) for x in X]
pyplot.text(x=0.5, y=0.9, s=col, horizontalalignment='center', transform=ax[i,j].transAxes)
ax[i,j].axhline(y=0, color='silver')
ax[i,j].axhline(y=1, color='silver')
ax[i,j].plot(X, Y)
for j in range(len(row), cols):
ax[i,j].set_visible(False)