-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenps
executable file
·202 lines (192 loc) · 5.45 KB
/
genps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/perl
$xoffset=0;
$yoffset=0;
$scale=1;
$colorscale=2;
$linewidth=0.005;
$auto_xoffset=0;
$auto_yoffset=0;
$auto_xsize=0;
$auto_ysize=0;
$autoscale=10;
$drawline=0;
foreach (@ARGV) {
chomp;
if (/-x(.*)/) {
$xoffset=$1;
}
if (/-y(.*)/) {
$yoffset=$1;
}
if (/-s(.*)/) {
$scale0=$1;
}
if (/-a/) {
$autoscale=1;
}
if (/-d/) {
$drawline=1;
}
if (/-l(.*)/) {
$linewidth=$1;
}
if (/-c(.*)/) {
$colorscale=$1;
}
if (/^-h/ or /^--h/ or /^-\?/) {
print "Usage: xbps [-x0] [-y0] [-s1] [-l0.01] FILE\n";
print "\t-x\toffset in x\n";
print "\t-y\toffset in y\n";
print "\t-s\tscale factor\n";
print "\t-a\ttry to autoscale\n";
print "\t-l\tline width\n";
exit;
}
}
foreach (@ARGV) {
chomp;
if (/^[^-]/){
$filename=$_;
open(INPUT,$filename) or die "Can't open $FOO: $!";
$particle_counter=1;
$page_counter=0;
while(<INPUT>){
next if(/^#/);
chomp;
if($particle_counter==0){
/^(\S*)\s*\S*\s*(\S*)\s*(\S*)\s*(\S*)\s*(\S*)/; # xball format 2d
# /^(\S*)\s*\S*\s*(\S*)\s*(\S*)\s*\S*\s*(\S*)\s*(\S*)/; # xball format 3d
if($autoscale){
if($4-$2>$auto_xsize){$auto_xsize=$4-$2};
if($5-$3>$auto_ysize){$auto_ysize=$5-$3};
}
$particle_counter=$1;
$page_counter++;
} else {
$particle_counter--;
}
}
# if($autoscale){
# $scale=29.7/$auto_ysize; # 297mm
# $tmp=21.0 / $auto_xsize; # 210mm
# if($tmp<$scale) {$scale=$tmp};
# }
############## an arrow
#newpath
#4.500000 25.30 moveto
#1 0 rlineto
#-.1 .2 rlineto
#.5 -.3 rlineto
#-.5 -.3 rlineto
#0.1 .2 rlineto
#-1 0 rlineto
#0 0.2 rlineto
#fill
#stroke
###################
print "%!PS-Adobe-1.0\n";
print "%%Pages: ", $page_counter,"\n";
print "/box {newpath 2 index 2 index exch moveto dup 0 rlineto dup 0 exch rlineto -1 mul 0 rlineto pop pop closepath stroke} bind def\n";
print"/fbox {newpath 2 index 2 index exch moveto dup 0 rlineto dup 0 exch rlineto -1 mul 0 rlineto pop pop closepath fill stroke} bind def\n";
print "/cir {0 360 arc closepath stroke}bind def\n";
print "/proj { 2 index viewx sub 1 index viewz sub div viewz mul -1 mul viewx add
2 index viewy sub 2 index viewz sub div viewz mul -1 mul viewy add } bind def\n";
print " /red {gsave 0 360 arc closepath 0.9 0.7 0.7 setrgbcolor fill stroke grestore }bind def";
print "/blue {gsave 0 360 arc closepath 0.7 0.7 0.9 setrgbcolor fill stroke grestore }bind def";
print "/bcir {gsave 0 360 arc closepath 0.3 0.3 0.3 setrgbcolor fill stroke grestore }bind def";
print "/wcir {gsave 0 360 arc closepath 0.9 0.9 0.9 setrgbcolor fill stroke grestore }bind def";
print"/textN { pop moveto (N) show newpath }bind def\n";
print"/textS{ pop moveto (S) show newpath}bind def\n";
print"/textE{ pop moveto (E) show newpath}bind def\n";
print"/textW { pop moveto (W) show newpath}bind def\n";
print"/textSE { pop moveto (SE) show newpath}bind def\n";
print"/textNW { pop moveto (NW) show newpath}bind def\n";
print"/textSW { pop moveto (SW) show newpath}bind def\n";
print"/textNE { pop moveto (NE) show newpath}bind def\n";
print "/fcir {0 360 arc closepath fill stroke}bind def\n";
print "/myarrow {moveto lineto stroke}bind def\n";
print "/bline { lineto gsave 0 0 1 setrgbcolor 0.05 setlinewidth stroke grestore}bind def\n";
print "/rline { gsave 1 0 0 setrgbcolor 0.05 setlinewidth lineto stroke grestore}bind def\n";
print "/c {pop 1 index 1 index lineto stroke moveto} bind def\n";
print "/cf {gsave 0 360 arc closepath } bind def\n";
print "/f {setrgbcolor fill stroke grestore} bind def\n";
print "/dc {0 360 arc gsave [0.2 0.2] 0.12 setdash .03 setlinewidth stroke";
print " grestore newpath } bind def\n";
print "/mypageinit {matrix currentmatrix /originmat exch def /umatrix {originmat matrix concatmatrix setmatrix} def [28.3465 0 0 28.3465 10.5 100.0] umatrix ", $linewidth, " setlinewidth} bind def\n";
print "
/Times-Roman findfont
0.2 scalefont
setfont
";
open(INPUT,$filename) or die "Can't open $FOO: $!";
$particle_counter=0;
$line_counter=0;
$page_counter=0;
print "%%Page: ", $page_counter,"\n";
print "mypageinit\n";
while(<INPUT>){
if(/^#echo (.*)/){
print $1;
}
next if(/^#/);
chomp;
/^\s*(\S*)\s*(\S*)\s*(\S*)\s*(\S*)\s*(\S*)\s*(\S*)\s*(\S*)\s*(\S*)\s*(\S*)\s*(\S*)/;
if($line_counter eq 0){
$height=$1;
$line_counter=1;
#$xoffset=-.2;
$scale=10.0*$scale/$height;
$yoffset=($2+$yoffset)*$scale*1.05;
}
if($1 eq "l" or $1 eq "a"){
$x=$xoffset+$scale*$2;
$y=$yoffset+$scale*$3;
$x2=$xoffset+$scale*$4;
$y2=$yoffset+$scale*$5;
$rcolor=0.5;
$gcolor=.5;
$bcolor=.5;
print "gsave ";
if($1 eq "a"){
$dashw=0.05/$height;
print "[",$dashw,"] 0 setdash\n";
$rcolor=0.2;
$gcolor=.2;
$bcolor=.2;
}
$linew=0.002/$height;
print $linew, " setlinewidth\n";
printf("%f %f %f setrgbcolor\n", $rcolor, $gcolor, $bcolor);
printf("newpath %f %f moveto\n", $x, $y);
printf("%f %f lineto stroke\n", $x2, $y2);
print "grestore\n";
}
if($1 eq "c" ){
if($5 eq 1){
$rcolor=1;
$gcolor=0;
$bcolor=0;
}
if($5 eq 0){
$rcolor=0;
$gcolor=0;
$bcolor=1;
}
if($5 eq 2){
$rcolor=0;
$gcolor=1;
$bcolor=0;
}
$x=$xoffset+$scale*$2;
$y=$yoffset+$scale*$3;
$r=1.3*$scale*$4;
print "gsave ";
printf("%f %f %f setrgbcolor\n", $rcolor, $gcolor, $bcolor);
printf("%f %f %f fcir\n", $x, $y, $r);
print "grestore\n";
}
}
print "showpage quit\n";
exit;
}
}