summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/metafont/mftoeps/m2esamp/clipsqu.mf
blob: 266ec217ae88d5f3a9f9e914141a868d2b5301fa (plain)
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
%%%%
%%%% This file belongs to the MFTOEPS package.
%%%%
% ---
% CLIPSQU.MF (Sierpi\'nski's carpet)
% ---
input mftoeps; eps_mode_setup;
% ---
def ^ = ** enddef; % syntactic sugar
primarydef i // n = % ditto
 (if n=0: 0 else: i/n fi)
% why not to divide by 0?
enddef;
def shifted_accordingly(expr i,j,n,D)=
 shifted ((i//n)[0,w-D],(j//n)[0,w-D])
enddef;
% ---
w#=16mm#; h#=16mm#; define_pixels(w,h);
for N:=1,2,3: % 4, 5, 6, ..., infinity
 set_BB 0,0,w,h;
 write_preamble jobname & decimal(N);
 D:=3w;
 for n:=0 for q:=1 upto N-1: , 3^q-1 endfor:
% i.e., |for n:=0, 3^1-1, 3^2-1, ..., 3^(N-1)-1:|
  path p[], q[]; D:=1/3D; k:=-1;
  for i:=0 upto n: for j:=0 upto n:
   k:=k+1;
   p[k]=unitsquare scaled D
    shifted_accordingly(i,j,n,D);
   q[k]=reverse unitsquare scaled 1/3D
    shifted (1/3D,1/3D) shifted_accordingly(i,j,n,D);
  endfor; endfor;
  clip_C p0, q0 for i:=1 upto k: , p[i], q[i] endfor;
 endfor;
 fill_C unitsquare scaled w;
 write_postamble;
endfor;
% ---
end.