How to resolve the algorithm Colour bars/Display step by step in the Icon and Unicon programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Colour bars/Display step by step in the Icon and Unicon programming language

Table of Contents

Problem Statement

Display a series of vertical color bars across the width of the display. The color bars should either use:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Colour bars/Display step by step in the Icon and Unicon programming language

Source code in the icon programming language

link graphics,printf
                     
procedure main()  # generalized colour bars 
   DrawTestCard(Simple_TestCard())
   WDone()
end   
   
procedure DrawTestCard(TC)
   size := sprintf("size=%d,%d",TC.width,TC.height)
   &window := TC.window := open(TC.id,"g","bg=black",size) | 
               stop("Unable to open window")   

   every R := TC.bands[r := 1 to *TC.bands -1] do
      every C := R.bars[c := 1 to *R.bars - 1] do {
	     Fg(R.bars[c].colour)
	     FillRectangle( C.left, R.top,
		            R.bars[c+1].left-C.left, TC.bands[r+1].top-R.top )
	     }
   return TC
end

record testcard(window,id,width,height,bands)
record band(top,bars)    
record bar(left,colour)   

procedure Simple_TestCard()  #: return structure simple testcard
   return testcard(,"Simple Test Card",width := 800,height := 600, 
		   [   band( 1, [ bar(  1, "black"),
				  bar(114, "red"),
				  bar(228, "green"),
				  bar(342, "blue"),
                                  bar(456, "magenta"),
                                  bar(570, "cyan"),
                                  bar(684, "yellow"),
                                  bar(width) ] ),
		       band(height) ])
end


procedure SMPTE_TestCard()  #: return structure with 480i(ish) testcard
   return testcard(,"SMPTE TV Test Card",width := 672,height := 504, 
		   [   band(  1, [ bar(  1, "#c0c0c0"),
				   bar( 95, "#c0c000"),
   	    		           bar(191, "#00c0c0"),
				   bar(288, "#00c000"),
				   bar(383, "#c000c0"),
				   bar(480, "#c00000"),
				   bar(575, "#0000c0"),
				   bar(width) ] ),
		       band(335, [ bar(  1, "#0000c0"),
				   bar( 95, "#131313"),
				   bar(191, "#c000c0"),
				   bar(288, "#131313"),
				   bar(383, "#00c0c0"),
				   bar(480, "#131313"),
				   bar(575, "#c0c0c0"),
			           bar(width) ] ),
		       band(378, [ bar(  1, "#00214c"), 
				   bar(120, "#ffffff"),
				   bar(240, "#32006a"), 
				   bar(360, "#131313"), 
				   bar(480, "#090909"), 
				   bar(512, "#131313"), 
				   bar(544, "#1d1d1d"), 
				   bar(576, "#131313"),    
				   bar(width) ] ),
			band(height) ])
end


  

You may also check:How to resolve the algorithm Echo server step by step in the Raku programming language
You may also check:How to resolve the algorithm HTTPS step by step in the EchoLisp programming language
You may also check:How to resolve the algorithm Meissel–Mertens constant step by step in the Java programming language
You may also check:How to resolve the algorithm Sum of a series step by step in the TI-83 BASIC programming language
You may also check:How to resolve the algorithm Nth root step by step in the AutoHotkey programming language