summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/metapost/featpost/example/electrospiral.mp
blob: 7ed2200e9f06a646b63a9c09b4144378fbf7cb74 (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
40
41
42
43
44
45
46
47
48
49
50
% electrospiral.mp
% L. Nobre G. 
% 2004

numeric turnstep;
turnstep = 1cm;

def spiral( expr Ang ) =
  begingroup
    numeric k, r;
    k = turnstep/360.0;
    r = k*Ang;
    ( r*dir(Ang) )
  endgroup
enddef;
    
beginfig(1);
  numeric i, angstep, actx, ray, corner, sider;
  path spir, cutter;
  pair thispos, sw, nw, ne, se, actpos;
  angstep = 30;
  ray = 0.7mm;
  corner = 4.2;
  sider = 10.5;
  spir = origin..
  for i=angstep step angstep until 4000-1:
    spiral(i)..
  endfor
  spiral(4000);
  draw spir;
  actx = 1;
  forever:
    thispos := (turnstep*actx,0);
    for i=1 upto actx:
      actpos := thispos+ray*normaldeviate*dir(uniformdeviate(359));
      draw actpos withpen pencircle scaled 1.5mm;
    endfor;
    actx := 2*actx;
    exitif actx > 9;
  endfor;
  sw = turnstep*(-corner,-corner);
  nw = turnstep*(-corner,corner);
  ne = turnstep*(sider,corner);
  se = turnstep*(sider,-corner);
  cutter = sw--nw--ne--se--cycle;
  clip currentpicture to cutter;
endfig;

end;