Debian Codegraph @

texmf-dist/doc/metapost/featpost/example/resistcircuit.mp

raw
1 % resistcircuit.mp
2 % L. Nobre G.
3 % IYP (2005)
4
5 input featpost3Dplus2D;
6
7 prologues := 1;
8
9 beginfig(1);
10 boolean kind[];
11 numeric largmolas, lengmolas, numolas, numturns, u, i, fraction, stepx;
12 numeric totalx, totaly, actuax, actuay, numparal, numserie, stepy;
13 path refpath;
14 pair refpoint, startpoint, ini, fin;
15 pickup pencircle scaled 2pt;
16 fraction = 0.6;
17 numolas = 9;
18 u = 2mm;
19 largmolas = 2u;
20 lengmolas = 12u;
21 numturns = 10;
22 actuax = 1;
23 actuay = 1;
24 numparal = 0;
25 numserie = 1;
26 stepy = largmolas/fraction;
27 stepx = 0.5*(1-fraction)*lengmolas;
28 draw (left*stepx)--origin;
29 for i=2 upto numolas:
30 if uniformdeviate(2) > 1:
31 kind[i] = false;
32 numserie := incr( numserie );
33 else:
34 kind[i] = true;
35 numparal := incr( numparal );
36 fi;
37 endfor;
38 totalx = numserie*lengmolas;
39 totaly = numparal*stepy;
40 draw (right*totalx)--(right*(totalx+stepx));
41 startpoint = (up*0.5*totaly);
42 refpoint = startpoint;
43 draw (down*0.5*totaly)--refpoint;
44 refpath = springpath(origin,right*lengmolas,numturns,largmolas,fraction);
45 draw refpath shifted refpoint;
46 refpoint := refpoint + right*lengmolas;
47 for i=2 upto numolas:
48 if kind[i]:
49 ini := startpoint+down*stepy*actuay;
50 fin := ini + 0.5*(actuax-1)*lengmolas*right;
51 draw ini--fin;
52 draw refpath shifted fin;
53 ini := fin + lengmolas*right;
54 fin := ini + 0.5*(actuax-1)*lengmolas*right;
55 draw ini--fin--refpoint;
56 refpoint := refpoint + down*stepy*0.5;
57 actuay := incr( actuay );
58 else:
59 draw refpath shifted refpoint;
60 refpoint := refpoint + right*lengmolas;
61 actuax := incr( actuax );
62 fi;
63 endfor;
64 endfig;
65
66 end.