4cade/res/notes/transitions/maple.py

77 lines
3.0 KiB
Python
Raw Normal View History

2019-11-08 19:05:58 +00:00
#!/usr/bin/env python3
import PIL.Image # https://pillow.readthedocs.io/
import util
# maple.png is the source image. The source image MUST have a white background,
# but other colors and pixel depth are irrelevant. This one is black & white.
# Due to the Apple II pixel aspect ratio, we do a 1-time aspect-ratio-losing resize
# to squash the image to 87% height.
#
# $ gm convert maple.png -resize "100%x87%!" squash.png
# (Depending on your shell, you may need to escape the exclamation point. Grr.)
#
# Now we can create individual images for each "frame" of the animation, by
# resizing the (squashed) source image and putting it in a 280x192 frame.
#
2022-08-31 20:17:21 +00:00
# $ for w in $(seq 1 1500); do \
2019-11-08 19:05:58 +00:00
# gm convert -size 280x192 squash.png \
# -resize "$w" \
# -background white \
# -compose Copy \
# -gravity center \
# -extent 280x192 thumb"$w".png; \
# done
#
# Depending on the source image, you may need more or fewer than 1500 frames. This
# number is duplicated below in the |frames| variable. Sorry.
#
# Now we have 1500 (or so) PNG images of what the HGR screen should look like at
# each stage. Despite each frame being 280x192 and in the correct aspect ratio,
# only coordinates
2022-08-31 20:17:21 +00:00
# - in the left half of the screen, AND
# - on even rows, AND
2019-11-08 19:05:58 +00:00
# - on even columns
2022-08-31 20:17:21 +00:00
# are included. It is assumed that the image is symmetrical across
# the left and half sides of the screen (along an axis at X=140).
2019-11-08 19:05:58 +00:00
#
# X coordinates are converted to byte+bitmask (but see notes below).
# Y coordinates are flipped (so 0,0 ends up on the bottom left) then
2022-08-31 20:17:21 +00:00
# incremented by 1 so that 0 can terminate the loop,
2019-11-08 19:05:58 +00:00
#
# 6502 code will be responsible for plotting each of these coordinates
2022-08-31 20:17:21 +00:00
# in a 2x2 block. The bitmask usually includes 2 adjacent pixels;
# the code will also plot the same 2 adjacent pixels in the adjacent row,
# AND mirror both of those plots in the right half of the screen.
2019-11-08 19:05:58 +00:00
#
2022-08-31 20:17:21 +00:00
# Unfortunately, since bytes are 7 bits across, some blocks will cross a
# byte boundary. To simplify the 6502 code, those are simply listed as
# separate coordinate pairs, each with a bitmask that includes 1 pixel
# instead of 2.
2019-11-08 19:05:58 +00:00
frames = 1500 # number of "thumbN.png" files
coords = []
for i in range(5, frames, 5):
p = PIL.Image.open("maple/thumb%s.png" % i)
for x in range(0, 280//2, 2):
for y in range(0, 192, 2):
2022-08-31 20:17:21 +00:00
if p.getpixel((x,191-y))[0] != (255,255,255,255):
2019-11-08 19:05:58 +00:00
coords.append((x,y))
unique_coords = util.unique(coords)
unique_vals = util.vals_2bit(unique_coords)
with open("../../../src/fx/fx.hgr.maple.data.a", "w") as f:
for aval, bval in unique_vals:
f.write(" !byte %s,%s\n" % (aval, bval))
ripple_vals = util.ripple(unique_vals)
with open("../../../src/fx/fx.hgr.maple.ripple.data.a", "w") as f:
for aval, bval in ripple_vals:
f.write(" !byte %s,%s\n" % (aval, bval))
unique_vals.reverse()
with open("../../../src/fx/fx.hgr.maple.in.data.a", "w") as f:
for aval, bval in unique_vals:
f.write(" !byte %s,%s\n" % (aval, bval))