Cotton code
86 lines · 3.7 KB · PythonRaw
#!/usr/bin/env python3"""Put the film's painted materials into the Loom package's catalogue.    python3 scripts/import-film-materials.py [<layers directory>]The layers were painted with Codex (30 Oct 2026, after the VHS picture the ownerchose) and cut out of the paintings (keyed off green, a sleeve's wear splitinto a grain the poster is multiplied by and the rubbed card laid over it, theshadows made from the objects' silhouettes); the claret baize is a board'spainted baize dyed claret, still seamless. The directory holds them as theface lays them (CottonFaces' `Cotton/FilmVHSFace.swift`, the baize by`FaceGroundSurface`). No word, number or star is on any of them: the facedraws the sleeve's lines, the sticker's and the spine label's live; a posteris the record's own picture, drawn first; the specimens' invented one(`poster-ferry`, painted with the layers) goes among the fixtures.    vhs-sleeve-grain     the sleeve's card, a poster multiplied by it    vhs-sleeve-wear      its bumped, rubbed corners and edges    vhs-sleeve-shadow    its shadow    vhs-cassette         the cassette, its windows and reels    vhs-cassette-shadow  its shadow    vhs-sticker          the round cream sticker    vhs-spine            the spine label    films-baize          the claret baize, a seamless tile (JPEG)Each is at least 3x the most it is drawn at on a phone (a shadow, a blur, halfthat), declared 3x (2x on the Mac) as the card paper is; the face sets theframe it draws each at. Its measures, taken off the paintings, are the face'sknobs (`FilmVHSFaceKnobs`): a repainted layer owes new ones."""import jsonimport pathlibimport sysHERE = pathlib.Path(__file__).resolve().parentCATALOGUE = HERE.parent / 'apps/loom/Sources/CottonPaper/Media.xcassets'# The invented poster the specimens show, painted with the layers: a# fixture, as the specimens' photographs are (`FixturePictures`).PICTURES = ['poster-ferry']NAMES = [    'vhs-sleeve-grain', 'vhs-sleeve-wear', 'vhs-sleeve-shadow', 'vhs-cassette', 'vhs-cassette-shadow',    'vhs-sticker', 'vhs-spine', 'films-baize',]def imageset(name, extension):    folder = CATALOGUE / f'{name}.imageset'    folder.mkdir(exist_ok=True)    for old in folder.iterdir():        old.unlink()    contents = {        'images': [            {'filename': f'{name}.{extension}', 'idiom': 'universal', 'scale': '3x'},            {'filename': f'{name}.{extension}', 'idiom': 'mac', 'scale': '2x'},        ],        'info': {'author': 'xcode', 'version': 1},        'properties': {'preserves-vector-representation': False},    }    (folder / 'Contents.json').write_text(json.dumps(contents, indent=2) + '\n')    return folder / f'{name}.{extension}'def main(source):    source = pathlib.Path(source)    total = 0    for name in NAMES:        found = [source / f'{name}.{extension}' for extension in ('png', 'jpg') if (source / f'{name}.{extension}').exists()]        if len(found) != 1:            sys.exit(f'{source} holds {len(found)} pictures named {name}, not one')        picture = found[0]        target = imageset(name, picture.suffix[1:])        target.write_bytes(picture.read_bytes())        total += picture.stat().st_size        print(f'{picture.name} -> {name}')    for name in PICTURES:        picture = source / f'{name}.jpg'        if not picture.exists():            sys.exit(f'{source} holds no {name}.jpg')        (FIXTURES / picture.name).write_bytes(picture.read_bytes())        total += picture.stat().st_size        print(f'{picture.name} -> fixture {name}')    print(f'{total // 1024} KB in all')if __name__ == '__main__':    main(sys.argv[1] if len(sys.argv) > 1 else str(pathlib.Path.home() / 'lane-briefs/book-film-faces/layers'))