boolean debug; pad := 0.1; debug := false; def insert (expr bp)(suffix s)(text loops)= forsuffixes $=loops: if $=1: subpath(0, s[$]t * length bp - pad) of bp fi .. if length s[$]p = 4: {direction s[$]t * length bp of bp rotated 180}(point 2 of s[$]p) else: subpath(2, length s[$]p-2) of s[$]p fi rotated angle direction s[$]t * length bp of bp shifted point s[$]t * length bp of bp .. subpath(s[$]t * length bp + pad, (if known s[$+1]t: s[$+1]t * length bp - pad else: length bp fi)) of bp endfor enddef; def loop(expr height) = (-.75height,0) .. (0,0) .. {-1,0}(0, height) .. (0,0) .. (.75height,0) enddef; %% %% The idea is to draw loops and toinsert them into other shapes at a 'time'. %% This time lies between 0 and 1 %% %% The easiest way to modify the drawing is by changing the main shape at te bottom %% of the file %% beginfig(1); path l[][]p, main; numeric l[][]t; %% Contsructing loop 1 and its subloops l[1][1]p = loop(15mm); l[1][1]t = .3; l[1][2]p = loop(19mm); l[1][2]t = 2/4; l[1][3]p = loop(9mm); l[1][3]t = .6; l[4][1]t = 1.5/6; l[4][1]p = insert(loop(40mm), l[1], 1, 2, 3); %% Constructing loop 2 and its subloops l[2][1]p = loop(12mm); l[2][1]t = .3; l[5][1]p = loop(4mm); l[5][1]t = .35; l[5][2]p = loop(4mm); l[5][2]t = .5; l[2][2]p = insert(loop(15mm), l[5], 1, 2); l[2][2]t = .5; l[2][3]p = loop(9mm); l[2][3]t = .7; l[4][2]t = 3/6; l[4][2]p = insert(loop(40mm), l[2], 1, 2, 3); %% Constructing loop 3 and its subloops l[3][1]p = loop(10mm); l[3][1]t = .3; l[3][2]p = loop(12mm); l[3][2]t = .4; l[3][3]p = loop(10mm); l[3][3]t = .5; l[3][4]p = loop(8mm); l[3][4]t = .6; l[3][5]p = loop(15mm); l[3][5]t = .7; l[4][3]t = 4.5/6; l[4][3]p = insert(loop(40mm), l[3], 1, 2, 3, 4, 5); %% Definition of the main shape, and the insertion of the subloops main = insert((0,0) -- (0,400mm), l[4], 1, 2, 3); draw main; % Drawing debug information if debug: for s=0 step 1 until length main: dotlabel.bot(decimal s, point s of main) withcolor red; endfor fi endfig; end;