#! \usr\bin\perl.exe
################################################################################
################################################################################
#
# Spectrum fill
#
# by Andrew Hardwick, http://duramecho.com
#
# Released under GNU Public Licence.
#
################################################################################
################################################################################
# Version 1, 2006/4/29
# Created to make wallless greyscale 16x16 Cretan maze favicon but looked naff.
# Version 2, 2006/4/29
# Added (black) walls.
# Version 3, 2006/4/29
# Added option of simple white path instead of greyscale.
# Version 4, 2006/4/29
# Added option of spectrum path.
# Version 5, 2006/4/30
# Added lots more documentation as program changed from disposable to to keep.
# Added option of different path & wall widths.
# Version 6, 2006/4/30
# Split large main routine up into 3 subroutines and generalised some parts.
# Version 7, 2006/5/1
# Added option of output of a series of images with shifted colours.
# Version 8, 2006/6/22
# Changed hardcoded labyrinth template to one read from an image file.
# Version 9, 2006/6/23
# Removed 2 stages that cancel out now that a template image is used.
# Version 10, 2006/6/23
# Replaced remaining sloppy global variable use with parameter passing.
# Version 11, 2006/7/10
# Corrected bug that corrupted reading of non-square templates.
# Version 12, 2006/7/10
# Corrected bug that corrupted output from even width or height templates.
# Version 13, 2006/7/16
# Added option of cycling through spectrum multiple times & chosing start hue.
# Version 14, 2006/7/16
# Made background & Monochrome (formerly 'White') path colours settable.
# Version 15, 2006/7/20
# Added support for non-unicursal mazes (equivalent to flood fill).
# Renamed from 'LabyrinthColourer.pl' to 'SpectrumFill.pl'
# Improved path walking function not overwrite template array.
# Version 16, 2006/7/20
# Added stop cells to block flood filling in unwanted directions in circuits.
# Version 17, 2006/7/20
# Added support for multiple start cells.
# Version 18, 2006/7/23
# Fixed PGM reading bug (it did not allow surround whitespace on text lines).
# Version 19, 2006/7/23
# Added optional progress logging ("verbose mode").
# Version 20, 2006/8/9
# Documentation typo corrections.
# Version 21, 2006/8/16
# Renamed setting 'StartHue' to 'StartOffset' as it is also used for greyscale.
# Version 22, 2007/9/15
# Tidied by moving maze output from main routine to subroutines.
# Tidied by moving colour calculation to a separate function.
# Changed internal RGB colour format from PPM space separated to generic array.
# Renamed 'ColourCycles' to 'NumberOfCycles' as works for monochrome too.
# Removed unnecessary function passing of fixed global parameters.
# Added 'OutputType' setting instead of guessing from 'NumberOfCycles'.
# Version 23, 2007/9/16
# Changed internal coordinate system from y=0 at top to y=0 at bottom.
# Added Javascript/HTML animation output ability.
# Version 24, 2007/9/19
# Added Id caching to Javascript as lousy IE's getElementById is very slow.
# Version 25, 2007/10/8
# Changed HTML animation page output to have background colour = maze wall.
# Stopped path following routine wandering off template when unwalled.
################################################################################
# This program colours in a maze image with spectrum colour progression.
# Additional features include alternative colouring schemes, image expanding
# and expanding the path to a different width to the wall.
################################################################################
# How to use:
# Set the maze shape & other parameters in the settings. Run it.
# Template format:
# An image in ASCII PGM format with 256 grey levels (0 to 255).
# Each pixel is a cell. Grey level of the cell determines what it is.
# 0 = wall cell.
# 128 = start cell (fill starts in and propogates out of this type of cell).
# 192 = stop cell (fill propogates into but not out of this type of cell).
# 255 = path cell (fill propogates into & out of this type of cell).
# The image must contain at least one start cell.
# Perferably the path should be 1 pixel wide to get the cleanest colour fill.
# If it is desired to resize the path to a different width from the wall
# then all pixels with both x & y even must be walls or be surrounded on
# all four sides by path cells. (This is because whole rows & columns are
# resized together).
# Set OutputType to the maze output type required. Options are:
# Static = one static PPM image.
# Series = an animation as a series of static PPM images that can be combined.
# Javascript = an animation as a Javascript animated HTML page.
# Set ColouringScheme to the colour scheme required. Options are:
# Monochrome = path of single colour.
# Greyscale = path graduates from black to white.
# Spectrum = path graduates from red up through the spectrum back to red.
# Set WallColour to the colour for the walls. Colours are represented
# as ASCII strings of whitespace separated decimal RGB values eaching ranging
# from 0 to 255.
# Set ColourPath to the colour for the Monochrome path. Colours are represented
# as ASCII strings of whitespace separated decimal RGB values eaching ranging
# from 0 to 255. Irrevelant for Spectrum or Greyscale path colouring.
# Set StartHue to where to start in a spectrum (or luminousity if the colouring
# scheme is Greyscale). Range is 0 to 1. Irrevelant for Monochrome
# path colouring.
# Set NumberOfCycles to the number of times it to cycle through the spectrum
# (or colouring greyscale) between the begining & end of the path. Irrevelant
# for Monochrome path colouring.
# Set WidthPath to the width of the path in pixels. Integer of 1 or more.
# Set WidthWall to the width of the walls in pixels. Integer of 1 or more.
# Set SeriesLength to the number larger of steps in an animation series
# (which is the number of images output for 'Series' animation). Ignored
# if the output type is 'Static'.
# (One can combine the 'Series' animation frames from using Image Magick by
# "convert -delay -loop 0
#