"""Draw the Bedrock ribbon study with Python's standard library.""" from math import cos, sin, pi from pathlib import Path def path(points, color): coords = " ".join(f"{x:.2f},{y:.2f}" for x, y in points) return f'' 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) 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 place(shape, x, y, scale): return f'{shape}' 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 ('' 'Bedrock — ribbon form studies' + "".join(marks) + '\n') if __name__ == "__main__": Path(__file__).with_name("preview.svg").write_text(draw(), encoding="utf-8")