plymouth-theme.py (5379B)
1 #!/usr/bin/env python3 2 """Makes the boot and shutdown splash: an animated Sector F flask (the logo's own drawing, with the 3 liquid rising and falling, bubbles, and the two circles at the end of its pipe pulsing) in the middle 4 of Everforest's background, and the words Sector F Labs at the bottom. Plymouth's two-step plugin 5 plays the frames in a loop. Run in the Containerfile's plymouth-theme stage, which has librsvg2-tools 6 and Pillow; the result is /usr/share/plymouth/themes/sectorf/, built on Fedora's spinner theme (for 7 its password-prompt pictures). 8 9 plymouth-theme.py <spinner theme dir> <logo.svg> <output dir> 10 """ 11 import math 12 import re 13 import subprocess 14 import sys 15 from pathlib import Path 16 17 from PIL import Image 18 19 BACKGROUND = 0x2D353B # Everforest Dark's bg0, as the greeter's 20 LIQUID = "#A7C080" # its accent 21 GLASS = "#D3C6AA" # its text 22 FRAMES = 60 # one loop 23 HEIGHT = 128 # px: the flask, bigger than the greeter's 64 px avatars 24 WORD_WIDTH = 300 # px: Sector F Labs 25 26 src, logo, out = (Path(a) for a in sys.argv[1:4]) 27 out.mkdir(parents=True, exist_ok=True) 28 29 # The flask is drawn in the logo's own coordinates (see seflos-logo.svg: a 1024-ish grid, the pipe and 30 # its two circles above the stopper at y 352..392, the neck at x 388..632, the round bottom to y 905). 31 OUTER = ("M388,385 V515 L252,697 Q222,738 222,785 Q230,900 510,905 Q790,900 798,785 " 32 "Q798,738 768,697 L632,515 V385 Z") 33 # What the glass encloses, a wall's thickness (40) inside the outer outline. 34 INNER = ("M428,385 V528 L287,720 Q262,758 262,790 Q270,865 510,865 Q750,865 758,790 " 35 "Q758,758 733,720 L592,528 V385 Z") 36 37 38 def frame_svg(i: int) -> str: 39 t = i / FRAMES 40 phase = 2 * math.pi * t 41 # The liquid's surface sits between the neck's bottom and the belly, and sways. 42 level = 700 - 95 * math.sin(phase) 43 wave = [] 44 for x in range(200, 821, 20): 45 y = level + 9 * math.sin(phase * 2 + x / 55) 46 wave.append(f"{x},{y:.1f}") 47 liquid = "M200,1000 L200," + wave[0].split(",")[1] + " L" + " L".join(wave) + " L820,1000 Z" 48 # Bubbles rise through the liquid, each on its own loop, fading at the top. 49 bubbles = [] 50 for k, (x, speed, r) in enumerate([(420, 1, 17), (520, 2, 12), (600, 1, 20), (470, 3, 9)]): 51 u = (t * speed + k * 0.23) % 1.0 52 y = 870 - u * (870 - level) 53 if y > level + 12: 54 bubbles.append(f'<circle cx="{x + 12 * math.sin(u * 9 + k)}" cy="{y:.1f}" r="{r}" ' 55 f'fill="none" stroke="#2D353B" stroke-opacity=".55" stroke-width="7"/>') 56 # The pipe's circles pulse, one after the other. 57 r1 = 40 + 3 * math.sin(phase) 58 r2 = 40 + 3 * math.sin(phase + math.pi) 59 return f'''<svg xmlns="http://www.w3.org/2000/svg" width="{HEIGHT * 700 // 835}" height="{HEIGHT}" viewBox="150 105 700 835"> 60 <defs><clipPath id="belly"><path d="{INNER}"/></clipPath></defs> 61 <g fill="none" stroke="{GLASS}" stroke-linejoin="round" stroke-linecap="round"> 62 <path d="M181,297 H664 M285,297 L398,172 H548" stroke-width="32"/> 63 <circle cx="591" cy="178" r="{r1:.1f}" stroke-width="37"/> 64 <circle cx="710" cy="293" r="{r2:.1f}" stroke-width="37"/> 65 </g> 66 <g clip-path="url(#belly)"><path d="{liquid}" fill="{LIQUID}"/>{"".join(bubbles)}</g> 67 <path fill="{GLASS}" fill-rule="evenodd" d="{OUTER} {INNER}"/> 68 <rect x="350" y="352" width="318" height="40" rx="20" fill="{GLASS}"/> 69 </svg>''' 70 71 72 def render(svg: str, path: Path, *args: str) -> None: 73 subprocess.run(["rsvg-convert", *args, "-o", str(path), "/dev/stdin"], input=svg.encode(), check=True) 74 75 76 for i in range(FRAMES): 77 svg = frame_svg(i) 78 # The same frames under both names: which one two-step plays depends on the theme's settings. 79 render(svg, out / f"throbber-{i + 1:04d}.png") 80 (out / f"animation-{i + 1:04d}.png").write_bytes((out / f"throbber-{i + 1:04d}.png").read_bytes()) 81 82 # The words, alone, from the logo's own lettering (its path after the flask), dimmed. 83 text = re.search(r'(<path fill="#ffffff" transform=.*?/>)', logo.read_text(), re.S).group(1) 84 word = (f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="985 330 3230 360">' 85 f'<g opacity=".6">{text.replace("#ffffff", GLASS)}</g></svg>') 86 render(word, out / "watermark.png", "-w", str(WORD_WIDTH)) 87 88 # The password prompt's pictures (for an encrypted disk), from Fedora's theme. 89 for png in src.glob("*.png"): 90 # Not its watermark.png, which is Fedora's logo and would replace ours. 91 if not png.name.startswith(("animation-", "throbber-")) and png.name != "watermark.png": 92 Image.open(png).save(out / png.name) 93 94 theme = (src / "spinner.plymouth").read_text() 95 theme = re.sub(r"^Name.*\n", "", theme, flags=re.M) 96 theme = theme.replace("[Plymouth Theme]\n", "[Plymouth Theme]\nName=Sector F Linux\n", 1) 97 theme = theme.replace("ImageDir=/usr/share/plymouth/themes//spinner", "ImageDir=/usr/share/plymouth/themes/sectorf") 98 theme = re.sub(r"^BackgroundStartColor=.*", f"BackgroundStartColor=0x{BACKGROUND:06X}", theme, flags=re.M) 99 theme = re.sub(r"^BackgroundEndColor=.*", f"BackgroundEndColor=0x{BACKGROUND:06X}", theme, flags=re.M) 100 # The flask in the middle of the screen, the words at the bottom. 101 theme = re.sub(r"^VerticalAlignment=.*", "VerticalAlignment=.5", theme, flags=re.M) 102 (out / "sectorf.plymouth").write_text(theme) 103 print(f"{out}: {len(list(out.iterdir()))} files")