chiark / gitweb /
overflow-tube: wip cut2
[quacks.git] / overflow-tube.ps.pl
1 #!/usr/bin/perl -w
2 # Books of Pumpkins, etc.  Extensions to Quacks of Quedlinburg
3 #  SPDX-License-Identifier: GPL-3.0-or-later OR CC-BY-SA-4.0
4 # Copyright 2020-2022 Ian Jackson
5
6 use strict;
7
8 BEGIN { unshift @INC, '.'; }
9 use Quacks;
10
11 sub o {
12   local $_;
13   for (@_) { $ps_framing .= $_ }
14 }
15
16 ps_start(<<END);
17 %90 rotate
18 %0 -210 translate
19 END
20
21 my $x_cut = 27;
22 my $x_cut2 = 38;
23 my $y_cut2 = 24;
24 my $y_cutd = 10;
25
26 my $y_cut2d = $y_cutd * ($x_cut2-$x_cut)/$x_cut;
27
28 my $nrepis = 4;
29
30 my $paper_x = 210;
31
32 my $spacing = 23;
33 my $colspacing = 23;
34 my $vhalf = sqrt( $spacing ** 2 - ($colspacing*0.5) ** 2 );
35
36 my $y_cut = 2.75 * $spacing;
37
38 my $x_pl_zero = $paper_x*0.5 - 3*$colspacing;
39 my $y_pl_zero = $y_cut + $spacing - $y_cutd* 0.5 * $x_cut/$colspacing;
40
41 my $y_top = $y_pl_zero + $y_cutd + $spacing*1.25;
42
43 our $veep_bg = " 0.95 0.90 0.67 setrgbcolor ";
44
45 sub some_cut_line($) {
46   <<END;
47 gsave
48   0.25 setlinewidth
49   $_[0]
50 grestore
51 END
52 }
53
54
55 o <<GS, some_cut_line(<<GR), <<END;
56 /cut_line {
57 GS
58                               newpath
59   $x_cut2 0                   moveto
60   $x_cut2 $y_cut2             lineto
61   $x_cut  $y_cut2 $y_cut2d add lineto
62   $x_cut $y_cut               lineto
63   0      $y_cut $y_cutd add   lineto
64   0      $y_top               lineto
65                               stroke
66 GR
67 } def
68 END
69
70 my $veep_font = "/Helvetica-Bold findfont 6.5 scalefont setfont";
71 my $money_font = "/Helvetica-BoldOblique findfont 6.5 scalefont setfont";
72
73 o <<END;
74 $money_font
75 END
76
77 sub veepsq ($) {
78   my ($veeps) = @_;
79
80   my $sqx = 4.1;
81   my $sqy = 3.2;
82
83   <<END;
84   gsave
85     -1.5 -3.0 translate
86
87     gsave
88       newpath  -$sqx -$sqy moveto
89                -$sqx  $sqy lineto
90                 $sqx  $sqy lineto
91                 $sqx -$sqy lineto closepath
92
93        gsave 
94              $veep_bg
95              fill
96        grestore
97        0.19 0.35 0.25 setrgbcolor
98        0.5 setlinewidth
99        stroke
100     grestore
101
102     $veep_font
103     0 0 moveto
104     ($veeps) dup  stringwidth pop -0.5 mul -2.5 rmoveto  show
105   grestore
106 END
107 }
108
109 sub places ($) {
110   my ($repi) = @_;
111   my $data = <<END;
112     -1-L*H -1
113         -1  0   34 14
114         -H  V   34 14 1
115          0  0   34 15
116          0 -1   35 15
117          0 -2   35 16
118          H -2-V 35 16 1
119          1 -2   36 16
120          1 -1   37 16
121      1+R*H  0
122 END
123   my $line;
124   my $line_word = 'moveto';
125
126   my $o = '';
127
128   $o .= <<END;
129     gsave
130 END
131   foreach (split /\n/, $data) {
132     s{\#.*}{};
133     next unless m/\S/;
134     s{^\s*}{};
135     s{L}{ ($repi == 0         ? 1 : 0) }ge;
136     s{R}{ ($repi == $nrepis-1 ? 1 : 0) }ge;
137     s{H}{ 0.5 }ge;
138     s{V}{ $vhalf / $spacing }ge;
139     my ($x,$y,$money,$veeps,$ruby) = map { eval $_ } split /\s+/;
140     $ruby ||= 0;
141     $x *= $colspacing;
142     $y *= $spacing;
143     $x += $x_pl_zero;
144     $y += $y_pl_zero;
145
146     $line .= " $x $y $line_word";
147     $line_word = 'lineto';
148     next unless defined $money;
149
150     $money += 4 * $repi;
151     $veeps += 2 * $repi;
152
153     $o .= <<END;
154 % place $x $y $money $veeps $ruby
155 gsave
156   $x $y translate
157   gsave
158     newpath
159     0 0 chip 0.5 mul 0 360 arc
160     gsave 0.5 setlinewidth $black stroke grestore
161     0.80 0.89 0.63 setrgbcolor fill
162   grestore
163
164   -4.7 1 moveto ($money) show
165
166   ${\ veepsq($veeps) }
167 END
168
169     $o .= <<END if $ruby;
170  gsave
171    6 -1 translate
172    0.8 dup scale
173    ${ \ruby() }
174  grestore
175 END
176
177     $o .= <<END;
178 grestore
179 END
180   }
181   $o .= <<END;
182     grestore
183 END
184
185   $line = <<END;
186   newpath
187     0.66 0.85 0.75 setrgbcolor
188     4 setlinewidth
189   $line
190   stroke
191 END
192
193   ($line, $o)
194 }
195
196 sub repis () {
197   for my $places_i (qw(0 1)) {
198     for my $repi (0..$nrepis-1) {
199       o(<<END);
200 % repi $places_i $repi
201 gsave
202   $repi $colspacing 2 mul mul  0 translate
203 END
204
205       o( (places($repi))[$places_i] );
206       o(<<END);
207 grestore
208 END
209     }
210   }
211 }
212
213 sub set () {
214   o(<<END);
215     cut_line
216     gsave
217       $paper_x $x_cut sub  0 translate
218       cut_line
219     grestore
220 END
221   o some_cut_line <<END;
222                                  newpath
223     0                    $y_top  moveto
224     $paper_x $x_cut sub  $y_top  lineto
225                                  stroke
226 END
227
228   repis();
229
230   o <<END;
231     gsave
232       /Times-Roman findfont 4.0 scalefont setfont
233       4 97 moveto  (cover) show
234       6 93.5 moveto  (up) show
235       4 89 moveto
236       /Helvetica-Bold-Italic findfont 3.5 scalefont setfont (35) show
237       1 0 rmoveto
238       /Helvetica-Bold findfont 3.5 scalefont setfont (15) show
239     grestore
240
241     gsave
242       $paper_x $x_cut sub  $y_top 7 sub translate
243
244       gsave
245         arrowlen 2 add neg  0 translate
246         ${\ arrow_any("arrowlen 0 moveto  -30 0 rlineto") }
247       grestore
248
249       -40 0 translate
250       /Helvetica-Bold findfont 6.5 scalefont setfont
251
252      -4.5 0 moveto
253      $money_font
254      (+16) show
255
256      4 -2 translate
257      ${\ veepsq('+8') }
258
259      4 4.5 moveto
260      /Times-Roman findfont 4.5 scalefont setfont
261      (per next page) show
262
263     grestore
264 END
265 }
266
267 set();
268 o <<END;
269 gsave 0 $y_top translate
270 END
271 set();
272 o <<END;
273 grestore
274 END
275
276 print $ps_framing or die $!;