Debian Codegraph @

texmf-dist/source/metafont/roex/roexsamp/roes-04.mf

raw
1 %%%%
2 %%%% This file belongs to the ROEX package.
3 %%%%
4 %%% draw find_BB fill_C fix_fill_cmyk write_preamble write_postamble
5 %%% length cycle join
6 %%% / //
7 % ROES-04.MF, ``STAR FLOWERS'':
8 % An example of removing overlaps of a single self-intersecting curve;
9 % the sample curves (separate EPS files are generated for different
10 % curves) are based upon a regular star polygon backbone;
11 % the first curve is just such a polygon, the remaining two are
12 % smooth variations (observe setting |epsil.time:=1/500| in the third case);
13 % after removing overlaps objects are repositioned in such a way that
14 % the lower left corner of the bounding box coincides with the origin
15 % of coordinate system.
16 %%%%
17 %% % an innocent formatting trick: the underscore character ending a name
18 %% % will be typeset as an superscript asterisk
19 %% \let\oriunderscore\_
20 %% \newif\ifbgroupopen\bgroupopenfalse
21 %% \def\altdblbackslash#1{\bgroup\bgroupopentrue\it#1}
22 %% \def\optegroup{\ifbgroupopen\egroup\fi}
23 %% \def\underscoreasasterisk#1{%
24 %% \ifx#1\relax\optegroup^*\else\oriunderscore#1\fi}
25 %% \def\\#1{%
26 %% \let\_\underscoreasasterisk
27 %% \altdblbackslash{#1\relax}\optegroup
28 %% \let\_\oriunderscore}
29 % ---
30 input mftoeps; eps_mode_setup; input roex; tracingremoving:=1;
31 max_idx:=500; % better increase the default value
32 % ---
33 primarydef i // n =
34 (if n=0: 0 else: i/n fi) % why not to divide by 0?
35 enddef;
36 % ---
37 h#=1in#; w#=1in#;
38 % ---
39 beginchar("0",w#,h#,0);
40 pickup pencircle scaled 1;
41 for case:=0,1,2:
42 path p, V[\\][\\]; pair R; save x,y; numeric N, K, A, twirl;
43 twirl:=180;
44 % star polygons should fullfil |GCC(K,N)=1|, |1<K<N/2|
45 % (|N| is the number of nodes, |K| is a `leap')
46 if case=0: % A
47 N=9; K=4; def join = -- enddef; twirl:=0;
48 elseif case=1: % B
49 N=7; K=2; def join = .. tension 3 .. enddef;
50 elseif case=2: % C
51 N=13; K=4; def join = .. tension 3 .. enddef; epsil.time:=1/500;
52 fi
53 A=180-(360/N)*K; R=1in*right; z0=origin;
54 for i:=1 upto N-1: z[i]=z[i-1]+R; R:=R rotated (180-A); endfor
55 p:=z0 for i:=1 upto N-1: join z[i] endfor join cycle;
56 if twirl<>0:
57 p:=z0{(direction 0 of p) rotated twirl}
58 for i:=1 upto N-1: join {(direction i of p) rotated twirl}z[i] endfor
59 join cycle;
60 fi
61 remove_overlap (p)()R; % dummy recombining
62 col_min:=infinity; col_max:=-infinity;
63 for i:=-EDGE_.num upto EDGE_.num: if i<>0:
64 col_min:=min(EDGE_.col[i],col_min); col_max:=max(EDGE_.col[i],col_max);
65 fi endfor;
66 find_BB p;
67 for k:=col_min upto col_max: if k<>0:
68 vardef good_colors(expr i,j) = (i=k) enddef;
69 message "recombine_edges: color=" & decimal(k);
70 recombine_edges(V[k]);
71 for l:=1 upto V[k]num: V[k][l]:=V[k][l] shifted -llxy; endfor
72 fi endfor;
73 xh_crd:=xh_crd-xl_crd; xl_crd:=0;
74 yh_crd:=yh_crd-yl_crd; yl_crd:=0;
75 write_preamble jobname & char(ASCII("a")+case);
76 for k:=col_min upto col_max: if k<>0:
77 if V[k]num>0:
78 if k>0:
79 fix_fill_cmyk 0,3/4(((k-1)//(col_max-1))**1/2)[1,0],1,0;
80 else:
81 fix_fill_cmyk 3/4(((1+k)//(1+col_min))**1/2)[1,0],1,0,0;
82 fi
83 fill_C make_list(1,V[k]num)V[k];
84 fi
85 fi endfor % |for k|
86 write_postamble;
87 endfor % |for case|
88 endchar;
89 % ---
90 end.
91 %%\end