#!/bin/bash

G=graphics
H=html

# Make a blank tile
pngtopnm $G/blank-bg-tile.png > blank.ppm 2>/dev/null

# Make a NESW path
pngtopnm $G/path-15.png > a.ppm
ppmcolormask '#ce3535' a.ppm > mask.pbm
pnmcomp -alpha=mask.pbm a.ppm blank.ppm path-15.ppm

# Make a NW path
pngtopnm $G/path-9.png > a.ppm
ppmcolormask '#ce3535' a.ppm > mask.pbm
pnmcomp -alpha=mask.pbm a.ppm blank.ppm path-9.ppm

# Make a NESW tunnel
pngtopnm $G/tunnel-15.png > a.ppm
ppmcolormask '#cc26c6' a.ppm > mask.pbm
pnmcomp -alpha=mask.pbm a.ppm path-15.ppm tunnel-15.ppm

# Make a NW tunnel
pngtopnm $G/tunnel-9.png > a.ppm
ppmcolormask '#cc26c6' a.ppm > mask.pbm
pnmcomp -alpha=mask.pbm a.ppm path-9.ppm tunnel-9.ppm

# Add a buffer
pngtopnm $G/buffer.png > a.ppm
ppmcolormask '#cc26c6' a.ppm > mask.pbm
pnmcomp -alpha=mask.pbm a.ppm tunnel-15.ppm b.ppm
pngtopnm $G/buffer-top.png > a.ppm
ppmcolormask '#cc26c6' a.ppm > mask.pbm
pnmcomp -alpha=mask.pbm a.ppm b.ppm buffer.ppm
pnmtopng buffer.ppm > $H/buffer.png

# Add a marble
pngtopnm $G/marble-5.png > a.ppm
ppmcolormask '#ee00ff' a.ppm > mask.pbm
pnmcomp -xoff=32 -yoff=32 -alpha=mask.pbm a.ppm buffer.ppm buffer2.ppm
pnmtopng buffer2.ppm > $H/buffer2.png

# Make a director
pngtopnm $G/director-0.png > a.ppm
ppmcolormask '#cc26c6' a.ppm > mask.pbm
pnmcomp -alpha=mask.pbm a.ppm tunnel-9.ppm b.ppm
pnmtopng b.ppm > $H/director.png

# Make a filter
pngtopnm $G/filter-7.png > a.ppm
ppmcolormask '#cc26c6' a.ppm > mask.pbm
pnmcomp -alpha=mask.pbm a.ppm tunnel-9.ppm b.ppm
pnmtopng b.ppm > $H/filter.png

# Make a painter
pngtopnm $G/painter-2.png > a.ppm
ppmcolormask '#cc26c6' a.ppm > mask.pbm
pnmcomp -alpha=mask.pbm a.ppm tunnel-9.ppm b.ppm
pnmtopng b.ppm > $H/painter.png

# Make a replicator
pngtopnm $G/replicator.png > a.ppm
ppmcolormask '#cc26c6' a.ppm > mask.pbm
pnmcomp -alpha=mask.pbm a.ppm tunnel-9.ppm b.ppm
pnmtopng b.ppm > $H/replicator.png

# Make a shredder
pngtopnm $G/shredder.png > a.ppm
ppmcolormask '#cc26c6' a.ppm > mask.pbm
pnmcomp -alpha=mask.pbm a.ppm tunnel-9.ppm b.ppm
pnmtopng b.ppm > $H/shredder.png

# Make a switch
pngtopnm $G/switch-03.png > a.ppm
ppmcolormask '#cc26c6' a.ppm > mask.pbm
pnmcomp -alpha=mask.pbm a.ppm tunnel-9.ppm b.ppm
pnmtopng b.ppm > $H/switch.png

# Make a teleporter
pngtopnm $G/teleporter-h.png > a.ppm
ppmcolormask '#cc26c6' a.ppm > mask.pbm
pnmcomp -alpha=mask.pbm a.ppm tunnel-9.ppm b.ppm
pnmtopng b.ppm > $H/teleporter.png

# Make the stoplights
pngtopnm $G/stoplight.png > a.ppm
ppmcolormask '#cc26c6' a.ppm > mask.pbm
pnmcomp -alpha=mask.pbm a.ppm blank.ppm stoplight-0.ppm
pngtopnm $G/marble-3.png > a.ppm
ppmcolormask '#ee00ff' a.ppm > mask.pbm
pnmcomp -xoff=32 -yoff=61 -alpha=mask.pbm a.ppm stoplight-0.ppm stoplight-1.ppm
pngtopnm $G/marble-4.png > a.ppm
ppmcolormask '#ee00ff' a.ppm > mask.pbm
pnmcomp -xoff=32 -yoff=32 -alpha=mask.pbm a.ppm stoplight-1.ppm stoplight-2.ppm
pngtopnm $G/marble-6.png > a.ppm
ppmcolormask '#ee00ff' a.ppm > mask.pbm
pnmcomp -xoff=32 -yoff=3 -alpha=mask.pbm a.ppm stoplight-2.ppm stoplight-3.ppm
pnmtopng stoplight-3.ppm > $H/stoplight.png
pnmtopng stoplight-2.ppm > $H/stoplight2.png

# Make the triggers
pngtopnm $G/trigger.png > a.ppm
ppmcolormask '#cc26c6' a.ppm > mask.pbm
pnmcomp -alpha=mask.pbm a.ppm blank.ppm trigger-0.ppm
pngtopnm $G/marble-6.png > a.ppm
ppmcolormask '#ee00ff' a.ppm > mask.pbm
pnmcomp -xoff=32 -yoff=4 -alpha=mask.pbm a.ppm trigger-0.ppm trigger-1.ppm
pngtopnm $G/marble-6.png > a.ppm
ppmcolormask '#ee00ff' a.ppm > mask.pbm
pnmcomp -xoff=60 -yoff=32 -alpha=mask.pbm a.ppm trigger-1.ppm trigger-2.ppm
pngtopnm $G/marble-3.png > a.ppm
ppmcolormask '#ee00ff' a.ppm > mask.pbm
pnmcomp -xoff=32 -yoff=60 -alpha=mask.pbm a.ppm trigger-2.ppm trigger-3.ppm
pngtopnm $G/marble-2.png > a.ppm
ppmcolormask '#ee00ff' a.ppm > mask.pbm
pnmcomp -xoff=4 -yoff=32 -alpha=mask.pbm a.ppm trigger-3.ppm trigger-4.ppm
pnmtopng trigger-4.ppm > $H/trigger.png
pnmtopng trigger-0.ppm > $H/trigger2.png

# Make a wheel
pngtopnm $G/wheel.png > a.ppm
ppmcolormask '#ea1515' a.ppm > mask.pbm
pnmcomp -alpha=mask.pbm a.ppm path-15.ppm wheel-0.ppm
pngtopnm $G/marble-4.png > a.ppm
ppmcolormask '#ee00ff' a.ppm > mask.pbm
pnmcomp -xoff=32 -yoff=4 -alpha=mask.pbm a.ppm wheel-0.ppm wheel-1.ppm
pnmtopng wheel-1.ppm > $H/wheel.png

# Delete all of the temporary files
rm *.ppm *.pbm
