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

Published on 12 May 2024 09:40 PM

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

Source code in the sidef programming language

require('GD')

func pinstripes(width = 1280, height = 720) {

    var im = %O.new(width, height)
    var colors = [0, 255].variations_with_repetition(3)

    var paintcolors = colors.shuffle.map {|rgb|
        im.colorAllocate(rgb...)
    }

    var starty     = 0
    var barheight  = height//4

    for barwidth in (1..4) {
        for (
            var(startx = 0, colorindex = 0);
            startx + barwidth <= width;
            startx += barwidth
        ) {
            im.filledRectangle(startx, starty, startx+barwidth,
                starty + barheight - 1, paintcolors[colorindex++ % 8])
        }
        starty += barheight
    }

    return im
}

File('pinstripes.png').write(pinstripes().png, :raw)


  

You may also check:How to resolve the algorithm Sort stability step by step in the PHP programming language
You may also check:How to resolve the algorithm Hello world/Web server step by step in the Delphi programming language
You may also check:How to resolve the algorithm Sutherland-Hodgman polygon clipping step by step in the C++ programming language
You may also check:How to resolve the algorithm Temperature conversion step by step in the Scala programming language
You may also check:How to resolve the algorithm Averages/Mean time of day step by step in the PL/I programming language