The task is to display a series of vertical greyscale bars (contrast bars) with a sufficient number of bars to span the entire width of the display.

For the top quarter of the display, the left hand bar should be black, and we then incrementally step through six shades of grey until we have a white bar on the right hand side of the display. (This gives a total of 8 bars)

For the second quarter down, we start with white and step down through 14 shades of gray, getting darker until we have black on the right hand side of the display. (This gives a total of 16 bars).

Halfway down the display, we start with black, and produce 32 bars, ending in white, and for the last quarter, we start with white and step through 62 shades of grey, before finally arriving at black in the bottom right hand corner, producing a total of 64 bars for the bottom quarter.

EnableExplicit
 
Macro Check(Function)
  If Not Function : End : EndIf
EndMacro
 
Check(InitKeyboard())    ; Cannot initialize keyboard
Check(InitSprite())      ; Cannot initialize sprite/screen library
Check(ExamineDesktops()) ; Cannot retrieve informations about desktops
 
Define.i iHeight, iWidth, iDepth
iHeight = DesktopHeight(0)
iWidth  = DesktopWidth(0)
iDepth  = DesktopDepth(0)
 
If OpenScreen(iWidth, iHeight, iDepth, "Press ENTER to exit")
  Define.i bMode.b, iLines, fLine.f, iRow, iSpans, fSpan.f,
           fColor.f, iTop, iWide, iHigh, iCol, iShade
  If StartDrawing(ScreenOutput())
 
    bMode  = #True ; Pow = #True; Add = #False
    iLines = 4     ; Number of Lines
 
    If   iLines < 1  : iLines = 1  : EndIf ; Pow/Add-Min
    If bMode
      If iLines > 6  : iLines = 6  : EndIf ; Pow-Max
    Else
      If iLines > 32 : iLines = 32 : EndIf ; Add-Max
    EndIf
    fLine  = iHeight / iLines
    iLines - 1
 
    For iRow = 0 To iLines
      If bMode
        iSpans = Pow(2, iRow + 3) - 1 ; Pow: 8, 16, 32, 64, 128, 256
      Else
        iSpans = (iRow + 1) * 8 - 1   ; Add: 8, 16, 24, 32, 40, 48, ...
      EndIf
      fSpan  = iWidth / (iSpans + 1)
      fColor = 255 / iSpans
      iTop   = Round(iRow * fLine, #PB_Round_Up)
      iWide  = Round(fSpan, #PB_Round_Up)
      iHigh  = Round(fLine, #PB_Round_Up)
      For iCol = 0 To iSpans
        iShade = Round(fColor * iCol, #PB_Round_Nearest)
        If iRow % 2 <> 0 : iShade = 255 - iShade : EndIf ; Alternation
        Box(Round(iCol * fSpan, #PB_Round_Up), iTop, iWide, iHigh,
            RGB(iShade, iShade, iShade))
      Next
    Next
 
    StopDrawing()
    FlipBuffers()
 
    Repeat
      Delay(30)
      ExamineKeyboard()
    Until KeyboardPushed(#PB_Key_Escape) Or
          KeyboardPushed(#PB_Key_Return)
  EndIf
  CloseScreen()
EndIf
End