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

Published on 12 May 2024 09:40 PM

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

Source code in the amazing programming language

#include 
#include 

#define  SPACE(_T_,_N_)   REPLICATE( " ", {_T_}DIV-INTO(_N_) )

DEF-MAIN(argv,argc)
   CLR-SCR
   GOSUB( Print Grey Scale )
END

RUTINES

DEF-FUN( Print Grey Scale )
  SET( nrcolors, 8 )
  SET( direction, 1 )
  MSET( quarter, color )
  LOCATE( 0, 0 )
  FOR( LT?( quarter, 4 ), ++quarter )
      SET( height, 0 )
      FOR( LT?( height, 5 ), ++height )
          SET( width, 0 )
          FOR( LT?( width, nrcolors ), ++width )
              LET( color := CEIL( MUL( width, DIV( 255, SUB(nrcolors,1) ) ) ) )
              WHEN( NOT( MOD( direction, 2 ) ) ){
                  LET( color := SUB( 255, color ) )
              }
               PRN( COLOR-RGBB( color, color, color) SPACE( 128, nrcolors ) )
          NEXT
          PRNL("\OFF")
      NEXT
      nrcolors*=2
      ++direction
  NEXT
RET

  

You may also check:How to resolve the algorithm Caesar cipher step by step in the SparForte programming language
You may also check:How to resolve the algorithm HTTP step by step in the GUISS programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the F# programming language
You may also check:How to resolve the algorithm 15 puzzle game step by step in the Action! programming language
You may also check:How to resolve the algorithm Temperature conversion step by step in the Insitux programming language