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


import gintro/[glib, gobject, gtk, gio, cairo]
 
const
  Width = 420
  Height = 420
 
const Colors = [[0.0, 0.0, 0.0], [255.0, 0.0, 0.0],
                [0.0, 255.0, 0.0], [0.0, 0.0, 255.0],
                [255.0, 0.0, 255.0], [0.0, 255.0, 255.0],
                [255.0, 255.0, 0.0], [255.0, 255.0, 255.0]]
 
#---------------------------------------------------------------------------------------------------
 
proc draw(area: DrawingArea; context: Context) =
  ## Draw the color bars.
 
  const lineHeight = Height div 4
 
  var y = 0.0
  for lineWidth in [1.0, 2.0, 3.0, 4.0]:
    context.setLineWidth(lineWidth)
    var x = 0.0
    var colorIndex = 0
    while x < Width:
      context.setSource(Colors[colorIndex])
      context.moveTo(x, y)
      context.lineTo(x, y + lineHeight)
      context.stroke()
      colorIndex = (colorIndex + 1) mod Colors.len
      x += lineWidth
    y += lineHeight
 
#---------------------------------------------------------------------------------------------------
 
proc onDraw(area: DrawingArea; context: Context; data: pointer): bool =
  ## Callback to draw/redraw the drawing area contents.
 
  area.draw(context)
  result = true
 
#---------------------------------------------------------------------------------------------------
 
proc activate(app: Application) =
  ## Activate the application.
 
  let window = app.newApplicationWindow()
  window.setSizeRequest(Width, Height)
  window.setTitle("Color pinstripe")
 
  # Create the drawing area.
  let area = newDrawingArea()
  window.add(area)
 
  # Connect the "draw" event to the callback to draw the color bars.
  discard area.connect("draw", ondraw, pointer(nil))
 
  window.showAll()
 
#———————————————————————————————————————————————————————————————————————————————————————————————————
 
let app = newApplication(Application, "Rosetta.ColorPinstripe")
discard app.connect("activate", activate)
discard app.run()