How to resolve the algorithm Greyscale bars/Display step by step in the zkl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Greyscale bars/Display step by step in the zkl 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 zkl programming language

Source code in the zkl programming language

img:=PPM(640,480);
foreach q in ([0..3]){		//quarter of screen
   n:=(8).shiftLeft(q);         //number of bars
   w:=640/n;			//width of bar (pixels)
   foreach b in ([0..n-1]){	//for each bar...
      c:=(255.0/(n-1).toFloat() * (if(q.isOdd) n-1-b else b)).toInt();
      c:=c.shiftLeft(16) + c.shiftLeft(8) + c;   //RGB color = gray
      foreach y in ([(3-q)*120 .. (3-q+1)*120-1]){  // flip image vertically
         img.line(w*b,y, w*(b+1)-1,y, c);
      }
   }
}
img.write(File("foo.ppm","wb"));

  

You may also check:How to resolve the algorithm Comments step by step in the E programming language
You may also check:How to resolve the algorithm Sorting algorithms/Counting sort step by step in the Ring programming language
You may also check:How to resolve the algorithm Gauss-Jordan matrix inversion step by step in the J programming language
You may also check:How to resolve the algorithm Delegates step by step in the Go programming language
You may also check:How to resolve the algorithm 100 doors step by step in the BQN programming language