summaryrefslogtreecommitdiff
path: root/info/examples/lgc2/D-4-2.mp
blob: 23f73640f786ba9a65bb0d71d8c7d3dfb3bd735a (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
% --- start of displayed preamble in the book ---

% --- end of displayed preamble in the book ---
defaultfont:="ptmr8r";
warningcheck:=0;
beginfig(1)
% Fraser's Spiral
% D. Roegel 29 April 2007

numeric u;
u=2.7cm;

vardef twisted_cord(expr i,twist,a,col)=
  save qa,qb,qc,P,ratio;
  path qa,qb,qc;
  pair P[];
  ratio=0.8;
  P1=A[i];
  P2=radius(i)*dir((1+i/2)*da);
  P3=radius(i)*dir((1+i/2-shift)*da);
  P5=B[i-1] rotated da;
  P6=radius(i)*dir((2+i/2)*da);
  P7=radius(i)*dir((2+i/2-shift)*da);
  P0=.5[P2,P7];
  P21=arclength((.5[ratio,1])[P1,P2]--origin)*unitvector(P0);
  P22=arclength((.5[ratio,1])[P5,P7]--origin)*unitvector(P0);

  P12=P2 rotatedaround(P0,twist);
  P13=P3 rotatedaround(P0,twist);
  P16=P6 rotatedaround(P0,twist);
  P17=P7 rotatedaround(P0,twist);
  P23=P21 rotatedaround(P0,twist);
  P24=P22 rotatedaround(P0,twist);


  P14=ratio[P1,P12];
  P18=ratio[P5,P17];

  qa=P1--P12--P13--cycle;
  qb=P5--P16--P17--cycle;
  qc=P14--P12...P24...P18--P17..P23..cycle;
  fill qa rotated a withcolor col;
  fill qb rotated a withcolor col;
  fill qc rotated a withcolor col;
enddef;

def circle(expr r)=
  fullcircle scaled 2r
enddef;

def radius(expr i)=
  (((i+10*i*i)/1000)*u)
enddef;

color cola,colb;
cola=.9(1,1,0);
colb=.8white;

cola:=.9(1,1,0);
colb:=.7green;

nc=16;
n=16;
da=360/n;
shift=0.4;
path p[];
pair A[],B[];

%beginfig(1);

  fill unitsquare shifted (-.5,-.5) scaled 3u withcolor cola;
  z0=origin ;
  if false:
  for i=1 upto nc:
    draw circle(radius(i));
  endfor;

  pickup pencircle scaled 5pt;
  for i=1 upto nc:
    for j=1 upto n:
      draw radius(i)*dir((j+i/2)*da) withcolor red;
      draw radius(i)*dir((j+i/2-shift)*da) withcolor green;
    endfor;
  endfor;

  pickup pencircle scaled .5;

  fi;


  p1=(radius(1)*dir((1+1/2-shift)*da))
  for i=2 upto nc:
    ..(radius(i)*dir((1+i/2-shift)*da))
  endfor;
  p2=p1 rotated (shift*da);
  p3=(radius(1)*dir((1+1/2-shift)*da))
  for i=2 upto nc:
    ..(radius(i)*dir((1-i/2-shift)*da))
  endfor;
  p4=p3 rotated (shift*da);

  if false:
  for j=1 upto n:
    draw p1 rotated (j*da);
    draw p2 rotated (j*da);
    draw p3 rotated (j*da);
    draw p4 rotated (j*da);
  endfor;
  fi;

  p5=p1--(reverse p2)--cycle;
  %fill p5 withcolor .8white;
  p6=p2--(reverse (p1 rotated da))--cycle;
  %fill p6 withcolor .8green;

  p7=p3--(reverse p4)--cycle;
  %fill p7 withcolor .8blue;
  p8=p4--(reverse (p3 rotated da))--cycle;
  %fill p8 withcolor .8red;

  for j=1 upto n:
    fill p7 rotated (j*da) withcolor colb;
  endfor;
  for j=1 upto n:
    fill p5 rotated (j*da) withcolor colb;
  endfor;


  pickup pencircle scaled 5pt;
  for i=1 upto nc-1:
    A[i]=p1 intersectionpoint (p4 rotated (i*da));
    B[i]=p2 intersectionpoint (p3 rotated (i*da+da));
    %draw A[i] withcolor (1,1,0);
    %draw B[i] withcolor (1,0,1);
  endfor;

  pickup pencircle scaled .5;
  for i=2 upto nc-1:
    for j=1 upto n:
      twisted_cord(i,3,j*da,(i/nc)[colb,black]);
    endfor;
  endfor;

  clip currentpicture to unitsquare shifted (-.5,-.5) scaled 3u;

  picture lab;
  % intentionally slightly shifted to the right
  lab=thelabel(btex Fraser's spiral etex,z0+.1u*right);
  unfill bbox lab;
  draw lab withcolor red;

%endfig;

%end

endfig;
end;