How to resolve the algorithm Greyscale bars/Display step by step in the FreeBASIC programming language
How to resolve the algorithm Greyscale bars/Display step by step in the FreeBASIC programming language
Table of Contents
Problem Statement
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.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Greyscale bars/Display step by step in the FreeBASIC programming language
Source code in the freebasic programming language
' version 01-09-2017
' compile with: fbc -s console
' or compile with: fbc -s gui
' hit any key to stop
Dim As UInteger d, blocks, blocksize, ps, col, h, w, x, y1, y2
ScreenInfo w, h
' create display size window, 8bit color (palette), no frame
ScreenRes w, h, 8,, 8
For x = 0 To 255 ' create grayscale palette for
Palette x, x, x, x ' the window we just opened
Next
h = h \ 4 : y2 = h -1
If w Mod 64 <> 0 Then w -= (w Mod 64)
blocks = 8 : blocksize = w \ 8
For ps = 1 To 4
For x = 0 To blocks -1
col = 255 * x \ (blocks -1) ' from black to white
If (ps And 1) = 0 Then col = 255 - col ' from white to black
Line (x * blocksize, y1) - (((x +1) * blocksize) -1, y2), col, bf
Next
y1 += h : y2 += h
blocks *= 2 : blocksize \= 2
Next
' empty keyboard buffer
While Inkey <> "" : Wend
Sleep
End
You may also check:How to resolve the algorithm Input loop step by step in the Phix programming language
You may also check:How to resolve the algorithm Generate lower case ASCII alphabet step by step in the Neko programming language
You may also check:How to resolve the algorithm Calculating the value of e step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Environment variables step by step in the Scala programming language
You may also check:How to resolve the algorithm Truncate a file step by step in the Liberty BASIC programming language