4cade/res/notes/transitions/apple.py
2019-11-06 15:02:09 -05:00

75 lines
2.9 KiB
Python
Executable File

#!/usr/bin/env python3
import PIL.Image # https://pillow.readthedocs.io/
import util
# apple72.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.
# The original image size was 1000x1187, so we want to retain the width (1000) but
# squash the image to height = 1187*0.87, which is 1032.
#
# $ gm convert apple72.png -resize "1000x1032!" 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.
#
# $ for w in `seq 1 500`; do \
# 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 500 frames. This
# number is duplicated below in the |frames| variable. Sorry.
#
# Now we have 500 (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
# - on every 3rd row
# - on even columns
# are included in the final data set.
#
# 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
# divided by 3.
#
# 6502 code will be responsible for plotting each of these coordinates
# in a 2x3 block. The bitmask usually includes 2 adjacent pixels;
# the code will also plot the same 2 adjacent pixels in the next two rows.
#
# Unfortunately, since bytes are 7 pixels across, some of the 2-pixel-wide
# blocks will cross a byte boundary. To simplify the 6502 code, these are
# simply listed as separate coordinate pairs, each with a bitmask that
# includes 1 pixel instead of 2.
frames = 500 # number of "thumbN.png" files
coords = []
for i in range(1, frames+1):
p = PIL.Image.open("apple/thumb%s.png" % i)
for x in range(0, 280, 2):
for y in range(0, 192, 3):
if p.getpixel((x,191-y))[0] != 255:
coords.append((x,y))
unique_coords = util.unique(coords)
unique_vals = util.vals_3bit(unique_coords)
with open("../../../src/fx/fx.hgr.apple.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.apple.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.apple.in.data.a", "w") as f:
for aval, bval in unique_vals:
f.write(" !byte %s,%s\n" % (aval, bval))