| 1 |
% convergingspirals.mp |
| 2 |
% L. Nobre G. - a twisted mind... |
| 3 |
% 2007 |
| 4 |
|
| 5 |
prologues := 1; |
| 6 |
|
| 7 |
vardef oper( expr Valu, Slop ) = |
| 8 |
(Valu*Slop) |
| 9 |
enddef; |
| 10 |
|
| 11 |
vardef hiperspiral( expr Val, Phi, Pitch ) = |
| 12 |
dir(57.29578*Val*(Pitch**2)+Phi)/oper(Val,Pitch) |
| 13 |
enddef; |
| 14 |
|
| 15 |
beginfig(5); %%%%%%%%%%%%%% This figure has one very small bug... %%%%%%% |
| 16 |
boolean adddepth; |
| 17 |
adddepth = true; |
| 18 |
pi = 3.14159; |
| 19 |
co = 180/pi; |
| 20 |
mar = 0.20cm; |
| 21 |
prmax = 6cm; |
| 22 |
prmin = 0.85cm; |
| 23 |
hrmax = 7cm; |
| 24 |
ptmax = 1.699*pi; |
| 25 |
pstpnum = 100; |
| 26 |
numarquid = 5; |
| 27 |
multipl = 5; %%%%%%%%%%%%%%% must be odd for checkerboard %%%%%%%%%%%%%% |
| 28 |
checkerdepth = multipl+3; |
| 29 |
fac = hrmax/prmax; |
| 30 |
alfa = 2*pi/numarquid; |
| 31 |
pitcha = prmax/ptmax; |
| 32 |
pitchb = prmax/(ptmax-alfa); |
| 33 |
numhiperb = numarquid*multipl; |
| 34 |
ptstp = ptmax/pstpnum; |
| 35 |
ptstb = (ptmax-alfa)/pstpnum; |
| 36 |
umin = prmax/10; |
| 37 |
vmin = prmax/20; |
| 38 |
ustp = (hrmax-umin)/pstpnum; |
| 39 |
vstp = (hrmax-vmin)/pstpnum; |
| 40 |
|
| 41 |
path n[]m[], c[], cutter; |
| 42 |
cutter = fullcircle rotated 180 scaled (2prmin); |
| 43 |
for i=1 upto 8: |
| 44 |
n0m[i] = origin; |
| 45 |
endfor; |
| 46 |
for i=1 upto pstpnum: |
| 47 |
tp := i*ptstp; |
| 48 |
tb := i*ptstb; |
| 49 |
pu := umin+i*ustp; |
| 50 |
vu := vmin+i*vstp; |
| 51 |
n0m1 := n0m1--dir(co*tp)*(pitcha*tp+mar); |
| 52 |
n0m2 := n0m2--dir(co*tp)*pitcha*tp; |
| 53 |
n0m3 := n0m3--dir(co*(tb+alfa))*pitchb*tb; |
| 54 |
n0m4 := n0m4--dir(co*(tb+alfa))*(pitchb*tb-mar); |
| 55 |
n0m5 := n0m5--dir(co*pitcha/pu)*(pu-fac*mar); |
| 56 |
n0m6 := n0m6--dir(co*pitcha/pu)*pu; |
| 57 |
n0m7 := n0m7--dir(co*pitchb/vu)*vu; |
| 58 |
n0m8 := n0m8--dir(co*pitchb/vu)*(vu+fac*mar); |
| 59 |
endfor; |
| 60 |
pair flast, hlast; |
| 61 |
flast = point pstpnum of n0m6; |
| 62 |
hlast = point pstpnum of n0m8; |
| 63 |
adif = angle( hlast ) - angle( flast ); |
| 64 |
n0m5 := n0m5 rotated adif; |
| 65 |
n0m6 := n0m6 rotated adif; |
| 66 |
for i=1 upto 8: |
| 67 |
n0m[i] := (reverse n0m[i]) cutafter cutter ; |
| 68 |
endfor; |
| 69 |
for j=1 upto numarquid: |
| 70 |
for i=1 upto 4: |
| 71 |
n[j]m[i] := n0m[i] rotated (j*alfa*co); |
| 72 |
% draw n[j]m[i]; |
| 73 |
endfor; |
| 74 |
endfor; |
| 75 |
for j=1 upto numhiperb: |
| 76 |
for i=5 upto 8: |
| 77 |
n[j]m[i] := n0m[i] rotated (j*360/numhiperb); |
| 78 |
% draw n[j]m[i]; |
| 79 |
endfor; |
| 80 |
endfor; |
| 81 |
distance = pstpnum; |
| 82 |
actualspik = 0; |
| 83 |
boolean intersectexists; |
| 84 |
pair itstm; |
| 85 |
for i=1 upto numhiperb: |
| 86 |
itstm := n1m2 intersectiontimes n[i]m6; |
| 87 |
intersectexists := ( itstm dotprod (-1,1) ) <> 0; |
| 88 |
if intersectexists: |
| 89 |
if ( (xpart itstm) < distance ): |
| 90 |
distance := xpart itstm; |
| 91 |
actualspik := i; |
| 92 |
fi; |
| 93 |
fi; |
| 94 |
endfor; |
| 95 |
numeric seq[]; |
| 96 |
seq0 = actualspik; |
| 97 |
for i=1 upto 2checkerdepth: |
| 98 |
if (seq[i-1]-1<1): |
| 99 |
seq[i] := numhiperb; |
| 100 |
else: |
| 101 |
seq[i]=seq[i-1]-1; |
| 102 |
fi; |
| 103 |
endfor; |
| 104 |
path ca, cb; |
| 105 |
ca = (reverse n1m3)--n1m2; |
| 106 |
cb = (reverse n[seq1]m7)--n[seq1]m6; |
| 107 |
c0 = buildcycle( cb, reverse n1m1 ); %%%%% may reverse |
| 108 |
c1 = buildcycle( ca, n[seq0]m8 ); |
| 109 |
for i=2 step 2 until 2checkerdepth: |
| 110 |
if i < 2*multipl-1 : |
| 111 |
ca := (reverse n[seq[i-2]]m6)--n[seq[i-2]]m7; |
| 112 |
c[i] := buildcycle( ca, n2m1 ); |
| 113 |
else: |
| 114 |
c[i]:=buildcycle(n[seq[i-2]]m7,n2m1,reverse n[seq[i-2]]m6,reverse n0m4); |
| 115 |
fi; |
| 116 |
c[i+1]:=buildcycle(n[seq[i-2]]m5,n1m3,reverse n[seq[i]]m8,reverse n1m2); |
| 117 |
endfor; |
| 118 |
if adddepth: |
| 119 |
depthadded = 1; |
| 120 |
else: |
| 121 |
depthadded = 0; |
| 122 |
fi; |
| 123 |
for i=1 step 2 until 2*checkerdepth+depthadded: |
| 124 |
for j=1 upto numarquid: |
| 125 |
fill c[i-1] rotated (j*alfa*co) withcolor 0.85*(red+green); |
| 126 |
fill c[i] rotated (j*alfa*co) withcolor 0.7*green; |
| 127 |
endfor; |
| 128 |
endfor; |
| 129 |
if not (multipl <> 5): |
| 130 |
cb := (reverse n[seq3]m7)--n[seq3]m6; |
| 131 |
ca := buildcycle( cb, reverse n1m1 ); %%%%% may reverse |
| 132 |
for j=1 upto numarquid: |
| 133 |
fill ca rotated (j*alfa*co) withcolor 0.85*(red+green); |
| 134 |
endfor; |
| 135 |
fi; |
| 136 |
endfig; |
| 137 |
|
| 138 |
beginfig(4); |
| 139 |
numeric pstpnum, prmax, i, j, pi, ptmax, ptstp, th, co, mar; |
| 140 |
numeric numarquid, numhiperb, multipl, pitcha, pitchb, alfa; |
| 141 |
path a, b, c, d, e, f, g, h; |
| 142 |
numeric ptstb, hrmax, fac, sn, sm, rn, rm; |
| 143 |
pi = 3.14159; |
| 144 |
co = 180/pi; |
| 145 |
mar = 0.16mm; |
| 146 |
prmax = 5mm; |
| 147 |
hrmax = 7mm; |
| 148 |
ptmax = 1.05*pi; |
| 149 |
pstpnum = 100; |
| 150 |
numarquid = 5; |
| 151 |
multipl = 1; |
| 152 |
rn = 4; |
| 153 |
rm = 2; |
| 154 |
sn = 8; |
| 155 |
sm = 6; |
| 156 |
fac = hrmax/prmax; |
| 157 |
alfa = 2*pi/numarquid; |
| 158 |
pitcha = prmax/ptmax; |
| 159 |
pitchb = prmax/(ptmax-alfa); |
| 160 |
numhiperb = numarquid*multipl; |
| 161 |
ptstp = ptmax/pstpnum; |
| 162 |
ptstb = (ptmax-alfa)/pstpnum; |
| 163 |
a = origin; |
| 164 |
b = origin; |
| 165 |
c = origin; |
| 166 |
d = origin; |
| 167 |
for i=1 upto pstpnum: |
| 168 |
th := i*ptstp; |
| 169 |
a := a--dir(co*th)*pitcha*th; |
| 170 |
b := b--dir(co*th)*(pitcha*th+mar); |
| 171 |
endfor; |
| 172 |
for i=1 upto pstpnum: |
| 173 |
th := i*ptstb; |
| 174 |
c := c--dir(co*(th+alfa))*pitchb*th; |
| 175 |
d := d--dir(co*(th+alfa))*(pitchb*th-mar); |
| 176 |
endfor; |
| 177 |
for i=1 upto numarquid: |
| 178 |
% unfill buildcycle( b , reverse d ) rotated (i*alfa*co); |
| 179 |
fill a--reverse c--cycle rotated (i*alfa*co); |
| 180 |
% draw a rotated (i*alfa*co) withcolor red+green; |
| 181 |
% draw b rotated (i*alfa*co) withcolor red; |
| 182 |
% draw c rotated (i*alfa*co) withcolor green; |
| 183 |
% draw d rotated (i*alfa*co) withcolor blue; |
| 184 |
endfor; |
| 185 |
numeric umin, vmin, ustp, vstp, pu, pv; |
| 186 |
umin = prmax/20; |
| 187 |
vmin = prmax/20; |
| 188 |
ustp = (hrmax-umin)/pstpnum; |
| 189 |
vstp = (hrmax-vmin)/pstpnum; |
| 190 |
e = origin; |
| 191 |
f = origin; |
| 192 |
g = origin; |
| 193 |
h = origin; |
| 194 |
for i=1 upto pstpnum: |
| 195 |
pu := umin+i*ustp; |
| 196 |
e := e--dir(co*pitcha/pu)*(pu-((fac*mar)**2)); |
| 197 |
f := f--dir(co*pitcha/pu)*pu; |
| 198 |
vu := vmin+i*vstp; |
| 199 |
g := g--dir(co*pitchb/vu)*(vu+sqrt(fac*mar)); |
| 200 |
h := h--dir(co*pitchb/vu)*vu; |
| 201 |
endfor; |
| 202 |
pair flast, hlast; |
| 203 |
numeric adif; |
| 204 |
path hiperbolio, hiperbolic; |
| 205 |
flast = point pstpnum of f; |
| 206 |
hlast = point pstpnum of h; |
| 207 |
adif = angle( hlast ) - angle( flast ); |
| 208 |
% draw e withcolor red+blue; |
| 209 |
% draw f withcolor red+blue; |
| 210 |
% draw g rotated (-adif) withcolor green+blue; |
| 211 |
% draw h rotated (-adif) withcolor green+blue; |
| 212 |
hiperbolio = (subpath (rn,pstpnum) of g rotated (-adif))... |
| 213 |
(subpath (pstpnum,rm) of e)..cycle; |
| 214 |
hiperbolic = (subpath (sn,pstpnum) of h rotated (-adif))... |
| 215 |
(subpath (pstpnum,sm) of f)..cycle; |
| 216 |
for i=1 upto numhiperb: |
| 217 |
unfill hiperbolio rotated (i*360/numhiperb); |
| 218 |
endfor; |
| 219 |
for i=1 upto numhiperb: |
| 220 |
fill hiperbolic rotated (i*360/numhiperb) withcolor 0.4*red+0.2*blue; |
| 221 |
endfor; |
| 222 |
picture storepic; |
| 223 |
storepic = currentpicture; |
| 224 |
currentpicture := nullpicture; |
| 225 |
draw storepic scaled 12; |
| 226 |
endfig; |
| 227 |
|
| 228 |
beginfig(3); |
| 229 |
numeric pstpnum, prmax, i, j, pi, ptmax, ptstp, th, co, mar; |
| 230 |
numeric numarquid, numhiperb, multipl, pitcha, pitchb, alfa; |
| 231 |
path a, b, c, d; |
| 232 |
pi = 3.14159; |
| 233 |
co = 180/pi; |
| 234 |
mar = 0.32; |
| 235 |
prmax = 5; |
| 236 |
ptmax = 4*pi; |
| 237 |
pstpnum = 100; |
| 238 |
multipl = 3; |
| 239 |
numarquid = 3; |
| 240 |
alfa = 2*pi/numarquid; |
| 241 |
pitcha = prmax/ptmax; |
| 242 |
pitchb = prmax/(ptmax-alfa); |
| 243 |
numhiperb = numarquid*multipl; |
| 244 |
ptstp = ptmax/pstpnum; |
| 245 |
a = origin; |
| 246 |
b = origin; |
| 247 |
c = origin; |
| 248 |
d = origin; |
| 249 |
for i=1 upto pstpnum: |
| 250 |
th := i*ptstp; |
| 251 |
a := a...dir(co*th)*pitcha*th; |
| 252 |
b := b...dir(co*th)*(pitcha*th-mar); |
| 253 |
c := c...dir(co*(th+alfa))*pitchb*th; |
| 254 |
d := d...dir(co*(th+alfa))*(pitchb*th+mar); |
| 255 |
endfor; |
| 256 |
for i=1 upto numarquid: |
| 257 |
drawoptions( rotated (i*alfa*co) scaled 1000 withpen pencircle scaled 0pt); |
| 258 |
draw a; |
| 259 |
draw b; |
| 260 |
draw c; |
| 261 |
draw d; |
| 262 |
endfor; |
| 263 |
%%%%%%%%%%%%%%%%%%%%%%%% A very nice case of knitting Bezier splines... |
| 264 |
endfig; |
| 265 |
|
| 266 |
beginfig(2); |
| 267 |
numeric u, numb, faca, numa, numc, rmin, rmax, i, j, pitch, phi; |
| 268 |
numeric petch, startang, angstep, ampi, ampe, arcstep, paperfactor; |
| 269 |
path b[], base, a[], alto; |
| 270 |
numeric valmax, valmin, valstep, valhmin, valhmax; |
| 271 |
u = 15mm; |
| 272 |
numb = 2; % start at one |
| 273 |
faca = 7; |
| 274 |
numc = 9; |
| 275 |
rmin = 0.3; |
| 276 |
rmax = 1.5; |
| 277 |
paperfactor = 0.25*u/rmin; |
| 278 |
angstep = 1/30; |
| 279 |
valstep = 0.017; |
| 280 |
numa = numb*faca; |
| 281 |
startang = 1/numb; |
| 282 |
arcstep = 1/numa; |
| 283 |
ampi = numc/faca; |
| 284 |
ampe = ampi-startang; |
| 285 |
pitch = (rmax-rmin)/ampi; %show pitch; |
| 286 |
petch = (rmax-rmin)/ampe; %show petch; |
| 287 |
valmin = 1/oper(rmax,pitch); |
| 288 |
valmax = 1/oper(rmin,pitch); |
| 289 |
valhmin = 1/oper(rmax,petch); |
| 290 |
valhmax = 1/oper(rmin,petch); |
| 291 |
for i=1 step 2 until 2*numb: |
| 292 |
phi := 0.5*i/numb; |
| 293 |
b[i-1] = dir(phi*360)*rmin for j=angstep step angstep until ampi: |
| 294 |
...dir((phi+j)*360)*(rmin+pitch*j) |
| 295 |
endfor; |
| 296 |
b[i] = dir((phi+startang)*360)*rmin for j=angstep step angstep until ampe: |
| 297 |
...dir((phi+startang+j)*360)*(rmin+petch*j) |
| 298 |
endfor; |
| 299 |
endfor; |
| 300 |
base = for i=1 step 2 until 2*numb: b[i-1]...reverse b[i]-- endfor cycle; |
| 301 |
fill base scaled paperfactor; |
| 302 |
for i=1 step 2 until 2*numa: |
| 303 |
phi := 0.5*(i-1)*arcstep*360; |
| 304 |
a[i-1] = hiperspiral(valmin,phi,pitch) |
| 305 |
for j=valmin+valstep step valstep until valmax: |
| 306 |
...hiperspiral(j,phi,pitch) |
| 307 |
endfor; |
| 308 |
draw a[i-1] scaled paperfactor withcolor red+green; |
| 309 |
phi := 0.5*i*arcstep*360; |
| 310 |
a[i] = hiperspiral(valhmin,phi,petch) |
| 311 |
for j=valhmin+valstep step valstep until valhmax: |
| 312 |
...hiperspiral(j,phi,petch) |
| 313 |
endfor; |
| 314 |
draw a[i] scaled paperfactor withcolor red; |
| 315 |
endfor; |
| 316 |
endfig; |
| 317 |
|
| 318 |
beginfig(1); |
| 319 |
numeric u, numb, faca, numa, numc, rmin, rmax, i, j, pitch, phi; |
| 320 |
numeric petch, startang, angstep, ampi, ampe, arcstep; |
| 321 |
path b[], base, a[], alto; |
| 322 |
u = 15mm; |
| 323 |
numb = 3; % start at one |
| 324 |
faca = 3; |
| 325 |
numc = 5; |
| 326 |
rmin = 2u; |
| 327 |
rmax = 10u; |
| 328 |
angstep = 1/90; % If too big, the figure may be broken... |
| 329 |
numa = numb*faca; |
| 330 |
ampi = numc/faca; |
| 331 |
pitch = (rmax-rmin)/ampi; |
| 332 |
startang = 1/numb; |
| 333 |
arcstep = 1/numa; |
| 334 |
ampe = numc/faca-startang; |
| 335 |
petch = (rmax-rmin)/ampe; |
| 336 |
for i=1 step 2 until 2*numb: |
| 337 |
phi := 0.5*i/numb; |
| 338 |
b[i-1] = dir(phi*360)*rmin for j=angstep step angstep until ampi: |
| 339 |
...dir((phi+j)*360)*(rmin+pitch*j) |
| 340 |
endfor; |
| 341 |
b[i] = dir((phi+startang)*360)*rmin for j=angstep step angstep until ampe: |
| 342 |
...dir((phi+startang+j)*360)*(rmin+petch*j) |
| 343 |
endfor; |
| 344 |
endfor; |
| 345 |
base = for i=1 step 2 until 2*numb: b[i-1]...reverse b[i]-- endfor cycle; |
| 346 |
fill base withcolor red; |
| 347 |
for i=1 step 2 until 2*numa: |
| 348 |
phi := 0.5*i/numa; |
| 349 |
a[i-1] = dir(phi*360)*rmin for j=angstep step angstep until 0.5: |
| 350 |
...dir(-(phi+j)*360)*(rmin+2*(rmax-rmin)*j) |
| 351 |
endfor; |
| 352 |
a[i] = dir((phi+arcstep)*360)*rmin |
| 353 |
for j=angstep step angstep until 0.5-arcstep: |
| 354 |
...dir(-(phi+arcstep+j)*360)*(rmin+(rmax-rmin)/(0.5-arcstep)*j) |
| 355 |
endfor; |
| 356 |
endfor; |
| 357 |
alto = for i=1 step 2 until 2*numa: a[i-1]...reverse a[i]-- endfor cycle; |
| 358 |
fill alto withcolor green+blue; |
| 359 |
endfig; |
| 360 |
|
| 361 |
end. |