The task is to create 1 pixel wide coloured vertical pinstripes with a sufficient number of pinstripes to span the entire width of the graphics display.



The pinstripes should either follow the system palette sequence,   or a sequence that includes:

black,   red,   green,   blue,   magenta,   cyan,   yellow,   and   white:

   after filling the top quarter, switch to a wider 2 pixel wide vertical pinstripe pattern,
   halfway down the display, switch to 3 pixel wide vertical pinstripe,
   finally to a 4 pixels wide vertical pinstripe for the last quarter of the display.


See also

   display black and white 
   print colour


require('GD')
 
func pinstripes(width = 1280, height = 720) {
 
    var im = %O<GD::Image>.new(width, height)
    var colors = [0, 255].variations_with_repetition(3)
 
    var paintcolors = colors.shuffle.map {|rgb|
        im.colorAllocate(rgb...)
    }
 
    var starty     = 0
    var barheight  = height//4
 
    for barwidth in (1..4) {
        for (
            var(startx = 0, colorindex = 0);
            startx + barwidth <= width;
            startx += barwidth
        ) {
            im.filledRectangle(startx, starty, startx+barwidth,
                starty + barheight - 1, paintcolors[colorindex++ % 8])
        }
        starty += barheight
    }
 
    return im
}
 
File('pinstripes.png').write(pinstripes().png, :raw)