#!/usr/bin/ruby

#
## https://rosettacode.org/wiki/Colour_bars/Display
#

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);
