Branchwell

PulseCanvas / app · pulsecanvas.ai / packaging / macos / generate-background.py

Raw 4.3 KB on 0c0f13aedcaf984646237f478d4915d73e9d0aeb
1"""Render original installer artwork at 1x/2x. Requires Pillow, not used in CI."""
2from pathlib import Path
3import math
4import subprocess
5
6from PIL import Image, ImageDraw, ImageFont
7
8ROOT = Path(__file__).resolve().parent
9FONT = Path("/System/Library/Fonts/SFNS.ttf")
10
11
12def render(scale: int) -> None:
13 width, height = 720 * scale, 460 * scale
14 canvas = Image.new("RGB", (width, height))
15 pixels = canvas.load()
16 # PulseCanvas brand base #17121b with light concentrated behind the installation path.
17 for y in range(height):
18 for x in range(width):
19 glow = math.exp(-(((x / scale - 360) / 410) ** 2
20 + ((y / scale - 240) / 300) ** 2))
21 pixels[x, y] = tuple(round(base + glow * lift)
22 for base, lift in zip((23, 18, 27), (24, 17, 29)))
23 draw = ImageDraw.Draw(canvas)
24
25 def box(bounds: tuple) -> tuple:
26 return tuple(round(value * scale) for value in bounds)
27
28 def text(value: str, y: int, size: int, color: str, weight: int = 400) -> None:
29 font = ImageFont.truetype(str(FONT), size * scale)
30 # SF's weight axis uses its own range. Select named instances when present.
31 names = font.get_variation_names()
32 desired = b"Bold" if weight >= 600 else b"Regular"
33 if desired in names:
34 font.set_variation_by_name(desired)
35 if draw.textlength(value, font=font) > 632 * scale:
36 raise ValueError(f"Installer instruction exceeds safe width: {value}")
37 draw.text((360 * scale, y * scale), value, font=font,
38 fill=color, anchor="mt")
39
40 draw.rounded_rectangle(box((18, 18, 702, 442)), radius=22 * scale,
41 outline="#67566F", width=scale)
42 text("Install PulseCanvas Studio", 48, 30, "#FFFFFF", 700)
43 text("Drag PulseCanvas Studio to Applications to get started.", 95, 16, "#E5DCEC")
44
45 # The real draggable Finder icons are placed over these two quiet wells.
46 draw.rounded_rectangle(box((117, 154, 273, 316)), radius=22 * scale,
47 fill="#DED1EB")
48 draw.rounded_rectangle(box((447, 154, 603, 316)), radius=22 * scale,
49 fill="#DED1EB", outline="#B5A1CD", width=scale)
50 # Rounded dotted outline: evenly spaced dots along four sides and corner arcs.
51 left, top, right, bottom, radius = 110, 147, 280, 323, 29
52 dots = []
53 for start, stop, fixed, horizontal in (
54 (left + radius, right - radius, top, True),
55 (left + radius, right - radius, bottom, True),
56 (top + radius, bottom - radius, left, False),
57 (top + radius, bottom - radius, right, False),
58 ):
59 count = round((stop - start) / 9)
60 for index in range(count + 1):
61 value = start + (stop - start) * index / count
62 dots.append((value, fixed) if horizontal else (fixed, value))
63 for cx, cy, begin in ((left + radius, top + radius, 180),
64 (right - radius, top + radius, 270),
65 (right - radius, bottom - radius, 0),
66 (left + radius, bottom - radius, 90)):
67 for angle in range(begin + 15, begin + 90, 20):
68 dots.append((cx + radius * math.cos(math.radians(angle)),
69 cy + radius * math.sin(math.radians(angle))))
70 for x, y in dots:
71 draw.ellipse(box((x - 1.15, y - 1.15, x + 1.15, y + 1.15)), fill="#F2B394")
72
73 # Rounded arrow pointing from the app to the actual Applications shortcut.
74 draw.line(box((321, 230, 396, 230)), fill="#C5B3DF", width=3 * scale)
75 draw.line(box((381, 215, 397, 230, 381, 245)), fill="#C5B3DF", width=3 * scale)
76 draw.line(box((88, 355, 632, 355)), fill="#67566F", width=scale)
77 text("Eject this disk image when copying is complete.", 378, 15, "#F7F1ED")
78 text("Open PulseCanvas Studio from your Applications folder.", 410, 14, "#C5B3DF")
79 target = ROOT / ("background.png" if scale == 1 else "background@2x.png")
80 canvas.save(target, dpi=(72 * scale, 72 * scale))
81 print(target.name, canvas.size)
82
83
84if __name__ == "__main__":
85 render(1)
86 render(2)
87 subprocess.run(["tiffutil", "-cathidpicheck", str(ROOT / "background.png"),
88 str(ROOT / "background@2x.png"), "-out", str(ROOT / "background.tiff")],
89 check=True)