#!/usr/bin/env python3 """Redraws the text of the Flutter images that were typeset in the freeware font "Mechfire", with Press Start 2P (SIL OFL 1.1). python3 fl_art.py Everything that is not lettering is kept pixel for pixel.""" import sys from PIL import Image, ImageDraw, ImageFont src, ttf, out = sys.argv[1:4] WHITE, BLACK, KEY = (255, 255, 255), (0, 0, 0), (255, 0, 255) def font(size): return ImageFont.truetype(ttf, size) def blank(im, box, color): ImageDraw.Draw(im).rectangle(box, fill=color) def text(im, x, top, s, size, color=WHITE, anchor='l'): """Draws s with the top of the capital letters at `top`; x is the left edge, the centre (anchor c) or the right edge (r).""" f = font(size); d = ImageDraw.Draw(im); d.fontmode = '1' w = f.getlength(s) x0 = x if anchor == 'l' else x - w / 2 if anchor == 'c' else x - w cap = round(size * 7 / 8) d.text((round(x0), top + cap), s, font=f, fill=color, anchor='ls') def load(n): return Image.open(f'{src}/{n}.png').convert('RGB') def save(im, n): im.save(f'{out}/{n}.png') # title (800x600, black): only the two lines of lettering im = load('title'); blank(im, (150, 250, 650, 345), BLACK) text(im, 392, 257, 'FLUTTER', 48, anchor='c'); text(im, 384, 321, 'CLICK TO START', 16, anchor='c'); save(im, 'title') # victory (800x600, black): lettering above y=270, the picture of the technician below im = load('victory'); blank(im, (40, 130, 760, 268), BLACK) text(im, 405, 136, 'CONGRATULATIONS!', 32, anchor='c'); text(im, 396, 176, 'THANKS FOR PLAYING', 16, anchor='c') text(im, 403, 249, '"FLUTTER" A SOLO PYWEEK29 ENTRY BY MIT-MIT', 16, anchor='c'); save(im, 'victory') def story(n, band, x, tops, lines): im = load(n); blank(im, (0, band[0], 800, band[1]), BLACK) for top, s in zip(tops, lines): text(im, x, top, s, 16) save(im, n) story('cutscene1', (60, 325), 99, [65, 89, 113, 160, 184, 208, 232, 256, 280, 304], ['METAMORPHOSIS. THE WONDER OF NATURE. A', 'CREATURE ALTERS ITS OWN BODY TO ADAPT', 'TO ITS NEW EXISTENCE, A NEW STAGE OF LIFE.', 'WE SOUGHT TO HARNESS THAT POWER, TO', 'USE OUR MODERN MEDICAL SCIENCE AND', 'HUMAN INGENUITY TO EXTRACT FROM NATURE', 'THAT ESSENCE FOR OUR OWN NEEDS. IT WAS', 'MEANT TO BE A GREAT LEAP FOR HUMANKIND,', 'THE NEXT BIG STEP IN OUR EVOLUTION. WHAT', 'FOOLS WE WERE.']) story('cutscene2', (88, 282), 38, [93, 117, 141, 165, 189, 213, 237, 261], ['AT LEPIDOPTECH RESEARCH LABS WE WORKED FOR', 'YEARS: COUNTLESS EXPERIMENTS, GENETIC', 'ENGINEERING OF CATERPILLARS AND BUTTERFLY: WE', 'BRED SUPER INSECTS, AND EXTRACTED FROM THEM', 'THE CHEMICAL COMPONENTS WE NEEDED. WE', 'NICKNAMED THE DRUG WE WOULD DEVELOP "THE', 'BUTTERFLY EFFECT". WE WERE ON THE EVE OF', 'PERFECTING THE FORMULA.']) story('cutscene3', (255, 305), 119, [260, 284], ['I STILL REMEMBER THE DAY IT ALL WENT', 'HORRIBLY WRONG.']) def tag(n, size, lines, tops, x=None, anchor='l'): im = Image.open(f'{src}/{n}.png').convert('RGB'); blank(im, (0, 0, im.width, im.height), KEY) for s, top in zip(lines, tops): text(im, x if x is not None else 0, top, s, size, anchor=anchor) save(im, n) tag('gameover', 40, ['GAME OVER'], [8], x=200, anchor='c') tag('continue', 24, ['CONTINUE?'], [4], x=108, anchor='c') tag('asdwmove', 14, ['ASDW TO', 'MOVE'], [4, 21], x=53, anchor='c') tag('clickshoot', 13, ['CLICK TO', 'SHOOT'], [4, 21], x=54, anchor='c') tag('healthup', 11, ['+20 HEALTH'], [5], x=55, anchor='c') tag('healthup2', 11, ['HEALTH'], [5], x=108, anchor='r') tag('weaponup', 10, ['+ WEAPON UP'], [4], x=56, anchor='c') tag('boss', 12, ['BOSS'], [3], x=26, anchor='c') # door numbers on four wall pictures: grey (127) digits on the door face (204) for n, digit in (('wall001', '5'), ('wall002', '4'), ('wall004', '2'), ('wall005', '5')): im = load(n); px = im.load() pts = [(x, y) for y in range(118, 152) for x in range(668, 694) if px[x, y] == (127, 127, 127)] x0, x1 = min(p[0] for p in pts), max(p[0] for p in pts); y0, y1 = min(p[1] for p in pts), max(p[1] for p in pts) blank(im, (x0 - 1, y0 - 1, x1 + 1, y1 + 1), (204, 204, 204)) f = font(24); d = ImageDraw.Draw(im); d.fontmode = '1' d.text(((x0 + x1) // 2 - 12 + 0, y1 + 1), digit, font=f, fill=(127, 127, 127), anchor='ls') save(im, n)