Gleduwiki GnomeRSVP
De Gleducar, http://www.gleducar.org.ar
- !/usr/bin/perl
- addpsx
- Generates addition worksheets in PostScript. Variable number of digits.
- This program is Copyright 1998 by Larry Doolittle.
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- If you do not have a copy of the GNU General Public License write to
- the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
- MA 02139, USA.
- You can reach Larry Doolittle as <weparent@widomaker.com>
- The "master" site for this program is
- http://www.widomaker.com/~weparent/oses.html
- Usage: addpsx <digits> | lpr
- Many parameters (e.g., size and spacing) are easily adjusted in the
- initialization section of this program.
$version="0.01";
if ($#ARGV < 0) {
print STDERR "usage: addpsx <digits> | lpr\n"; exit 1;
}
- Overall size
$pointsize=16; $vskip=18; $digits=int($ARGV[0]); if ($digits<1 || $digits>4) {
die "usage: addpsx <digits> | lpr\n digits must be between 1 and 4\n"; exit 1;
}
- Lateral spacing
$quescol=40; $colsep=60;
- Vertical spacing
$vstart=-90; $bottomskip=-450;
- Derived quantities
$dwidth=$pointsize*0.6; $hlsize=$dwidth*(2+$digits); $vskip2=0.7*$vskip; $vskip3=0.9*$vskip; $vskip4=1.8*$vskip; $lwidth=0.03*$vskip; $v2start=$vstart+$pointsize;
- Adjustments to primary quantities
$quescol+=($digits+2)*$dwidth; $colsep+=($digits+2)*$dwidth;
$gcos = (getpwuid($<))[6];
sub ps_digits { my $i; printf "LF "; for $i (reverse unpack ("C*",pop @_)) { $i=65 if $i==32; # space printf "d%c ",$i; } print "CR\n"; # printf "(%s)L\n",(pop @_); }
$now=localtime();
print <<EOF; %!PS-Adobe-2.0 EPSF-2.0 %%Creator: Larry Doolittle %%CreationDate: $now %%DocumentFonts: Helvetica %%Pages: 1 %%BoundingBox: 0 0 612 792 %%EndComments /Larrydict 20 dict def Larrydict begin /R {currentpoint stroke moveto
dup stringwidth pop neg 0 rmoveto show } def
/L {exch dup F exch moveto exch R -$vskip add} bind def /S {$vskip2 add newpath dup F -$hlsize add exch moveto
dup F exch lineto stroke -$vskip3 add} bind def
/LF {dup F -$dwidth add exch moveto} bind def /CR {-$vskip add} bind def /A {gsave show grestore -$dwidth 0 rmoveto} bind def /d0 {(0)A} bind def /d1 {(1)A} bind def /d2 {(2)A} bind def /d3 {(3)A} bind def /d4 {(4)A} bind def /d5 {(5)A} bind def /d6 {(6)A} bind def /d7 {(7)A} bind def /d8 {(8)A} bind def /d9 {(9)A} bind def /dx {(x)A} bind def /d+ {(+)A} bind def /dA {( )A} bind def end %%EndProlog
%%Page: 1 1 Larrydict begin gsave /Helvetica findfont $pointsize scalefont setfont $lwidth setlinewidth 90 rotate
EOF
$vpos=0; print "$vstart /F $quescol def\n"; for $i (1..40) { chomp(); if (1) { $a=int(rand(10**$digits)); $b=int(rand(10**$digits)); } else { $a=8; $b=int(rand(10)); if (rand(2)<1) { $t=$a; $a=$b; $b=$t; } } # ($a,$b)=split(); $t=$a+$b; ps_digits($a); ps_digits("+ ".$b); print "S\n"; # ps_digits($t); # don't print answer ps_digits(""); # skip a line instead print "-$vskip4 add\n"; $vpos+=3*$vskip+($vskip3-$vskip2)+$vskip4; if ($vpos > $vstart-$bottomskip) { $vpos=0; $quescol+=$colsep; print "pop $vstart /F $quescol def\n"; } } print <<EOF;
pop
grestore end showpage %%Trailer EOF