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


// version 1.1.0
 
import java.awt.*
import java.awt.Color.*
import javax.swing.*
 
class ColourPinstripeDisplay : JPanel() {
    private companion object {
        val palette = arrayOf(black, red, green, blue, magenta, cyan, yellow, white)
    }
 
    private val bands = 4
 
    init {
        preferredSize = Dimension(900, 600)
    }
 
    override fun paintComponent(g: Graphics) {
        super.paintComponent(g)
        for (b in 1..bands) {
            var colIndex = 0
            val h = height / bands
            for (x in 0 until width step b) {
                g.color = palette[colIndex % palette.size]
                g.fillRect(x, (b - 1) * h, b, h)
                colIndex++
            }
        }
    }
}
 
fun main(args: Array<String>) {
    SwingUtilities.invokeLater {
        val f = JFrame()
        f.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
        f.title = "ColourPinstripeDisplay"
        f.add(ColourPinstripeDisplay(), BorderLayout.CENTER)
        f.pack()
        f.setLocationRelativeTo(null)
        f.isVisible = true
    }
}