Task

Display a series of vertical color bars across the width of the display.

The color bars should either use:

   the system palette,   or 
   the sequence of colors: 
   black
   red
   green
   blue
   magenta
   cyan
   yellow
   white


require('GD');
 
var colors = Hash.new(
              white   => [255, 255, 255],
              red     => [255, 0,   0],
              green   => [0,   255, 0],
              blue    => [0,   0,   255],
              magenta => [255, 0,   255],
              yellow  => [255, 255, 0],
              cyan    => [0,   255, 255],
              black   => [0,   0,   0],
             );
 
var barwidth = 160/8;
var image    = %s'GD::Image'.new(160, 100);
var start    = 0;
 
colors.values.each { |rgb|
    var paintcolor = image.colorAllocate(rgb...);
    image.filledRectangle(start * barwidth, 0, start*barwidth + barwidth - 1, 99, paintcolor);
    start++;
};
 
%f'colorbars.png'.open('>:raw').print(image.png);