Glimmr Drawing Commands

version 2/101030 by Erik Temple

  • Home page
  • Beginning
  • Previous
  • Next



  • Section: Colors

    Colors in GDC are specified as numbers. However, we actually have a lot of freedom in how we actually specify those numbers. The (computationally) fastest way to specify a color is as an unadorned decimal representation of the hex color code that would be used in I6 glulx. This is inconvenient, since we have to convert a hex code to decimal (using a hex calculator or online conversion utility), and very often we will have first had to convert an RGB color to hex.

        16777215 (decimal) = $FFFFFF (hex) = white = RGB (255, 255, 255)

    GDC in fact allows us to provide color values in all of these forms, and more. (It does this by running an in-line calculation on our input to arrive at that decimal code.) Here are the color specifications we can use (all of these set the color to white):

        Hexadecimal (the "hex" identifier is required):
        hex FFFFFF
        hex $FFFFFF
        hex #FFFFFF
        hex 0xFFFFFF

        Color name (must be previously defined; see below):
        color g-White

        RGB:
        R 255 G 255 B 255
        r 255 g 255 b 255
        r = 255 g = 255 b = 255
        
        RGB percentages (rather coarse):
        R% 100 G% 100 B% 100
        r% 100 g% 100 b% 100
        r% = 100 g% = 100 b% = 100

        RGB percentages using fixed point numbers (4 decimal places REQUIRED):
        R% 100.0000 G% 100.0000 B% 100.0000
        r% 100.0000 g% 100.0000 b% 100.0000
        r% = 100.0000 g% = 100.0000 b% = 100.0000

    Any of these expressions can be surrounded by parentheses to make them more readable. Here are some examples of actual use:

        draw a line (color g-Lavender) in the graphics-window from {100, 100} to {200, 200} with 2 pixel line-weight.
        change the current foreground-color to hex FF0000.
        draw a rectangle (r = 20 g = 40 b = 150) in the graphics-window from 120 by 30 to 180 by 40.
        display a monochrome bitmap (r% = 100 g% = 50 b% = 20) in the graphics-window at {10, 25} using 12 wide data from Player Avatar with dot size 2 px and background (r% = 0 g% = 0 b% = 0).

    Color names are of the "glulx color value" kind of value. To use color names, we must first define them by extending the Table of Common Color Values provided in the (built-in) Glulx Text Effects extension, like so:

        Table of Common Color Values (continued)
      glulx color value  assigned number  
      g-MyNewColor  4467887  

    A list of 140 color names is provided by the extension HTML Color Names for Glulx Text Effects.

    The fixed point RGB percentages are made possible by Michael Callaghan's Fixed Point Maths extension (see that extension for details). Fixed point numbers must be specified to 4 decimal places or unexpected results may emerge.