Colour pinstripe/Printer: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Phix}}: marked p2js compatible)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(4 intermediate revisions by 4 users not shown)
Line 8:
 
Optionally, on systems where the printer resolution cannot be determined, it is permissible to prompt the user for printer resolution, and to calculate point size based on user input, enabling fractional point sizes to be used.
 
=={{header|Ada}}==
{{libheader|APDF}}
<syntaxhighlight lang="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
-- Pinstripes
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;
 
-- Box
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);
-- Text
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;</syntaxhighlight>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
This program first displays a Print Dialogue so the printer can be selected.
<langsyntaxhighlight lang="bbcbasic"> PD_RETURNDC = 256
_LOGPIXELSY = 90
Line 54 ⟶ 140:
pitch% += 1
NEXT y%
VDU 2,1,12,3</langsyntaxhighlight>
 
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">Dim As String exename
#ifdef __FB_WIN32__
exename = "mspaint.exe /pt"
#endif
#ifdef __FB_LINUX__
exename = "lp -o media=A4 "
#endif
 
Dim As Uinteger ps, col, h, w, x, y1, y2
 
' (A4) # 595 x 842 dots
w = 842 : h = 595
' create display size window, 8bit color (palette), no frame
Screenres w, h, 8,, 8
 
h \= 7 : y2 = h -1
 
For ps = 1 To 7
col = 0
For x = 0 To (w - ps -1) Step ps
Line (x, y1) - (x + ps -1, y2), col, bf
col = (col +1) And 255
Next x
y1 += h : y2 += h
Next ps
 
Dim As String filename = "color_pinstripe.bmp"
If Bsave(filename, 0) <> 0 Then
Cls: Print "Error saving: "; fileName : Sleep
Else
Dim As Integer result = Exec(exename, filename)
If result = -1 Then Print "Error running "; exename : Sleep
End If
End</syntaxhighlight>
 
 
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
void local fn BuildWindow
CGRect r = { 0, 0, 612, 791 } // U.S. Letter Portrait
long i, j, colorCount, bars = 612
CGFloat y = 0.0, w = 1
CFArrayRef colors = @[¬
fn ColorBlack,¬
fn ColorRed,¬
fn ColorGreen,¬
fn ColorBlue,¬
fn ColorMagenta,¬
fn ColorCyan,¬
fn ColorYellow,¬
fn ColorWhite]
window 1, @"Color Pinstripe Printer Page [U.S. Letter Portrait]", r
pen -1
for j = 1 to 4
r = fn CGRectMake( 0, y, w, 197.75 )
colorCount = 0
for i = 0 to bars - 1
rect fill r, colors[colorCount]
r.origin.x += w
colorCount++
if colorCount == 8 then colorCount = 0
next
bars = bars << 1
y += 197.75 : w++
next
end fn
 
fn BuildWindow
 
HandleEvents
</syntaxhighlight>
{{output}}
[[File:Color Pinstripe Printer Page.png]]
 
 
=={{header|Go}}==
Line 60 ⟶ 228:
<br>
The code for this task is basically the same as for [[Colour_pinstripe/Display#Go]] except that the drawing parameters have been tweaked to produce 1 inch bands when printing on A4 paper and some code has been added to dump the image to the default printer.
<langsyntaxhighlight lang="go">package main
import (
Line 107 ⟶ 275:
log.Fatal(err)
}
}</langsyntaxhighlight>
 
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">
<lang Julia>
using Colors, FileIO
 
Line 146 ⟶ 314:
colorstripepng("temp.png")
run(`print temp.png`) # the run statement may need to be set up for the installed device
</syntaxhighlight>
</lang>
 
=={{header|Nim}}==
Line 153 ⟶ 321:
The code for drawing is the same that in the task Colour_pinstripe/Display but the context is different. We have chosen to display a dialog to give the user a way to choose the destination (which may be a printer or a file). Instead of the “draw” signal, we have to process the “begin_print” signal to set the number of pages and the “draw_page” signal to render the page.
 
<langsyntaxhighlight Nimlang="nim">import gintro/[glib, gobject, gtk, gio, cairo]
 
const Colors = [[0.0, 0.0, 0.0], [255.0, 0.0, 0.0],
Line 205 ⟶ 373:
let app = newApplication(Application, "Rosetta.ColorPinstripe")
discard app.connect("activate", activate)
discard app.run()</langsyntaxhighlight>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang Phix="phix">(phixonline)--><!--</langsyntaxhighlight>-->
See the print_cb function of [[Colour_pinstripe/Display#Phix]] and the final comments of that entry.
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(load "@lib/ps.l")
 
# Using circular lists for an endless supply of colors
Line 236 ⟶ 404:
(zero I)
(inc 'Step) ) ) )
(page) ) )</langsyntaxhighlight>
 
=={{header|Python}}==
<syntaxhighlight lang="python">
<lang Python>
from turtle import *
from PIL import Image
Line 319 ⟶ 487:
subprocess.run(["mspaint", "/pt", "striped.jpg"])
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
Line 326 ⟶ 494:
only drawing onto a printer device context now.
 
<syntaxhighlight lang="racket">
<lang Racket>
#lang racket/gui
 
Line 348 ⟶ 516:
 
(send* dc (end-page) (end-doc))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
Line 355 ⟶ 523:
Note that Raku does not attempt to be a printer driver. This example allows users to specify the dpi and paper size, then generates an image and passes it to the default printer. Defaults to 300 dpi and US letter paper.
 
<syntaxhighlight lang="raku" perl6line>unit sub MAIN ($dpi = 300, $size = 'letter');
 
my $filename = './Color-pinstripe-printer-perl6.png';
Line 411 ⟶ 579:
 
# Uncomment next line if you actually want to print it
#run('lp', $filename)</langsyntaxhighlight>
See [https://github.com/thundergnat/rc/blob/master/img/Color-pinstripe-printer-perl6.png Color-pinstripe-printer-perl6.png] (offsite png image)
 
Line 417 ⟶ 585:
This code assumes that the page's printable area is 8.5"×11".
{{libheader|Tk}}
<langsyntaxhighlight lang="tcl">package require Tk
# Allocate a temporary drawing surface
canvas .c
Line 432 ⟶ 600:
exec lp - << [.c postscript -height $y -width $x -pageheight $y -pagewidth $x]
# Explicit exit; no GUI desired
exit</langsyntaxhighlight>
 
=={{header|Wren}}==
Line 439 ⟶ 607:
<br>
This reuses the plug-in from the [[Pinstripe/Printer#Wren]] task to enable DOME to print to the default printer.
<langsyntaxhighlight ecmascriptlang="wren">import "graphics" for Canvas, Color, ImageData
import "dome" for Window
import "plugin" for Plugin
Line 496 ⟶ 664:
}
 
var Game = Main.new()</langsyntaxhighlight>
 
{{omit from|AWK}}
9,485

edits