File: electrospiral.mp

package info (click to toggle)
texlive-base 2020.20210202-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 791,092 kB
  • sloc: perl: 45,038; sh: 4,926; makefile: 4,655; ansic: 2,266; ruby: 2,231; tcl: 2,156; xml: 1,874; python: 822; cpp: 695; awk: 606; lisp: 199; sed: 8
file content (50 lines) | stat: -rw-r--r-- 992 bytes parent folder | download | duplicates (9)
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;