Branchwell

Graphley / app · graphley.ai / scripts / icon-waves.py

Raw 1.5 KB on 089159c793cd9cbff9078de2ee49995b60c6b768
1"""Generates the three tide curves in brand/graphley-icon.svg.
2
3Each edge is one smooth function, sampled and turned into cubic Béziers with matching tangents
4at every join (Catmull-Rom), so the waves have no kinks or flat spots. The bands are offsets of the
5same curve, so they stay parallel and widen a little toward the right.
6Run: python3 scripts/icon-waves.py (prints the three path d= strings)
7"""
8import math
9
10X0, X1 = -80.0, 1104.0
11
12def smooth(t):
13 t = min(1.0, max(0.0, t))
14 return t * t * t * (t * (6 * t - 15) + 10)
15
16def crest(x):
17 # A soft trough on the left, then one long, even rise to the upper right.
18 dip = 34 * math.exp(-((x - 300) / 230) ** 2)
19 rise = 470 * smooth((x - 220) / 1050)
20 return 585 + dip - rise
21
22def edge(offset, spread):
23 return lambda x: crest(x) + offset + spread * (x - X0) / (X1 - X0)
24
25def path(f, n=12):
26 xs = [X0 + (X1 - X0) * i / n for i in range(n + 1)]
27 pts = [(x, f(x)) for x in xs]
28 d = f"M{pts[0][0]:.1f} {pts[0][1]:.1f}"
29 for i in range(n):
30 p0 = pts[max(i - 1, 0)]; p1 = pts[i]; p2 = pts[i + 1]; p3 = pts[min(i + 2, n)]
31 c1 = (p1[0] + (p2[0] - p0[0]) / 6, p1[1] + (p2[1] - p0[1]) / 6)
32 c2 = (p2[0] - (p3[0] - p1[0]) / 6, p2[1] - (p3[1] - p1[1]) / 6)
33 d += f" C{c1[0]:.1f} {c1[1]:.1f} {c2[0]:.1f} {c2[1]:.1f} {p2[0]:.1f} {p2[1]:.1f}"
34 return d + " L1104 1100 L-80 1100 Z"
35
36if __name__ == "__main__":
37 print("crest", path(crest))
38 print("band-teal", path(edge(162, 40)))
39 print("band-amber", path(edge(325, 70)))