- 论坛徽章:
- 0
|
MetaPost语言 自娱自乐
#!/bin/sh
genmpost()
{
cat - << EOF
def Drawhorses(expr ha,hb,hc,hd)=
begingroup
save i, line_s, line_e, line_w, line_h, line_hw;
pair line_s, line_e, line_h;
line_s:=(0,0); line_e:=(5cm,0);
line_w:=8mm;
line_h:=(0,2mm); line_hw:=4mm;
draw (-3,-3mm) withcolor white;
draw (53mm,35mm) withcolor white;
for i=0 step 1 until 4:
draw (line_s -- line_e) shifted (0,line_w*i) withpen pencircle scaled 3pt ;
numeric myshift;
if i=0: myshift:=ha; else: if i=1: myshift:=hb; else: if i=2: myshift:=hc; else: myshift:=hd; fi; fi; fi;
if i<=3:
draw (line_h -- line_h shifted (line_hw,0) -- line_h shifted (line_hw, line_hw) -- line_h shifted(0, line_hw) -- cycle) shifted (myshift, i*line_w) withpen pencircle scaled 4pt;
fi;
endfor;
endgroup
enddef;
EOF
awk 'BEGIN{
"date +%s" | getline myseed; srand(myseed);
ha=0;hb=0;hc=0;hd=0; myend=46; i=1000;
while(ha < myend && hb < myend && hc < myend && hd < myend )
{
ha+=rand()*2;
hb+=rand()*2;
hc+=rand()*2;
hd+=rand()*2;
printf("beginfig(%3d)\n",i++);
printf("Drawhorses(%fmm,%fmm,%fmm,%fmm);\n",ha,hb,hc,hd);
print "endfig;";
}
print "end;";
exit;
}'
}
genmpost > mytmpmposthorse.mp
mptopdf mytmpmposthorse.mp
convert -sampling-factor 1 mytmpmposthorse-[0-9]???.pdf horses.gif
rm mytmpmposthorse-[0-9]???.pdf
rm mytmpmposthorse.[0-9]???
rm mytmpmposthorse.mp |
[ 本帖最后由 doctorjxd 于 2007-12-27 17:32 编辑 ] |
|