How to resolve the algorithm Colour pinstripe/Display step by step in the PureBasic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Colour pinstripe/Display step by step in the PureBasic 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 PureBasic programming language
Source code in the purebasic programming language
;Create a Pinstripe image with a pattern of vertical stripe colors
Procedure PinstripeDisplay(width, height, Array psColors(1), numColors = 0)
Protected x, imgID, psHeight = height / 4, psWidth = 1, psTop, horzBand, curColor
If numColors < 1: numColors = ArraySize(psColors()) + 1: EndIf
imgID = CreateImage(#PB_Any, width, height)
If imgID
StartDrawing(ImageOutput(imgID))
Repeat
x = 0
curColor = 0
Repeat
Box(x, psTop, psWidth, psHeight, psColors(curColor))
curColor = (curColor + 1) % numColors
x + psWidth
Until x >= width
psWidth + 1
horzBand + 1
psTop = horzBand * height / 4 ;move to the top of next horizontal band of image
Until psTop >= height
StopDrawing()
EndIf
ProcedureReturn imgID
EndProcedure
;Open a window and display the pinstripe
If OpenWindow(0, 0, 0, 1, 1,"PureBasic Pinstripe", #PB_Window_Maximize | #PB_Window_SystemMenu)
Dim psColors(7)
psColors(0) = RGB($00, $00, $00) ;black
psColors(1) = RGB($FF, $00, $00) ;red
psColors(2) = RGB($00, $FF, $00) ;green
psColors(3) = RGB($00, $00, $FF) ;blue
psColors(4) = RGB($FF, $00, $FF) ;magenta
psColors(5) = RGB($00, $FF, $FF) ;cyan
psColors(6) = RGB($FF, $FF, $00) ;yellow
psColors(7) = RGB($FF, $FF, $FF) ;white
PicID = PinstripeDisplay(WindowWidth(0), WindowHeight(0), psColors())
ImageGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), ImageID(PicID))
While WaitWindowEvent() <> #PB_Event_CloseWindow
Wend
EndIf
You may also check:How to resolve the algorithm Strip comments from a string step by step in the Groovy programming language
You may also check:How to resolve the algorithm Luhn test of credit card numbers step by step in the SenseTalk programming language
You may also check:How to resolve the algorithm Langton's ant step by step in the Python programming language
You may also check:How to resolve the algorithm Partial function application step by step in the C++ programming language
You may also check:How to resolve the algorithm Factorial step by step in the ChucK programming language