Pinstripe/Printer: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 17: Line 17:


=={{header|Tcl}}==
=={{header|Tcl}}==
{{incorrect|PicoLisp|Output not device dependent, contrary to task giver's ink smudge intention.}}
This code assumes that the page's printable area is 8.5"×11".
This code assumes that the page's printable area is 8.5"×11".
{{libheader|Tk}}
{{libheader|Tk}}

Revision as of 08:33, 8 July 2011

Task
Pinstripe/Printer
You are encouraged to solve this task according to the task description, using any language you may know.

The task is to demonstrate the creation of a series of 1 point wide vertical pinstripes with a sufficient number of pinstripes to span the entire width of the printed page (except for the last pinstripe). The pinstripes should alternate one point white, one point black. (Where the printer does not support producing graphics in terms of points, pixels may be substituted in this task.)

After the first inch of printing, we switch to a wider 2 point wide vertical pinstripe pattern. alternating two points white, two points black. We then switch to 3 points wide for the next inch, and then 4 points wide, etc. This trend continues for the entire length of the page (or for 12 inches of run length in the case of a printer using continuous roll stationery). After printing the test pattern the page is ejected (or the test pattern is rolled clear of the printer enclosure, in the case of continuous roll printers).

PicoLisp

This example is incorrect. Please fix the code and remove this message.

Details: Output not device dependent, contrary to task giver's ink smudge intention.

<lang PicoLisp>(load "@lib/ps.l")

(call 'lpr

  (pdf "pinstripes"
     (a4)  # 595 x 842 dots
     (for X 595
        (gray (if (bit? 1 X) 0 100)
           (vline X 0 842) ) )
     (page) ) )</lang>

Tcl

This example is incorrect. Please fix the code and remove this message.

Details: Output not device dependent, contrary to task giver's ink smudge intention.

This code assumes that the page's printable area is 8.5"×11".

Library: Tk

<lang tcl>package require Tk

  1. Allocate a temporary drawing surface

canvas .c

  1. Draw the output we want

for {set y 0;set dx 1} {$y < 11*72} {incr y 72;incr dx} {

   for {set x 0;set c 0} {$x < 8.5*72} {incr x $dx;set c [expr {!$c}]} {

.c create rectangle $x $y [expr {$x+$dx+1}] [expr {$y+73}] \ -fill [lindex {black white} $c] -outline {}

   }

}

  1. Send postscript to default printer, scaled 1 pixel -> 1 point

exec lp - << [.c postscript -height $y -width $x -pageheight $y -pagewidth $x]

  1. Explicit exit; no GUI desired

exit</lang>