How to resolve the algorithm Colour pinstripe/Display step by step in the Tcl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Colour pinstripe/Display step by step in the Tcl 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 Tcl programming language

Source code in the tcl programming language

package require Tcl 8.5
package require Tk 8.5
 
wm attributes . -fullscreen 1
pack [canvas .c -highlightthick 0] -fill both -expand 1
set colors {black red green blue magenta cyan yellow white}

set dy [expr {[winfo screenheight .c]/4}]
set y 0
foreach dx {1 2 3 4} {
    for {set x 0} {$x < [winfo screenwidth .c]} {incr x $dx} {
	.c create rectangle $x $y [expr {$x+$dx}] [expr {$y+$dy}] \
            -fill [lindex $colors 0] -outline {}
	set colors [list {*}[lrange $colors 1 end] [lindex $colors 0]]
    }
    incr y $dy
}


  

You may also check:How to resolve the algorithm Call a function step by step in the Go programming language
You may also check:How to resolve the algorithm Short-circuit evaluation step by step in the Swift programming language
You may also check:How to resolve the algorithm Rep-string step by step in the C programming language
You may also check:How to resolve the algorithm Longest string challenge step by step in the Racket programming language
You may also check:How to resolve the algorithm Associative array/Iteration step by step in the M4 programming language