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 java.awt.Color._
import java.awt._
 
import javax.swing._
 
object ColourPinstripeDisplay extends App {
  private def palette = Seq(black, red, green, blue, magenta, cyan, yellow, white)
 
  SwingUtilities.invokeLater(() =>
    new JFrame("Colour Pinstripe") {
 
      class ColourPinstripe_Display extends JPanel {
 
        override def paintComponent(g: Graphics): Unit = {
          val bands = 4
 
          super.paintComponent(g)
          for (b <- 1 to bands) {
            var colIndex = 0
            for (x <- 0 until getWidth by b) {
              g.setColor(ColourPinstripeDisplay.palette(colIndex % ColourPinstripeDisplay.palette.length))
              g.fillRect(x, (b - 1) * (getHeight / bands), x + b, b * (getHeight / bands))
              colIndex += 1
            }
          }
        }
 
        setPreferredSize(new Dimension(900, 600))
      }
 
      add(new ColourPinstripe_Display, BorderLayout.CENTER)
      pack()
      setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
      setLocationRelativeTo(null)
      setVisible(true)
    }
  )
 
}