113 lines
5.1 KiB
Python
113 lines
5.1 KiB
Python
"""Calm streak animations: for calm tasks, at any streak level. 2 s, slow, small and quiet, like the
|
|
calm set (gentle boil CB, thin strokes, things easing in and out), each showing the streak number.
|
|
Sounds: calm_sounds.py (written quiet, like the calm set's).
|
|
"""
|
|
import math
|
|
|
|
from anim_kit import CB, NUM, K, cc, cl, cp, ease_out, inout, oval, rotate
|
|
|
|
|
|
def snowglobe(i, t):
|
|
"""A snow globe sits on the box with the number inside; its flakes swirl slowly round and settle at the bottom."""
|
|
s = []
|
|
cx, cy, r = 0.0, -2.1, 1.45
|
|
s.append(cp([(-1.0, -0.25), (1.0, -0.25), (0.8, -0.75), (-0.8, -0.75)])) # the base
|
|
s.append(cc(cx, cy, r, 0.08))
|
|
s.append(cl([(cx - 0.9, cy - 0.75), (cx - 0.55, cy - 1.05)], 0.06)) # a glint on the glass
|
|
s.append(K("red"))
|
|
s.append(NUM(cx, cy - 0.1, 1.05, boil=CB))
|
|
s.append(K("blue"))
|
|
settle = ease_out(min(1.0, t * 1.25))
|
|
for k in range(11):
|
|
a = k * 2.4 + t * 2.2 * (1 - settle)
|
|
rr = 0.35 + (k % 4) * 0.25
|
|
x0, y0 = cx + rr * math.cos(a), cy + rr * math.sin(a) * 0.8
|
|
x1 = cx - 1.0 + k * 0.2
|
|
y1 = cy + r - 0.22 - 0.06 * (k % 2) - 0.25 * (1 - abs(x1 - cx) / 1.2) * 0.4
|
|
x, y = x0 + (x1 - x0) * settle, y0 + (y1 - y0) * settle
|
|
s.append(cc(x, y, 0.06 + 0.02 * (k % 2)))
|
|
return s
|
|
|
|
|
|
def slate(i, t):
|
|
"""A little framed slate rises by the box; a stick of chalk taps the number onto it, then rests on the ledge in a puff of dust."""
|
|
s = []
|
|
up = ease_out(min(1.0, t * 3))
|
|
y0 = -0.9 - 0.9 * up
|
|
x0, x1, top = -1.6, 1.6, y0 - 2.4
|
|
s.append(cl([(x0, y0), (x1, y0), (x1, top), (x0, top), (x0, y0)], 0.16))
|
|
s.append(cl([(x0 - 0.2, y0 + 0.12), (x1 + 0.2, y0 + 0.12)], 0.1)) # the ledge
|
|
if i >= 8:
|
|
s.append(K("blue"))
|
|
s.append(NUM(0, (y0 + top) / 2, 1.25, boil=CB))
|
|
s.append(K("red"))
|
|
if i < 18: # the chalk, writing
|
|
u = max(0.0, (t - 0.25) / 0.5)
|
|
cx = -0.7 + 1.4 * min(1.0, u) + 0.1 * math.sin(i * 1.4)
|
|
cy = (y0 + top) / 2 - 0.4 + 0.5 * math.sin(i * 0.9)
|
|
s.append(cl(rotate([(cx, cy), (cx + 0.5, cy - 0.35)], 0.0), 0.14))
|
|
else: # put down on the ledge
|
|
s.append(cl([(0.9, y0 - 0.05), (1.4, y0 - 0.05)], 0.14))
|
|
g = inout((t - 0.75) / 0.25, 0.5)
|
|
for k in range(3):
|
|
s.append(cc(1.1 + (k - 1) * 0.25, y0 - 0.25 - k * 0.1 - (i - 18) * 0.05, 0.05 + 0.04 * g))
|
|
return s
|
|
|
|
|
|
def sundial(i, t):
|
|
"""A sundial by the box with the number on its face; the sun crosses the sky slowly and the gnomon's shadow sweeps round beneath it."""
|
|
s = []
|
|
cx, cy = 0.0, -1.0
|
|
s.append(cp(oval(cx, cy, 1.9, 0.6, 18))) # the dial, seen a little from above
|
|
s.append(K("blue"))
|
|
for k in range(7): # hour marks
|
|
a = math.pi + k * math.pi / 6
|
|
s.append(cl([(cx + 1.55 * math.cos(a), cy + 0.48 * math.sin(a)), (cx + 1.75 * math.cos(a), cy + 0.55 * math.sin(a))], 0.05))
|
|
s.append(K("yellow"))
|
|
s.append(cp([(cx - 0.05, cy), (cx + 0.05, cy), (cx + 0.05, cy - 1.0)])) # the gnomon
|
|
sa = math.pi * (1.05 + 0.9 * t) # the sun's path across the sky
|
|
sx, sy = cx + 3.2 * math.cos(sa), cy - 0.6 + 2.6 * math.sin(sa)
|
|
s.append(cc(sx, sy, 0.38))
|
|
for k in range(8):
|
|
a = k * math.pi / 4 + t * 0.6
|
|
s.append(cl([(sx + 0.55 * math.cos(a), sy + 0.55 * math.sin(a)), (sx + 0.75 * math.cos(a), sy + 0.75 * math.sin(a))], 0.05))
|
|
s.append(K("blue"))
|
|
ha = sa + math.pi # the shadow points away from the sun
|
|
s.append(cl([(cx, cy), (cx + 1.35 * math.cos(ha), cy + 0.42 * math.sin(ha) * -1)], 0.1))
|
|
s.append(K("red"))
|
|
s.append(NUM(cx, cy - 2.2, 1.2, boil=CB))
|
|
return s
|
|
|
|
|
|
def abacus(i, t):
|
|
"""A small abacus stands by the box; beads slide across one by one, unhurried, and the number settles in above it."""
|
|
s = []
|
|
x0, x1, y0, y1 = -1.8, 1.8, -0.4, -2.4
|
|
s.append(cl([(x0, y0), (x0, y1)], 0.14))
|
|
s.append(cl([(x1, y0), (x1, y1)], 0.14))
|
|
s.append(cl([(x0 - 0.2, y1), (x1 + 0.2, y1)], 0.14))
|
|
s.append(cl([(x0 - 0.2, y0), (x1 + 0.2, y0)], 0.14))
|
|
rows = 3
|
|
for r in range(rows):
|
|
y = y1 + (r + 1) * (y0 - y1) / (rows + 1)
|
|
s.append(cl([(x0, y), (x1, y)], 0.04))
|
|
for b in range(4):
|
|
start = (r * 4 + b) / 12 * 0.75 # one bead after another
|
|
u = ease_out(max(0.0, min(1.0, (t - start) / 0.18)))
|
|
bx = x0 + 0.3 + b * 0.38 + u * (x1 - x0 - 0.6 - 3 * 0.38 - 0.0) * 1.0
|
|
bx = min(bx, x1 - 0.3 - (3 - b) * 0.38)
|
|
s.append(K("yellow" if r == 1 else "red"))
|
|
s.append(cp(oval(bx, y, 0.17, 0.2, 10)))
|
|
s.append(K("blue"))
|
|
g = inout(t, 0.0001) * ease_out(min(1.0, max(0.0, (t - 0.45) / 0.3)))
|
|
if g > 0:
|
|
s.append(NUM(0, y1 - 1.0 - 0.3 * g, 0.6 + 0.7 * g, boil=CB))
|
|
s.append(K("red"))
|
|
return s
|
|
|
|
|
|
ANIMS = [
|
|
(snowglobe, "blue", "settle"), (slate, "red", "chalk"),
|
|
(sundial, "yellow", "noon"), (abacus, "red", "beads"),
|
|
]
|