How to resolve the algorithm Colour pinstripe/Display step by step in the Scala programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Colour pinstripe/Display step by step in the Scala programming language
Table of Contents
Problem Statement
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:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Colour pinstripe/Display step by step in the Scala programming language
Source code in the scala programming language
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)
}
)
}
You may also check:How to resolve the algorithm Find palindromic numbers in both binary and ternary bases step by step in the F# programming language
You may also check:How to resolve the algorithm Loops/Foreach step by step in the Scheme programming language
You may also check:How to resolve the algorithm Sum multiples of 3 and 5 step by step in the Rust programming language
You may also check:How to resolve the algorithm Conway's Game of Life step by step in the Brainf*** programming language
You may also check:How to resolve the algorithm URL parser step by step in the V (Vlang) programming language