diff --git a/brand/ribbon-study/generate.py b/brand/ribbon-study/generate.py
index 785b4f7..69f0a81 100644
--- a/brand/ribbon-study/generate.py
+++ b/brand/ribbon-study/generate.py
@@ -1,47 +1,64 @@
-"""Draw the Bedrock ribbon study with Python's standard library."""
+"""Render a ribbon study as editable SVG, using only the standard library."""
from math import cos, sin, pi
from pathlib import Path
+BACKGROUND = "#431744"
+# Coordinates are relative to the centre of the reference mark.
+CAP = "M-91 -78 C-67 -111 -34 -121 0 -121 C33 -121 70 -107 90 -80 C105 -59 82 -52 63 -53 C37 -52 14 -63 0 -74 C-23 -58 -47 -52 -69 -53 C-91 -53 -100 -63 -91 -78Z"
+LEFT = "M-91 -78 C-58 -107 -28 -99 0 -74 C-23 -58 -47 -52 -69 -53 C-91 -53 -100 -63 -91 -78Z"
+RIGHT = "M0 -74 C37 -104 65 -98 90 -80 C105 -59 82 -52 63 -53 C37 -52 14 -63 0 -74Z"
-def path(points, color):
- coords = " ".join(f"{x:.2f},{y:.2f}" for x, y in points)
- return f''
+
+def gradient(name, colors):
+ stops = ''.join(f''
+ for i, color in enumerate(colors))
+ return f'{stops}'
def trefoil():
- # Two faces share a crossing inside a rounded segment of the silhouette.
layers = []
- for angle, base, left, right in [
- (0, "#beabb6", "#a35f81", "#817e92"),
- (120, "#ffdabd", "#8a8599", "#ffa086"),
- (240, "#ffac91", "#fc887b", "#a8617c"),
- ]:
- layers.append(f'''
-
-
-
- ''')
- return "".join(layers)
+ palettes = [
+ ("#d6c9c6", "#917687", "#a35c78", "#874969", "#99909d", "#766d82"),
+ ("#ffe0bf", "#ffc0a2", "#8e8e9b", "#726d84", "#ffb295", "#ff8c76"),
+ ("#ffb390", "#ff917c", "#ff9983", "#ff846f", "#b57184", "#8c506f"),
+ ]
+ for index, colors in enumerate(palettes):
+ parts = []
+ for face, outline in enumerate((CAP, LEFT, RIGHT)):
+ name = f"petal-{index}-{face}"
+ parts.append(gradient(name, colors[2*face:2*face+2]))
+ parts.append(f'')
+ layers.append(f'{"".join(parts)}')
+ return ''.join(layers)
-def globe(count, wave, tilt, phase):
- front = ["#ffd9ba", "#ff947f", "#b8c6c3", "#e6a2a2"]
- rear = ["#99607b", "#766780", "#ad798b", "#7e708a"]
- faces = []
- for back in (True, False):
- for i in range(count):
- center = -pi / 2 + (i + .5) * pi / count
- edges = []
- for side in (-1, 1):
- edge = []
- for j in range(97):
- lon = (j / 96 + int(back)) * pi
- lat = center + (side * .33 * pi / count
- + wave * sin(2 * lon + phase) * sin(lon) ** 2 * cos(center))
- edge.append((96 * cos(lat) * cos(lon), -96 * sin(lat)))
- edges.append(edge)
- faces.append(path(edges[0] + edges[1][::-1], (rear if back else front)[i % 4]))
- return f'' + "".join(faces) + ""
+def coil(turns, width, pitch, tilt, prefix):
+ """Project a spherical helix. Draw its far half-turns before its near ones."""
+ palettes = [
+ [("#7b566f", "#aa7889"), ("#a4b4bb", "#79748c"), ("#834764", "#b77987")],
+ [("#ffa58a", "#ff8876"), ("#ffdebb", "#f2b9a8"), ("#c2d6d0", "#a39daa")],
+ ]
+ layers = [[], []]
+ for half in range(2 * turns):
+ near = half % 2
+ start = half*pi
+ name = f"{prefix}-{half}"
+
+ def point(t, side):
+ u = t / (2*pi*turns)
+ lat = -pi/2 + pi*u + side*width*pi/(2*turns)*sin(pi*u)**.55
+ lat += pitch*sin(t)*cos(lat) + .12*sin(2*t)*cos(lat)
+ return f"{100*cos(lat)*cos(t):.2f},{-100*sin(lat):.2f}"
+
+ # Follow the actual circular limb between both edges at each turn.
+ points = [point(start + pi*j/80, -1) for j in range(81)]
+ points += [point(start + pi, -1+j/8) for j in range(1,17)]
+ points += [point(start + pi*j/80, 1) for j in reversed(range(80))]
+ points += [point(start, 1-j/8) for j in range(1,17)]
+ layers[near].append(gradient(name, palettes[near][(half//2)%3]))
+ opacity = .90 if near else .84
+ layers[near].append(f'')
+ return f'{"".join(layers[0]+layers[1])}'
def place(shape, x, y, scale):
@@ -49,13 +66,16 @@ def place(shape, x, y, scale):
def draw():
- marks = [place(trefoil(), 239, 223, 1.58)]
- for x, y, spec in [(536, 126, (3, .34, -17, .5)), (713, 126, (5, .16, 12, 1)),
- (536, 319, (4, .24, -10, 2)), (713, 319, (3, .28, 83, .4))]:
- marks.append(place(globe(*spec), x, y, .70))
- return ('\n')
+ marks = [place(trefoil(), 214, 238, 1.20)]
+ for index, (x, y, turns, width, pitch, tilt) in enumerate([
+ (502, 88, 2, .77, .45, -14), (673, 88, 3, .91, .40, 46),
+ (502, 239, 4, .85, .21, 4), (673, 239, 4, .46, .10, -10),
+ (502, 391, 3, .65, .39, -12), (673, 391, 3, .82, .21, 82),
+ ]):
+ marks.append(place(coil(turns, width, pitch, tilt, f"s{index}"), x, y, .48))
+ return ('\n')
if __name__ == "__main__":
diff --git a/brand/ribbon-study/preview.svg b/brand/ribbon-study/preview.svg
index 1c84da8..9f30892 100644
--- a/brand/ribbon-study/preview.svg
+++ b/brand/ribbon-study/preview.svg
@@ -1,13 +1 @@
-
+