summaryrefslogtreecommitdiff
path: root/info/examples/lgc2/4-1-5.mp
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /info/examples/lgc2/4-1-5.mp
Initial commit
Diffstat (limited to 'info/examples/lgc2/4-1-5.mp')
-rw-r--r--info/examples/lgc2/4-1-5.mp43
1 files changed, 43 insertions, 0 deletions
diff --git a/info/examples/lgc2/4-1-5.mp b/info/examples/lgc2/4-1-5.mp
new file mode 100644
index 0000000000..96ac30324f
--- /dev/null
+++ b/info/examples/lgc2/4-1-5.mp
@@ -0,0 +1,43 @@
+% --- start of displayed preamble in the book ---
+% p=picture
+def draw_multipath(expr p) text options=
+ for i within p:
+ draw i options;
+ endfor;
+enddef;
+
+vardef addto_multipath(text p)(expr pa,thickness) text options=
+ save savepen;
+ pen savepen;
+ savepen=currentpen;
+ pickup pencircle scaled thickness;
+ addto p also image(draw pa options;);
+ currentpen:=savepen;
+enddef;
+% --- end of displayed preamble in the book ---
+% graphic converted to gray in book using 'color2gray'
+defaultfont:="ptmr8r";
+warningcheck:=0;
+beginfig(1)
+numeric u;u=10mm;
+path p[];picture pic;
+p0=origin..(2u,0)..(4u,u)..(3u,2u)
+ ...(2u,-u)..tension2..(u,3u);
+n=20;
+for i=1 upto n:
+ p[i]=subpath(((i-1)/n)*length(p0),
+ (i/n)*length(p0)) of p0;
+endfor;
+pic=nullpicture;
+for i=1 upto n:
+ if odd i:
+ addto_multipath(pic)(p[i],2pt*i/n)
+ withcolor ((i/n)*red+(1-i/n)*blue);
+ else:
+ addto_multipath(pic)(p[i],3pt*(1-i/n))
+ withcolor ((i/n)*green+(1-i/n)*blue);
+ fi;
+endfor;
+draw_multipath(pic);
+endfig;
+end;