31 lines
1.4 KiB
Python
31 lines
1.4 KiB
Python
"""Render the original terminal ident as a texture on the modeled CRT screen."""
|
|
from pathlib import Path
|
|
import struct
|
|
from PIL import Image
|
|
|
|
ROOT=Path(__file__).resolve().parents[2]
|
|
|
|
|
|
def main():
|
|
data=(ROOT/'assets/animations/intro/eblan-sequence.bin').read_bytes()
|
|
_,cols,rows,count,loop,ms,glyphs,size,version=struct.unpack_from('<4s8I',data)
|
|
payload=data[36:];colors=struct.unpack_from('<256I',payload)
|
|
masks=payload[1024:5120]
|
|
out=ROOT/'assets/cinematics/blender/screen';out.mkdir(parents=True,exist_ok=True)
|
|
for frame in range(1,193):
|
|
source=min(count-1,max(0,(frame-12)*count//116))
|
|
cells=struct.unpack_from('<'+str(cols*rows)+'H',payload,5120+source*cols*rows*2)
|
|
im=Image.new('RGB',(576,432),(1,3,3));px=im.load()
|
|
for index,cell in enumerate(cells):
|
|
if index//cols in [17,19,20] or index%cols>=64:continue
|
|
glyph=cell&255;color=colors[cell>>8];ink=((color>>16)&255,(color>>8)&255,color&255)
|
|
cx=index%cols*8+32;cy=index//cols*16+48
|
|
for y in range(16):
|
|
bits=masks[glyph*16+y]
|
|
for x in range(8):
|
|
if bits&(128>>x):px[cx+x,cy+y]=tuple(round(c*(.82 if y%2 else 1)) for c in ink)
|
|
im.save(out/f'screen_{frame:04}.png')
|
|
print('Prepared 192 CRT frames from the original Eblan Games terminal animation')
|
|
|
|
|
|
if __name__=='__main__':main()
|