Skip to content

Instantly share code, notes, and snippets.

@nazfox
Created May 8, 2022 05:16
Show Gist options
  • Save nazfox/bae79b3540f76b3f4eb88022470a141b to your computer and use it in GitHub Desktop.
Save nazfox/bae79b3540f76b3f4eb88022470a141b to your computer and use it in GitHub Desktop.
keyframeを自動生成するスクリプト
#!/bin/env python
def ease_in_out_quad(x):
if x < 0.5:
return 2 * x * x
else:
return 1 - pow(-2 * x + 2, 2) / 2
n_step = 50
n_sway = 2
key_start = 50
x_start = -30
x_end = 20
x_diff = x_end - x_start
sway_step = n_step / n_sway
sway_init = (sway_step * abs(x_start / x_diff) / 2)
y_start = -70
y_end = 240
y_diff = y_end - y_start
for i in range(n_step):
xi = 1 - abs((i + sway_init) % sway_step / sway_step * 2 - 1)
x = x_diff * ease_in_out_quad(xi) + x_start;
y = y_diff * ease_in_out_quad((i + 1) / n_step);
if y > y_end:
y = y - y_diff
a = key_start + (i + 1) / n_step * (100 - key_start)
print(f"{a}% {{ transform: translate({x:.2f}px, {y:.2f}px); }}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment