Glimmr Drawing Commands

version 2/101030 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next



  • Chapter: Complex commands: Image-maps

    An image-map is similar to a bitmap in that the author defines a regular grid for graphical display. However, rather than each cell of the grid displaying a rectangular area of color, it draws an image from a PNG or JPEG file. This could be used for drawing tile-based maps (as in RPG games), sliding-block puzzles, graphical user interfaces, or a number of other things.

    Image-maps can be specified in one of two ways:

        direct image-map: Takes a list of lists of figure names
        tileset image-map: Takes a list of lists of numbers keyed to a separate tileset listing

    The main advantage of the direct image-map is that it is at least notionally faster, since there is no need for an intervening lookup to a tileset. In practice, the lookup is very fast and (at least on most machines) there isn't much difference.

    One advantage of the tileset approach is human-readability. With short integers and some formatting, the list itself can be understand relatively easily as a kind of low-resolution "image." The following, for example, might represent a long hallway with a door on the left:

        {
            { 11, 11, 11, 11, 11, 11, 11 },
            { 05, 00, 00, 00, 00, 00, 00 },
            { 05, 00, 00, 00, 00, 00, 00 },
            { 11, 11, 11, 11, 11, 11, 11 }
        }

    In contrast, the direct version might look like this--not nearly as readable:

        {
            { Figure of Wall, Figure of Wall, Figure of Wall, Figure of Wall, Figure of Wall, Figure of Wall, Figure of Wall },
            { Figure of Door, Figure of Null, Figure of Null, Figure of Null, Figure of Null, Figure of Null, Figure of Null },
            { Figure of Door, Figure of Null, Figure of Null, Figure of Null, Figure of Null, Figure of Null, Figure of Null },
            { Figure of Wall, Figure of Wall, Figure of Wall, Figure of Wall, Figure of Wall, Figure of Wall, Figure of Wall},
         }

    Another advantage is that we can swap out the tileset to change the look of the image-map without actually changing the image-set data. For example, if we want have a map made up of separate tiles and we want to illustrate a change from day to night, we just change the tileset we're using from the day set to the night set. If the numbers used in the two tilesets are keyed to one another in the same way, the resulting image-set will display nicely.

    Remember that the tile- or figure-array is a list of lists. We supply the standard set of list braces, and then we supply one list for each row within those braces, each row's list also having its own braces, e.g. here's a simple tile-array with 4 rows:

        { {1, 0, 1}, {0, 1, 0}, {1, 0, 1}, {0, 1, 0} }.

    (The Glimmr Automap extension uses tilesets to render the automapping data produced by Mark Tilford's Automap extension.)