Task: Colour pinstripe_Printer







Python: from turtle import *
from PIL import Image
import time
import subprocess



colors = ["black", "red", "green", "blue", "magenta", "cyan", "yellow", "white"]

screen = getscreen()




inch_width = 11.0
inch_height = 8.5

pixels_per_inch = 100

pix_width = int(inch_width*pixels_per_inch)
pix_height = int(inch_height*pixels_per_inch)

screen.setup (width=pix_width, height=pix_height, startx=0, starty=0)

screen.screensize(pix_width,pix_height)





left_edge = -screen.window_width()//2

right_edge = screen.window_width()//2

bottom_edge = -screen.window_height()//2

top_edge = screen.window_height()//2



screen.delay(0)
screen.tracer(5)

for inch in range(int(inch_width)-1):
    line_width = inch + 1
    pensize(line_width)
    colornum = 0

    min_x = left_edge + (inch * pixels_per_inch)
    max_x = left_edge + ((inch+1) * pixels_per_inch)
    
    for y in range(bottom_edge,top_edge,line_width):
        penup()
        pencolor(colors[colornum])
        colornum = (colornum + 1) % len(colors)
        setposition(min_x,y)
        pendown()
        setposition(max_x,y)
         
screen.getcanvas().postscript(file="striped.eps")




im = Image.open("striped.eps")
im.save("striped.jpg")


    
subprocess.run(["mspaint", "/pt", "striped.jpg"])





Ada: with Ada.Text_IO;

with PDF_Out;

procedure Color_Pinstripe_Printer
is
   use PDF_Out;

   package Point_IO
   is new Ada.Text_Io.Float_IO (Real);

   procedure Pinstripe (Doc          : in out Pdf_Out_File;
                        Line_Width   : Real;
                        Line_Height  : Real;
                        Screen_Width : Real;
                        Y            : Real)
   is
      type Color_Range is (Blck, Red, Green, Blue, Magenta, Cyan, Yellow, White);
      Colors : constant array (Color_Range) of Color_Type
        := (Blck    => (0.0, 0.0, 0.0), Red   => (1.0, 0.0, 0.0),
            Green   => (0.0, 1.0, 0.0), Blue  => (0.0, 0.0, 1.0),
            Magenta => (1.0, 0.0, 1.0), Cyan  => (0.0, 1.0, 1.0),
            Yellow  => (1.0, 1.0, 0.0), White => (1.0, 1.0, 1.0));
      Col : Color_Range := Color_Range'First;

      Count  : constant Natural
        := Natural (Real'Floor (Screen_Width / Line_Width));
      Corner      : constant Point := (Doc.Left_Margin, Doc.Bottom_Margin);
      Corner_Box  : constant Point := Corner     + (10.0, 10.0);
      Corner_Text : constant Point := Corner_Box + (10.0, 10.0);
      Light_Gray  : constant Color_Type := (0.9, 0.9, 0.9);
      Image : String (1 .. 4);
   begin
      
      for A in 0 .. Count loop
         Doc.Color (Colors (Col));
         Doc.Draw (What => Corner +
                     Rectangle'(X_Min  => Real (A) * Line_Width,
                                Y_Min  => Y,
                                Width  => Line_Width,
                                Height => Line_Height),
                   Rendering => Fill);
         Col := (if Col = Color_Range'Last
                 then Color_Range'First
                 else Color_Range'Succ (Col));
      end loop;

      
      Doc.Stroking_Color (Black);
      Doc.Color (Light_Gray);
      Doc.Line_Width (3.0);
      Doc.Draw (What => Corner_Box + (0.0, Y, 150.0, 26.0),
                Rendering => Fill_Then_Stroke);
      
      Doc.Color (Black);
      Doc.Text_Rendering_Mode (Fill);
      Point_Io.Put (Image, Line_Width, Aft => 1, Exp => 0);
      Doc.Put_XY (Corner_Text.X, Corner_Text.Y + Y,
                  Image & " point color pinstripe");
   end Pinstripe;

   Doc : PDF_Out_File;
begin
   Doc.Create ("color-pinstripe.pdf");
   Doc.Page_Setup (A4_Portrait);
   Doc.Margins (Margins_Type'(Left   => Cm_2_5,
                              others => One_cm));
   declare
      Width  : constant Real
        := A4_Portrait.Width - Doc.Left_Margin - Doc.Right_Margin;
      Height : constant Real
        := A4_Portrait.Height - Doc.Top_Margin - Doc.Bottom_Margin;
   begin
      for Point in 1 .. 11 loop
         Pinstripe (Doc,
                    Line_Width   => Real (Point),
                    Line_Height  => One_Inch,
                    Screen_Width => Width,
                    Y            => Height - Real (Point) * One_Inch);
      end loop;
   end;
   Doc.Close;
end Color_Pinstripe_Printer;