okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221apps/host: the owner's UI and the Node App Host0b3299a01

main
2.5 KiB39 linesraw
1"""Create the original Fieldnotes motion examples (Pillow + imageio-ffmpeg)."""
2from pathlib import Path
3from PIL import Image, ImageDraw, ImageFont
4import math, subprocess
5import imageio_ffmpeg
6OUT=Path(__file__).resolve().parents[2]/'public/examples'
7W,H=768,432
8font=ImageFont.truetype('/System/Library/Fonts/Supplemental/Arial.ttf',15)
9small=ImageFont.truetype('/System/Library/Fonts/Supplemental/Arial.ttf',12)
10serif=ImageFont.truetype('/System/Library/Fonts/Supplemental/Georgia.ttf',38)
11def frame(t):
12    im=Image.new('RGB',(W,H),'#f5f3eb');d=ImageDraw.Draw(im)
13    d.text((40,30),'FIELDNOTES',font=font,fill='#224d3d')
14    d.text((40,112),'A little room\nfor your next idea.',font=serif,fill='#243e34',spacing=5)
15    d.text((42,230),'Capture. Connect. Create.',font=font,fill='#647368')
16    d.rounded_rectangle((42,285,202,324),20,fill='#224d3d');d.text((63,296),'Make a fresh start',font=small,fill='#ffffff')
17    for i in range(3):
18        y=95+i*36+int(math.sin(t*2*math.pi+i*.55)*10)
19        x=444+i*16
20        d.rounded_rectangle((x,y,x+196,y+175),18,fill=['#d5dfcf','#b9cdb9','#fffcf4'][i],outline='#b2c4b3',width=1)
21        if i==2:
22            d.ellipse((x+24,y+25,x+36,y+37),fill='#408260')
23            d.text((x+24,y+55),'An idea worth keeping',font=small,fill='#243e34')
24            for j,length in enumerate([135,113,128]):d.rounded_rectangle((x+24,y+88+j*17,x+length,y+93+j*17),2,fill='#d5dfcf')
25    d.line((40,375,728,375),fill='#d5dfcf',width=1)
26    d.text((40,390),'A SMALL SPACE FOR WHAT COMES NEXT',font=small,fill='#647368')
27    for i in range(3):
28        d.ellipse((672+i*18,392,678+i*18,398),fill='#224d3d' if int(t*3)%3==i else '#c4d1bd')
29    return im
30frames=[frame(i/72) for i in range(72)]
31frames[0].save(OUT/'fieldnotes-motion-poster.png')
32writer=subprocess.Popen([imageio_ffmpeg.get_ffmpeg_exe(),'-y','-f','rawvideo','-vcodec','rawvideo','-s',f'{W}x{H}','-pix_fmt','rgb24','-r','18','-i','-','-an','-c:v','libx264','-pix_fmt','yuv420p','-movflags','+faststart',str(OUT/'fieldnotes-motion.mp4')],stdin=subprocess.PIPE,stderr=subprocess.DEVNULL)
33for im in frames:writer.stdin.write(im.tobytes())
34writer.stdin.close()
35if writer.wait():raise RuntimeError('Video encoding failed')
36# A 4-second, 9 fps looping GIF with a separate still for pause/reduced motion.
37gif_frames=[im.resize((576,324)).quantize(colors=96) for im in frames[::2]]
38gif_frames[0].save(OUT/'fieldnotes-ideas.gif',save_all=True,append_images=gif_frames[1:],duration=111,loop=0,optimize=False,disposal=2)
39print('Created MP4, animated GIF and still poster.')