From ac3c55a3216b5988f0e48ba9414ddb059f19a699 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Wed, 11 Jan 2006 22:58:36 +0000 Subject: trunk/Master/texmf-dist/metapost git-svn-id: svn://tug.org/texlive/trunk@104 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/metapost/makecirc/ejemplos.mp | 307 ++++++++ Master/texmf-dist/metapost/makecirc/latex.mp | 246 ++++++ Master/texmf-dist/metapost/makecirc/makecirc.mp | 981 ++++++++++++++++++++++++ 3 files changed, 1534 insertions(+) create mode 100644 Master/texmf-dist/metapost/makecirc/ejemplos.mp create mode 100644 Master/texmf-dist/metapost/makecirc/latex.mp create mode 100644 Master/texmf-dist/metapost/makecirc/makecirc.mp (limited to 'Master/texmf-dist/metapost/makecirc') diff --git a/Master/texmf-dist/metapost/makecirc/ejemplos.mp b/Master/texmf-dist/metapost/makecirc/ejemplos.mp new file mode 100644 index 00000000000..3b1953be694 --- /dev/null +++ b/Master/texmf-dist/metapost/makecirc/ejemplos.mp @@ -0,0 +1,307 @@ +input makecirc; + +initlatex("\usepackage{amsmath,amssymb}"); + + +beginfig(1); + source.a(origin, AC, 90,"v","220 V"); + resistor.a(S.a.p+(2cm,1cm),normal,0,"R","5\ohm"); + centreof.A(R.a.r+(2cm,0),(xpart R.a.r + 2cm,ypart S.a.n - 1cm),cap); + capacitor.a(c.A,normal,phi.A,"C",""); + wire(S.a.p,R.a.l,udsq); + wire(R.a.r,C.a.l,rlsq); + wireU(S.a.n,C.a.r,-1cm,udsq); + imesh(S.a.n+(3cm,5mm),25mm,15mm,cw,0,"i(t)"); +endfig; + +beginfig(2); + source.a(origin, AC, 90,"v","220 V"); + resistor.a(S.a.p+(2cm,1cm),normal,0,"R","15\ohm"); + inductor.a(R.a.r+(2cm,-10mm),Up,-90,"L",""); + wire(S.a.p,R.a.l,udsq); + wire(R.a.r,L.a.l,rlsq); + wireU(S.a.n,L.a.r,-1cm,udsq); +endfig; + +beginfig(3); + source.a(origin,AC,90,"v","220 V"); + resistor.a(S.a.p+(2cm,1cm),normal,0,"R","15\ohm"); + inductor.a(R.a.r+(2cm,-10mm),Up,-90,"L","5 H"); + centerto.A(R.a.l,R.a.r)(-3.2cm,cap); + capacitor.a(A,normal,0,"C","12 pF"); + wire(S.a.p,R.a.l,udsq); + wire(R.a.r,L.a.l,rlsq); + wire(S.a.n,C.a.l,udsq); + wire(C.a.r,L.a.r,rlsq); +endfig; + +beginfig(4); + source.a(origin,AC,90,"v",""); + resistor.a(S.a.n+(2cm,5mm),normal,90,"R_L",""); + inductor.a(R.a.l,Down,-90,"L",""); + resistor.b(R.a.l+(2cm,0),normal,90,"R_C",""); + capacitor.a(R.b.l,normal,-90,"C",""); + wireU(S.a.p,R.a.r,1cm,udsq); + wireU(S.a.n,L.a.r,-1cm,udsq); + wire((xpart R.a.r,ypart S.a.p + 1cm),R.b.r,rlsq); + wire(C.a.r,(xpart L.a.r,ypart S.a.n-1cm),udsq); +endfig; + +beginfig(5); + source.a(origin,AC,90,"v",""); + diode.a(S.a.p+(1cm,1cm),normal,0,pinA,"D_r",""); + impedance.a(D.a.K+(1cm,-1cm),-90,"Z_L",""); + wire(S.a.p,D.a.A,udsq); + wire(D.a.K,Z.a.l,rlsq); + wireU(S.a.n,Z.a.r,-1cm,udsq); +endfig; + +beginfig(6); + transformer.a(origin,mid,0); + diode.a(tf.a.ss+(1cm,1cm),normal,0,pinA,"D_1",""); + diode.b(tf.a.si+(1cm,-1cm),normal,0,pinA,"D_2",""); + impedance.a(D.a.K+(3cm,-4mm),-90,"Z_L","300\ohm"); + wire(tf.a.ss,D.a.A,udsq); + wire(tf.a.si,D.b.A,udsq); + wire(D.a.K,Z.a.l,rlsq); + wire(Z.a.r,tf.a.m,udsq); + wire(D.b.K,D.a.K+(1cm,0),rlsq); + junction.a(D.a.K+(1cm,0),"")(top); + centerto.A(tf.a.pi,tf.a.ps)(-25mm,sac); + source.a(A,AC,90,"v","220 V"); + wire(S.a.p,tf.a.ps,udsq); + wire(S.a.n,tf.a.pi,udsq); + centreof.A((xpart S.a.p,ypart tf.a.ps),tf.a.ps,cur); + current.a(c.A,phi.A,"i(t)","5 A"); + imesh(tf.a.ss+(2cm,0),3cm,1cm,cw,0,"I_{cc}"); +endfig; + +beginfig(7); + source.a(origin,AC,90,"v",""); + junction.a(S.a.p+(3cm,1cm),"")(top); + diode.a(J.a,normal,-45,pinA,"D_1",""); + diode.b(D.a.K,normal,-135,pinK,"D_2",""); + diode.c(D.b.A,normal,135,pinK,"D_3",""); + diode.d(D.c.A,normal,45,pinA,"D_4",""); + junction.b(D.b.A,"")(bot); + centerto.A(S.a.n,S.a.p)(5cm,imp); + impedance.a(A,90,"Z_L",""); + wireU(S.a.p,D.a.A,1.5cm,udsq); + wireU(S.a.n,D.b.A,-1.5cm,udsq); + wire(D.a.K,Z.a.r,rlsq); + wire(Z.a.l,Z.a.l+(0,-4mm),nsq); + wireU(Z.a.l+(0,-4mm),D.d.A,-4cm,rlsq); +endfig; + +beginfig(8); + junction.a(origin,"1b")(bot); + junction.b((0,4cm),"1a")(top); + resistor.a((1cm,4cm),normal,0,"R_1","0,82\ohm"); + inductor.a(R.a.r,Up,0,"X_{L1}","0,92\ohm"); + centerto.A(J.a,J.b,4cm,res); + resistor.b(A,normal,90,"G_{\phi}","0,41"); + centerto.B(J.a,J.b,6cm,ind); + inductor.b(B,Down,90,"B_{\phi}","2,24"); + inductor.c(L.a.r+(2.6cm,0),Up,0,"X'_{L2}","0,9\ohm"); + resistor.c(L.c.r,normal,0,"R'_2","0,8\ohm"); + junction.c(R.c.r+(1cm,0),"2a")(top); + junction.d(R.c.r+(1cm,-4cm),"2b")(bot); + wire(J.a,J.d,nsq); + wire(J.b,R.a.l,nsq); + wireU(R.b.r,L.b.r,3mm,udsq); + wireU(R.b.l,L.b.l,-3mm,udsq); + wire(L.a.r,(5cm,ypart R.b.r + 3mm),rlsq); + wire((5cm,ypart R.b.l - 3mm),(5cm,0),nsq); + wire(R.c.r,J.c,nsq); + wire(L.c.l,(5cm,ypart L.c.l),nsq); + ctext(J.a,J.b,"$V_1$",noarrow); + ctext(J.c,J.d,"$V'_2$",noarrow); +endfig; + +beginfig(9); + rheostat.a(origin,Lrheo,0); + wire(rh.a.s,rh.a.s+(-1cm,0),udsq); + wire(rh.a.i,(-1cm,0),nsq); + transformer.a((5cm,0),normal,0); + meains.a(tf.a.ps-(1cm,0),ampere,180,""); + meains.b((xpart rh.a.r + 5mm,ypart tf.a.ps),watt,0,""); + centerto.A(tf.a.pi,tf.a.ps,-1cm,ins); + centerto.B(mi.a.r,mi.b.r,0,0); + meains.c((xpart B,ypart A),volt,90,""); + wire(rh.a.i,tf.a.pi,nsq); + wire(rh.a.r,mi.b.l,udsq); + wire(mi.b.r,mi.a.r,nsq); + wire(B,mi.c.r,nsq); + wire(mi.c.l,(xpart B,0),nsq); + wire(mi.b.p,(xpart mi.b.p,0),nsq); + wire(mi.a.l,tf.a.ps,nsq); + wireU(tf.a.si,tf.a.ss,1cm,rlsq); + current(mi.b.l-(2mm,0),0,"I_1",""); +endfig; + +beginfig(10); + generator.a(origin,90,"E_g",""); + resistor.a(G.a.B,normal,90,"R_a",""); + resistor.f(G.a.D-(2cm,0),normal,90,"",""); + resistor.F(R.f.r,variable,90,"",""); + resistor.L(G.a.B+(2cm,-5mm),normal,90,"R_L",""); + current.a(R.a.r,90,"I_a",""); + wireU(i.a.d,R.L.r,5mm,udsq); + wireU(G.a.D,R.L.l,-5mm,udsq); + wire(i.a.d+(0,5mm),R.F.r,rlsq); + wire(R.f.l,G.a.D-(0,5mm),udsq); + ctext(R.f.l-(5mm,0),R.F.r-(5mm,0),"$R_f$",noarrow); + current.f(i.a.d+(-1cm,5mm),180,"","$I_f$"); + current.L(i.a.d+(1cm,5mm),0,"I_L",""); + ctext.lft(R.f.l-(1cm,5mm),(xpart R.F.r-1cm,ypart i.a.d+5mm),"$V_f$",witharrow); + ctext.rt((xpart R.L.l+1cm,-5mm),(xpart R.L.r+1cm,ypart i.a.d+5mm),"$V_L$",witharrow); +endfig; + +beginfig(11); + generator.a(origin,90,"E_g","500 V"); + resistor.a(G.a.B,normal,90,"R_a",""); + current.a(G.a.D+(2mm,-1cm),0,"I_a",""); + junction.A(i.a.d+(2mm,0),"A")(top); + current.s(J.A+(4mm,0),0,"I_s",""); + resistor.s(i.s.d,normal,0,"R_s",""); + junction.B(R.s.r+(2mm,0),"B")(top); + current.d(J.A+(4mm,-1cm),0,"I_d","54 A"); + resistor.d(i.d.d,variable,0,"R_d",""); + current.f(J.B+(2mm,5mm),90,"I_f",""); + current.L(J.B+(1cm,0),0,"I_L",""); + resistor.L(i.L.d+(1cm,1.25cm),normal,90,"R_L",""); + resistor.f(i.f.d+(0,2mm),normal,90,"",""); + resistor.F(R.f.r,variable,90,"",""); + wire(R.F.r,R.a.r,rlsq); + wire(R.F.r,R.L.r,rlsq); + wire(R.L.l,J.B,udsq); + wire(J.B+(2mm,0),R.f.l,nsq); + wire(J.B,R.d.r,udsq); + wire(R.d.l,J.A,rlsq); + wire(J.A,R.s.l,nsq); + wire(R.s.r,J.B,nsq); + wire(J.A,G.a.D,rlsq); + puttext("$R_f$",R.f.r-(5mm,0)); +endfig; + +beginfig(12); + junction.a(origin,"")(bot); + junction.b((0,4cm),"")(top); + ctext.lft(J.a,J.b,"$V_a=V_L=120\,\text{V}$",witharrow); + current.L(J.b+(5mm,0),0,"I_L",""); + current.f(i.L.d+(5mm,-5mm),-90,"I_f",""); + current.a(i.L.d+(2cm,0),0,"I_a",""); + resistor.a(i.a.d+(15mm,-8mm),normal,-90,"R_a","0,25\ohm"); + motor.a(R.a.r,-90,"E_c",""); + resistor.f(i.f.d,normal,-90,"",""); + resistor.F(R.f.r,variable,-90,"",""); + puttext("$R_f$",R.f.r+(5mm,0)); + wire(J.b,R.a.l,rlsq); + wire(J.a,M.a.B,rlsq); + wire(i.f.s+(0,5mm),R.f.l,nsq); + wire(R.F.r,(xpart R.F.r,0),nsq); +endfig; + +beginfig(13); + junction.a(origin,"")(bot); + rheostat.a((5mm,2cm),Rrheo,0); + junction.b(rh.a.s-(5mm,0),"")(top); + resistor.a(rh.a.r+(2cm,0),normal,-90,"R_a","0,2\ohm"); + motor.a((xpart R.a.r,0),90,"E_c",""); + resistor.F(R.a.l+(2cm,0),variable,-90,"",""); + resistor.f((xpart R.F.l,0),normal,90,"",""); + wire(J.b,rh.a.s,nsq); + wire(rh.a.r,R.a.l,nsq); + wire(R.a.l,R.F.l,nsq); + wire(R.F.r,R.f.r,nsq); + wire(R.a.r,M.a.B,nsq); + wire(J.a,R.f.l,nsq); + ctext(J.a,J.b,"$V_a$",noarrow); +endfig; + +beginfig(14); + transistor.a(origin,pnp,0); + junction.B(T.a.B,"B")(top); + junction.E(T.a.E,"E")(llft); + junction.C(T.a.C,"C")(top); + resistor.C(T.a.C+(2cm,-5mm),normal,-90,"R_C",""); + source.CC(R.C.r,DC,-90,"V_{CC}",""); + resistor.B(T.a.B-(2cm,0),normal,-90,"R_B",""); + source.EE(R.B.r,DC,-90,"V_{BB}",""); + capacitor.a(T.a.B-(3cm,0),normal,180,"C_a",""); + junction.a(C.a.r-(1cm,0),"")(top); + junction.b((xpart J.a,ypart S.EE.p-5mm),"")(bot); + wire(T.a.C,R.C.l,rlsq); + wire(T.a.B,C.a.l,nsq); + wire(C.a.r,J.a,nsq); + wireU(S.EE.p,S.CC.p,-5mm,udsq); + wire(J.b,S.EE.p-(0,5mm),nsq); + wire(T.a.E,(xpart T.a.E,ypart S.EE.p-5mm),nsq); + current.E(T.a.E-(0,1cm),90,"I_E",""); + current.C(T.a.C+(5mm,0),0,"I_C",""); + current.B(J.B-(5mm,0),180,"I_B",""); + ctext.lft(J.a,J.b,"$E_1$",witharrow); + wire(R.C.l,R.C.l+(1cm,0),nsq); + wire(R.C.r,R.C.r+(1cm,0),nsq); + ctext.rt(R.C.l+(1cm,0),R.C.r+(1cm,0),"$E_2$",witharrow); +endfig; + +beginfig(15); + source.a(origin,AC,90,"v",""); + diode.a(S.a.p+(1cm,1cm),normal,0,pinA,"D_r",""); + capacitor.a(D.a.K+(5mm,-12mm),electrolytic,-90,"C_e",""); + impedance.a(D.a.K+(2cm,-1cm),-90,"Z_L",""); + wire(S.a.p,D.a.A,udsq); + wire(D.a.K,Z.a.l,rlsq); + wireU(S.a.n,Z.a.r,-1cm,udsq); + wire(D.a.K+(5mm,0),C.a.l,nsq); + wire(C.a.r,(xpart C.a.r,ypart S.a.n-1cm),nsq); +endfig; + +beginfig(16); + transformer.a(origin,mid,0); + diode.a(tf.a.ss+(1cm,1cm),normal,0,pinA,"D_1",""); + diode.b(tf.a.si+(1cm,-1cm),normal,0,pinA,"D_2",""); + capacitor.a(D.a.K+(3cm,-6mm),electrolytic,-90,"C_e",""); + impedance.a(D.a.K+(5cm,-4mm),-90,"Z_L",""); + wire(tf.a.ss,D.a.A,udsq); + wire(tf.a.si,D.b.A,udsq); + wire(D.a.K,Z.a.l,rlsq); + wire(Z.a.r,tf.a.m,udsq); + wire(D.b.K,D.a.K+(1cm,0),rlsq); + junction.a(D.a.K+(1cm,0),"")(top); + centerto.A(tf.a.pi,tf.a.ps)(-25mm,sac); + source.a(A,AC,90,"v",""); + wire(S.a.p,tf.a.ps,udsq); + wire(S.a.n,tf.a.pi,udsq); + wire(D.a.K+(3cm,0),C.a.l,nsq); + wire(C.a.r,(xpart C.a.r,ypart tf.a.m),nsq); +endfig; + +beginfig(17); + inductor.a(origin,Up,90,"",""); + inductor.b(origin,Down,90+120,"",""); + inductor.c(origin,Up,90-120,"",""); + inductor.d(origin,Up,-90,"",""); + inductor.e(origin,Down,-90-120,"",""); + inductor.f(origin,Up,-90+120,"",""); + diode.a((3cm,ypart L.a.r),normal,0,pinA,"",""); + diode.b((3cm,ypart L.b.r-1.2cm),normal,0,pinA,"",""); + diode.c((3cm,ypart L.c.r),normal,0,pinA,"",""); + diode.d((3cm,ypart L.d.r),normal,0,pinA,"",""); + diode.e((3cm,ypart L.e.r+1.2cm),normal,0,pinA,"",""); + diode.f((3cm,ypart L.f.r),normal,0,pinA,"",""); + centerto.A(D.e.K,(xpart D.e.K,0),2cm,imp); + impedance.a(A,90,"Z_L",""); + wire(L.a.r,D.a.A,nsq); + wire(L.b.r,D.b.A,udsq); + wire(L.c.r,D.c.A,nsq); + wire(L.d.r,D.d.A,nsq); + wire(L.e.r,D.e.A,udsq); + wire(L.f.r,D.f.A,nsq); + wire(D.e.K,Z.a.r,rlsq); + wire(Z.a.l,origin,udsq); + wire(D.b.K,D.e.K,nsq); + junction.a(D.e.K,"")(top); +endfig; +end. \ No newline at end of file diff --git a/Master/texmf-dist/metapost/makecirc/latex.mp b/Master/texmf-dist/metapost/makecirc/latex.mp new file mode 100644 index 00000000000..f2f1945ef32 --- /dev/null +++ b/Master/texmf-dist/metapost/makecirc/latex.mp @@ -0,0 +1,246 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% latex.mp Parametrizable latex labels for metapost +%% Copyright (c) 2003 JL Diaz +%% based on an idea taken from Metafun, by Hans Hagen +% +% This program may be distributed and/or modified under the conditions +% of the LaTeX Project Public License, either version 1.2 of this +% license or (at your option) any later version. The latest version +% of this license is in http://www.latex-project.org/lppl.txt and +% version 1.2 or later is part of all distributions of LaTeX version +% 1999/12/01 or later. +% +% This program consists of the file latex.mp +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% For the impatient: Jump to "USAGE" +% +% Introduction: The problem +% +% Let us suppose that you need to typeset several labels of the form +% $x_1$, $x_2$, ... $x_{10}$. Since each label is a formula, the +% construction btex/etex is required to typeset it through TeX (or +% LaTeX). So, the straighforward solution is: +% +% label(btex $x_1$ etex, (1u,0u)); +% label(btex $x_2$ etex, (2u,0u)); +% ... +% label(btex $x_{10}$ etex, (10u,0u)); +% +% This repeated structure is inviting us to convert it into a for +% loop. A naive attempt would be: +% +% for i=1 upto 10: +% label (btex $x_{i}$ etex, (i*u, 0)); +% endfor; +% +% Unfortunately the above would produce ten times the same label +% $x_{i}$, because i is not evaluated in this context as a variable. +% +% A second, more clever attempt would be: +% +% for i=1 upto 10: +% label("btex $x_{" & decimal i & "}$ etex", (i*u, 0)); +% endfor; +% +% where we are making use of the string concatenation operator (&), +% and the "decimal" operator, which produces an string whith the +% decimal representation of its argument. This way, the macro label +% will receive successively as first argument the strings: "btex +% $x_{1}$ etex", "btex $x_{2}$ etex", end so on. +% +% This solution does not work either, because label is receiving a +% string, instead of a picture (which is the result of a proper +% btex/etex construction). When a string is received, label simply +% outputs that string, without calling TeX (LaTeX) for formatting it. +% +% Metapost provides a way of "executing" the code which is stored in +% a string, it is the scantokens primitive. So, it appears that a +% modification of the label primitive would be possible, which +% applies the scantokens primitive on the string which it receives as +% parameter. Unfortunately this does not work either, because the way +% in which btex/etex works procludes it use as argument of +% scantokens. +% +% So, apparently, there is not an easy solution to the problem of +% passing arguments to the etex/btex construct. +% +% The solution +% +% Since the construct btex/etex can only be used at the "top level" +% of a source file, and not embedded in any string, the only way to +% achieve the desired result is to store the string "btex ... etex" +% in an external temporal file, and input back that file. +% +% This solution is implemented in the macro package "TEX.mp" which is +% part of the standard metapost distribution. Using this package, the +% problem of printing the ten labels $x_1$ .. $x_{10}$ becomes simple: +% +% for i=0 upto 10: +% label(TEX("$x_{" & decimal i & "}$", (u*i,0)); +% endfor; +% +% The macro TEX receives an string as argument, and uses TeX to +% typeset it. This is achieved, as already explained, by creating a +% new string which encapsulated the given argument into a btex/etex +% pair, writing this new string in an external file, and inputting +% that file back. +% +% This approach has two main drawbacks: +% +% 1) An external file is created, and processed each time TEX is +% used. This is very inefficient, and the slowdown is noticeable if +% TEX is used often. +% +% 2) If we want to use latex istead of tex, the TEX macro will not +% work, because the external file created through this macro does +% not include the verbatimtex header required to initialize latex. +% +% Metafun approach: a clever solution +% +% In the excelent macro package Metafun (by Hans Hagens), a nice +% solution is found to the first problem. Instead of writing the +% auxiliar file and inputting it again, what is wrote is an auxiliar +% metapost program which defines a serie of picture variables, each +% one with the result of a btex/etex pair. In the first run of +% metapost, this auxiliar file is write-only. In the second run, the +% file is read at the beginning, so all picture variables get +% defined. In this second run, each time the TEX macro is called, it +% checks if the corresponding picture variable is already defined, +% and in this case it simply returns its value. +% +% This approach is much more efficient, since a single externa file +% is produced and processed, no matter how much the TEX macro is +% called. The only drawback is that two metapost runs are required. +% +% latex.mp: my solution +% +% I liked very much the metafun solution, but I did not want to use +% the whole Metafun package only to obtain this +% functionality. Moreover, metafun relies in a set of external +% scripts, which decide to input or not the external file, depending +% on the existence of that file. I would prefer do not require perl +% nor any other scripting language. Only metapost. +% +% This is why I wrote "latex.mp". It implements the idea in the +% metafun package, but it does not require any external script in +% order to check the existence of the auxiliar file. +% +% ================================================================ +% +% USAGE +% +% input "latex"; +% initlatex(...); +% ... +% +% latex("string to be formatted by latex"); +% % Returns a picture which can be used in a label +% +% The initlatex macro writes a latex header in an auxiliar file. You +% do not need to call this macro if you use TeX as typesetting engine. +% +% On the other hand, if you want to use LaTeX as typesetting engine, +% you need to call this macro before the first beginfig(). The macro +% requires a mandatory argument, which is a string with adittional +% macro commands to be placed before the "\begin{document}". For +% example: +% +% initlatex("\usepackage[latin1]{inputenc}\usepackage{amsmath}"); +% +% If you do not need any aditional package, you can use "" as +% argument. +% +% You can use the latex macro in any place where a picture is +% expected, as in the first argument of a label comand. For example: +% +% for i=0 upto 10: +% label(latex("$x_{$ & decimal i & "}$", (u*i,0)); +% endfor; +% +% In order to correctly obtain the labels which use the latex macro, +% you need to process your source file twice through metapost. The +% first run all labels will show as "[?]", but the second run they +% will have the correct value. +% +% IMPORTANT: +% +% If the text passed to the latex macro contains errors, latex will be +% unable to complete its run. This will make impossible to run mpost +% on the source, even if the errors are corrected, until you delete +% the auxiliar file (which has .mpt extension) +% +% +%================================================================ +% Implementation +% +numeric NumPic; % Total number of times that latex() macro has been + % called +picture LaTeXPic[]; % Picture array which stores the result of each + % latex macro call. This array is filled when the + % axiliar file is read. +string LaTeXsetup; % additional packages and macro definitions for latex + +% Initialization +NumPic:=0; +LaTeXsetup:="\documentclass{article}"; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Entry point +% +% The auxiliar file is read, but only if it exists +% +if readfrom(jobname&".mpt") <> EOF: + scantokens ("input "&jobname & ".mpt"); +fi; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% initlatex() +% +% By calling this function, the user can specify aditional packages and +% macro definitions to the be used by latex. +% +% For example: +% +% initlatex("\usepackage[latin1]{inputenc}\usepackage{amsmath}"); +% +% The global variable LaTeXsetup is also provided, mainly for third +% party libraries which require to define their own macros. The +% programmers of these libraries should append their own material to +% the LaTeXsetup variable, by using the & operator. For example: +% +% LaTeXsetup:=LaTeXsetup & "\def\TO{\Longrightarrow}"; +% +def initlatex primary s = + write "verbatimtex" to jobname & ".mpt"; + write "%&latex" to jobname & ".mpt"; + write LaTeXsetup to jobname & ".mpt"; + write s to jobname & ".mpt"; + write "\begin{document}" to jobname & ".mpt"; + write "etex" to jobname & ".mpt"; +enddef; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% latex() +% +% This macro receives a string, and returns a picture which contains +% the result of running the string by latex. The result can be used +% whenever a picture argument is expected, as for example in a label. + +vardef latex@#(expr txt) = + NumPic := NumPic + 1 ; + if string txt : + write "% figure " & decimal charcode & " : " & char(10) & + "LaTeXPic[" & decimal NumPic & "] := btex " & + txt & " etex ;" to jobname & ".mpt" ; + if unknown LaTeXPic[NumPic] : + thelabel@#("[??]",origin) + else : + thelabel@#(LaTeXPic[NumPic],origin) + fi + else : + thelabel@#(txt,origin) + fi +enddef ; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% EOF diff --git a/Master/texmf-dist/metapost/makecirc/makecirc.mp b/Master/texmf-dist/metapost/makecirc/makecirc.mp new file mode 100644 index 00000000000..0c6d8c8751d --- /dev/null +++ b/Master/texmf-dist/metapost/makecirc/makecirc.mp @@ -0,0 +1,981 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%||||||||||||||||||||«makecirc.mp»|||||||||||||||||||||||||%% +%%==========================================================%% +%<------------------- version 1.1 ------------------------->%% +% A MetaPost library for drawing electrical circuit diagrams. +% Copyright (c) 2003 GS Bustamante Argañaraz. +% It uses latex.mp by JL Diaz. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% This program may be distributed and/or modified under the conditions +% of the LaTeX Project Public License, either version 1.2 of this +% license or (at your option) any later version. The latest version +% of this license is in http://www.latex-project.org/lppl.txt and +% version 1.2 or later is part of all distributions of LaTeX version +% 1999/12/01 or later. +% +% This program consists of the files makecirc.mp and latex.mp +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +input latex; +% +% Commands definitions to do the labeled easier % +% +LaTeXsetup:=LaTeXsetup & +"\def\ohm{\ensuremath{\,\Omega}}" & +"\def\kohm{\,k\ensuremath{\Omega}}" & +"\def\modarg#1#2{\setbox0=\hbox{$\mkern-1mu/#2^\circ$}" & +"\dp0=.21ex $#1\underline{\box0}$}"; +% +newinternal labeling, rotatelabel, norotatelabel; +labeling:=0; norotatelabel:=labeling; rotatelabel:=1; + +% Macros for the pens, I define them as such so when they expand, +% look for the last value assigned to linewd and use it +% (thanks to JLD). The linewd value assigns it as newinternal to +% be able to change it «from out». + +newinternal linewd; +linewd:=0.25mm; + +def line = pencircle scaled linewd enddef; +def misc = pencircle scaled .8linewd enddef; + +% Arrowhead definitions % + +vardef miscahead expr p = +save A,u,a,b; pair A,u; path a,b; +A := point length(p) of p; +u := unitvector(direction length(p)/2 of p); +a := A--(A - ahlength*u rotated 15); +b := A--(A - ahlength*u rotated -15); +(a & reverse(a) & b & reverse(b))--cycle +enddef; + +vardef bjtahead expr p = +save A,u,a,b; pair A,u; path a,b; +A := point 0.7length(p) of p; +u := unitvector(direction length(p)/2 of p); +a := A--(A - ahlength*u rotated 20); +b := A--(A - ahlength*u rotated -20); +(a & reverse(a) & b & reverse(b))--cycle +enddef; + +vardef txtahead expr p = +save A,B,u,a; pair A,B,u; path a; +A := point length p of p; +B := point .97length p of p; +u := unitvector(direction length p of p); +a := A{-u}..(A - 7*u rotated 15)--B + --(A - 7*u rotated -15)..A{u}--cycle; +a +enddef; + +% Macros for wire the symbols % + +newinternal nsq, udsq, rlsq, usq; +nsq:=0; udsq:=2; rlsq:=3; usq:=4; + +def wire(expr pin_beg,pin_end,type)= + if type=nsq: + draw pin_beg--pin_end withpen line + elseif type=udsq: + draw pin_beg--(xpart pin_beg,ypart pin_end)--pin_end withpen line + elseif type=rlsq: + draw pin_beg--(xpart pin_end,ypart pin_beg)--pin_end withpen line + fi; +enddef; + +% Macro to connect two branches in parallel % + +def wireU(expr pin_beg,pin_end,dist,type)= + if type=udsq: + draw pin_beg--(pin_beg+(0,dist))--(xpart pin_end,ypart pin_beg + dist) + --pin_end withpen line + elseif type=rlsq: + draw pin_beg--(pin_beg+(dist,0))--(xpart pin_beg + dist,ypart pin_end) + --pin_end withpen line + fi; +enddef; + +% Variable to find the center of two pins, for to include a symbols. It returns the point +% and the input angle for the symbol that we want to place. + +vardef centreof@#(expr pin_beg,pin_end,lchar)= + pair c@#; numeric phi@#; + c@#= -lchar*dir angle(xpart(pin_end)-xpart(pin_beg), + ypart(pin_end)-ypart(pin_beg)) shifted .5[pin_beg,pin_end]; + phi@#=angle(xpart(pin_end)-xpart(pin_beg), + ypart(pin_end)-ypart(pin_beg)); +enddef; + +% Variable to center an element regarding the pins of another, at +% a distance «dist» of the same one. It returns the point in which we should +% place the symbol that we want to center. + +vardef centerto.@#(expr pinref_beg,pinref_end)(expr dist,elem)= + pair @#; + if (xpart(pinref_beg)=xpart(pinref_end)): + @#:=(.5[pinref_beg,pinref_end]+(dist,-elem)) + elseif (ypart(pinref_beg)=ypart(pinref_end)): + @#:=(.5[pinref_beg,pinref_end]+(-elem,dist)) + fi +enddef; + +% Macro for scale the circuit when it is concluded. % + +def scalecirc expr factor = + currentpicture:=currentpicture scaled factor +enddef; + +% Macro to include text into the circuits % + +vardef puttext@#(expr txt, point)= + label@#(latex(txt),point); +enddef; + +% Macro to center text among two pins % + +newinternal witharrow, noarrow; +witharrow:=0; noarrow:=1; + +vardef ctext@#(expr pin_beg,pin_end,txt,type)= + save ctxt; picture ctxt; + ctxt:=nullpicture; + %ahlength:=10; + if type=noarrow: + addto ctxt also thelabel(latex(txt),.5[pin_beg,pin_end]); + elseif type=witharrow: + addto ctxt doublepath pin_beg--pin_end; + addto ctxt contour txtahead pin_beg--pin_end; + addto ctxt contour txtahead reverse(pin_beg--pin_end); + addto ctxt also thelabel@#(latex(txt),.5[pin_beg,pin_end]); + fi; + draw ctxt withpen line; +enddef; + +% Definition of lbsep (label separation), distance among symbol and label. % + +newinternal lbsep; +lbsep:=3mm; + +% Macros to facilitate the one labeled of the symbols % + +def putlabel(expr pin_beg,pin_end,lchar,lcharv,ang,name,val)= +if labeling=rotatelabel: + if ((ang > (-90)) and (ang <= 90)) or ((ang > 270) and (ang <= 450)): + label(latex("$" & name & "$") rotatedaround (.5[pin_beg,pin_end],ang), + (lchar+lbsep)*dir (90+ang) shifted .5[pin_beg,pin_end]); + + label(latex(val) rotatedaround (.5[pin_beg,pin_end],ang), + (lcharv+lbsep)*dir (270+ang) shifted .5[pin_beg,pin_end]); + elseif ((ang > 90) and (ang <= 270)) or ((ang > (-270)) and (ang <= (-90))): + label(latex("$" & name & "$") rotatedaround (.5[pin_beg,pin_end],180+ang), + (lchar+lbsep)*dir (90+ang) shifted .5[pin_beg,pin_end]); + + label(latex(val) rotatedaround (.5[pin_beg,pin_end],180+ang), + (lcharv+lbsep)*dir (270+ang) shifted .5[pin_beg,pin_end]); + fi; + elseif labeling=norotatelabel: + if (ang = 0): + label.top(latex("$" & name & "$"), (lchar+.25lbsep)*dir (90+ang) + shifted .5[pin_beg,pin_end]); + + label.bot(latex(val),(lcharv+.25lbsep)*dir (270+ang) shifted .5[pin_beg,pin_end]); + elseif (ang > 0) and (ang < 90): + label.ulft(latex("$" & name & "$"), (lchar)*dir (90+ang) + shifted .5[pin_beg,pin_end]); + + label.lrt(latex(val),(lcharv)*dir (270+ang) shifted .5[pin_beg,pin_end]); + elseif (ang = 90): + label.lft(latex("$" & name & "$"),(lchar+.25lbsep)*dir (90+ang) + shifted .5[pin_beg,pin_end]); + + label.rt(latex(val),(lcharv+.25lbsep)*dir (270+ang) shifted .5[pin_beg,pin_end]); + elseif (90 < ang) and (ang < 180): + label.llft(latex("$" & name & "$"),(lchar)*dir (90+ang) + shifted .5[pin_beg,pin_end]); + + label.urt(latex(val),(lcharv)*dir (270+ang) shifted .5[pin_beg,pin_end]); + elseif (ang = 180) or (ang = (-180)): + label.bot(latex("$" & name & "$"), (lchar+.25lbsep)*dir (90+ang) + shifted .5[pin_beg,pin_end]); + + label.top(latex(val),(lcharv+.25lbsep)*dir (270+ang) shifted .5[pin_beg,pin_end]); + elseif ((ang > 180) and (ang < 270)) or ((ang > (-180)) and (ang < (-90))): + label.lrt(latex("$" & name & "$"),(lchar)*dir (90+ang) + shifted .5[pin_beg,pin_end]); + + label.ulft(latex(val),(lcharv)*dir (270+ang) shifted .5[pin_beg,pin_end]); + elseif (ang = 270) or (ang = (-90)): + label.rt(latex("$" & name & "$"), (lchar+.25lbsep)*dir (90+ang) + shifted .5[pin_beg,pin_end]); + + label.lft(latex(val),(lcharv+.25lbsep)*dir (270+ang) shifted .5[pin_beg,pin_end]); + elseif ((270 < ang) and (ang < 360)) or ((ang < 0) and (ang > (-90))): + label.urt(latex("$" & name & "$"),(lchar)*dir (90+ang) + shifted .5[pin_beg,pin_end]); + + label.llft(latex(val),(lcharv)*dir (270+ang) shifted .5[pin_beg,pin_end]); + fi; + fi; +enddef; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%% Here the symbols begin %%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%<---Inductor (bobina) --->%%% + +newinternal coil, Up, Down; +coil:=2mm; Up:=0; Down:=1; + +vardef inductor@#(expr z,type,ang,name,val)= + save bobina; + pair L@#.l, L@#.r; % pines % + L@#.l=z; L@#.r=(z+(6coil,0)) rotatedaround (z,ang); + picture bobina; + bobina:=nullpicture; + + if type=Up: + addto bobina doublepath z--(z+(coil,0)){up}.. for i=2 upto 4: + {down}(z+(i*coil,0)){up}.. endfor {down}(z+(5coil,0))--(z+(6coil,0)); + putlabel(L@#.l,L@#.r,coil,.5coil,ang,name,val); + elseif type=Down: + addto bobina doublepath z--(z+(coil,0)){down}.. for i=2 upto 4: + {up}(z+(i*coil,0)){down}.. endfor {up}(z+(5coil,0))--(z+(6coil,0)); + putlabel(L@#.l,L@#.r,coil,.5coil,(ang-180),name,val); + fi; + + draw bobina rotatedaround(z,ang) withpen line; +enddef; + +%%%<---Capacitor (condensador)--->%%% + +newinternal normal, electrolytic, variable, variant, platsep; +normal:=0; electrolytic:=1; variable:=2; platsep:=1mm; variant:=3; + +vardef capacitor@#(expr z,type,ang,name,val)= + save cap; + pair C@#.l, C@#.r; % pines % + C@#.l:=z; + C@#.r:=(xpart(z)+7platsep,ypart(z)) rotatedaround(z,ang); + picture cap; cap:=nullpicture; + + addto cap doublepath z--(xpart(z)+3platsep,ypart(z)) withpen line; + addto cap doublepath (xpart(z)+4platsep,ypart(z)) + --(xpart(z)+7platsep,ypart(z)) withpen line; + + if type=normal: + addto cap doublepath (xpart(z)+3platsep,ypart(z)-2.5platsep) + --(xpart(z)+3platsep,ypart(z)+2.5platsep) withpen line; + addto cap doublepath (xpart(z)+4platsep,ypart(z)-2.5platsep) + --(xpart(z)+4platsep,ypart(z)+2.5platsep) withpen line; + elseif type=electrolytic: + addto cap doublepath (xpart(z)+3platsep,ypart(z)-1.8platsep) + --(xpart(z)+3platsep,ypart(z)+1.8platsep) withpen line; + addto cap doublepath (xpart(z)+2platsep,ypart(z)-2.5platsep) + --(xpart(z)+4platsep,ypart(z)-2.5platsep)--(xpart(z)+4platsep,ypart(z)+2.5platsep) + --(xpart(z)+2platsep,ypart(z)+2.5platsep) withpen line; + elseif type=variable: + addto cap doublepath (xpart(z)+3platsep,ypart(z)-2.5platsep) + --(xpart(z)+3platsep,ypart(z)+2.5platsep) withpen line; + addto cap doublepath (xpart(z)+4platsep,ypart(z)-2.5platsep) + --(xpart(z)+4platsep,ypart(z)+2.5platsep) withpen line; + addto cap doublepath (xpart(z)+platsep,ypart(z)-2.5platsep) + --(xpart(z)+6platsep,ypart(z)+2.5platsep) withpen misc; + ahlength:=1.7platsep; + addto cap contour miscahead (xpart(z)+platsep,ypart(z)-2.5platsep) + --(xpart(z)+6platsep,ypart(z)+2.5platsep) withpen misc; + elseif type=variant: + addto cap doublepath (xpart(z)+3platsep,ypart(z)-2.5platsep) + --(xpart(z)+3platsep,ypart(z)+2.5platsep) withpen line; + addto cap doublepath (z+(4.5platsep,-2.5platsep))..(z+(4platsep,0)) + ..(z+(4.5platsep,2.5platsep)) withpen line; + fi; + + draw cap rotatedaround(z,ang); + + putlabel(C@#.l,C@#.r,2.5platsep,2.5platsep,ang,name,val); +enddef; + +%%%<--- Electrical machines (maquinas electricas) --->%%% + +vardef motor@#(expr z,ang,name,val)= + save mot, p, q, r, s, ca, cb, c, hc; + pair M@#.D, M@#.B; % pines % + M@#.D:=z; M@#.B:=(z+(2ssize,0)) rotatedaround(z,ang); + picture mot; mot:=nullpicture; + + addto mot doublepath z--(z+(.4ssize,0)); + addto mot doublepath (z+(1.6ssize,0))--(z+(2ssize,0)); + addto mot doublepath fullcircle scaled ssize shifted (z+(ssize,0)); + addto mot also thelabel(latex("\textsf{M}") scaled (ssize/6mm) + rotated (-ang), (z+(ssize,0))); + + path p,q,r,s,ca,cb,c,hc; + p=(z+(.6ssize,.075ssize))--(z+(.4ssize,.075ssize)); + q=(z+(.4ssize,.075ssize))--(z+(.4ssize,-.075ssize)); + ca=(z+(.4ssize,-.075ssize))--(z+(.6ssize,-.075ssize)); + + + r=(z+(1.4ssize,.075ssize))--(z+(1.6ssize,.075ssize)); + s=(z+(1.6ssize,.075ssize))--(z+(1.6ssize,-.075ssize)); + cb=(z+(1.6ssize,-.075ssize))--(z+(1.4ssize,-.075ssize)); + + c=fullcircle scaled ssize shifted (z+(ssize,0)); + hc=halfcircle scaled ssize rotated 270 shifted (z+(ssize,0)); + + addto mot contour buildcycle(p,q,ca,c); + addto mot doublepath buildcycle(p,q,ca,c); + + addto mot contour buildcycle(cb,s,r,hc); + addto mot doublepath buildcycle(cb,s,r,hc); + + draw mot rotatedaround(z,ang) withpen line; + + putlabel(M@#.D,M@#.B,.5ssize,.5ssize,ang,name,val); +enddef; + +vardef generator@#(expr z,ang,name,val)= + save gen; + pair G@#.D, G@#.B; % pines % + G@#.D:=z; G@#.B:=(z+(2ssize,0)) rotatedaround(z,ang); + picture gen; gen:=nullpicture; + + addto gen doublepath z--(z+(.5ssize,0)); + addto gen doublepath (z+(1.5ssize,0))--(z+(2ssize,0)); + addto gen doublepath fullcircle scaled ssize shifted (z+(ssize,0)); + addto gen also thelabel(latex("\textsf{G}") scaled (ssize/6mm) + rotated (-ang), (z+(ssize,0))); + + draw gen rotatedaround(z,ang) withpen line; + + putlabel(G@#.D,G@#.B,.5ssize,.5ssize,ang,name,val); +enddef; + +newinternal mid, Fe, auto; +mid:=1; Fe:=2; auto:=3; + +vardef transformer@#(expr z,type,ang)= + save trafo; + pair tf@#.pi, tf@#.ps, tf@#.si, tf@#.ss, tf@#.m; + tf@#.pi:=z; tf@#.ps:=(z+(0,8coil)) rotatedaround(z,ang); + tf@#.si:=(z+(2.4coil,0)) rotatedaround(z,ang); + tf@#.ss:=(z+(2.4coil,8coil)) rotatedaround(z,ang); + tf@#.m:=(z+(3.4coil,4coil)) rotatedaround(z,ang); + + picture trafo; trafo:=nullpicture; + + if type=normal: + tf@#.pi:=z; tf@#.ps:=(z+(0,8coil)) rotatedaround(z,ang); + tf@#.si:=(z+(2.4coil,0)) rotatedaround(z,ang); + tf@#.ss:=(z+(2.4coil,8coil)) rotatedaround(z,ang); + addto trafo doublepath z--(z+(0,coil)){right}.. + for i=2 upto 6: {left}(z+(0,i*coil)){right}.. endfor + {left}(z+(0,7coil))--(z+(0,8coil)); + addto trafo doublepath (z+(coil,coil))--(z+(coil,7coil)); + addto trafo doublepath (z+(1.4coil,coil))--(z+(1.4coil,7coil)); + addto trafo doublepath (z+(2.4coil,0))--(z+(2.4coil,coil)){left}.. + for i=2 upto 6: {right}(z+(2.4coil,i*coil)){left}.. endfor + {right}(z+(2.4coil,7coil))--(z+(2.4coil,8coil)); + elseif type=mid: + tf@#.pi:=z; tf@#.ps:=(z+(0,8coil)) rotatedaround(z,ang); + tf@#.si:=(z+(2.4coil,0)) rotatedaround(z,ang); + tf@#.ss:=(z+(2.4coil,8coil)) rotatedaround(z,ang); + tf@#.m:=(z+(3.4coil,4coil)) rotatedaround(z,ang); + addto trafo doublepath z--(z+(0,coil)){right}.. + for i=2 upto 6: {left}(z+(0,i*coil)){right}.. endfor + {left}(z+(0,7coil))--(z+(0,8coil)); + addto trafo doublepath (z+(coil,coil))--(z+(coil,7coil)); + addto trafo doublepath (z+(1.4coil,coil))--(z+(1.4coil,7coil)); + addto trafo doublepath (z+(2.4coil,0))--(z+(2.4coil,coil)){left}.. + for i=2 upto 6: {right}(z+(2.4coil,i*coil)){left}.. endfor + {right}(z+(2.4coil,7coil))--(z+(2.4coil,8coil)); + addto trafo doublepath (z+(2.4coil,4coil))--(z+(3.4coil,4coil)); + elseif type=Fe: + tf@#.pi:=z rotatedaround(z,ang); tf@#.ps:=(z+(0,5.3coil)) rotatedaround(z,ang); + tf@#.si:=(z+(14coil,0)) rotatedaround(z,ang); + tf@#.ss:=(z+(14coil,5.228coil)) rotatedaround(z,ang); + addto trafo doublepath z+(2coil,-2.5coil)--z+(12coil,-2.5coil) + --z+(12coil,7.5coil)--z+(2coil,7.5coil)--cycle; + addto trafo doublepath z+(4coil,-.5coil)--z+(10coil,-.5coil) + --z+(10coil,5.5coil)--z+(4coil,5.5coil)--cycle; + addto trafo doublepath z--z+(2coil,0)--z+(4coil,0.728coil) + {right}..{left}z+(4coil,1.3*coil); + for i=1 upto 4: + addto trafo doublepath z+(2coil,(i+.5)*coil){left}.. + {right}z+(2coil,i*coil)--z+(4coil,(i+0.728)*coil) + {right}..{left}z+(4coil,(i+1.3)*coil); + endfor; + addto trafo doublepath z+(2coil,5.3coil)--z+(0,5.3coil); + for i=0 upto 3: + addto trafo doublepath z+(10coil,i*coil){left}.. + {right}z+(10coil,(i+.5)*coil)--z+(12coil,(i+.5+0.728)*coil) + {right}..{left}z+(12coil,(i+.656)*coil); + endfor; + addto trafo doublepath z+(10coil,4coil){left}..{right} + z+(10coil,4.5coil)--z+(12coil,5.228coil)--z+(14coil,5.228coil); + addto trafo doublepath z+(12coil,0)--z+(14coil,0); + elseif type=auto: + tf@#.pi:=z rotatedaround(z,ang); tf@#.ps:=(z+(0,4coil)) rotatedaround(z,ang); + tf@#.si:=(z+(4coil,-6coil)) rotatedaround(z,ang); + tf@#.ss:=(z+(4coil,4coil)) rotatedaround(z,ang); + addto trafo doublepath z--z+(2coil,0); + addto trafo doublepath z+(2coil,-6coil)--z+(2coil,-5coil){right}.. + for i=2 upto 10: {left}(z+(2coil,(i-6)*coil)){right}.. endfor + {left}(z+(2coil,5coil))--z+(2coil,6coil)--z+(0,6coil); + addto trafo doublepath z+(2coil,6coil)--z+(4coil,6coil); + addto trafo doublepath z+(2coil,-6coil)--z+(4coil,-6coil); + fi; + + draw trafo rotatedaround(z,ang) withpen line; +enddef; + +%%%<---Sources (fuentes de alimentaci'on)--->%%% + +newinternal AC,DC,I,V,ssize; +AC:=1; DC:=0; I:=2; V:=3; ssize:=6mm; + +vardef source@#(expr z,type,ang,name,val)= + save fuente, positive, negative, seno; + pair S@#.p,S@#.n; % pines % + if (type=AC) or (type=I) or (type=V): + S@#.n:=z; + S@#.p:=(z+(2ssize,0)) rotatedaround(z,ang); + elseif type=DC: + S@#.p:=(z+(ssize,0)) rotatedaround(z,ang); + S@#.n:=z; + fi; + + picture fuente, positive, negative, seno; + positive:=nullpicture; negative:=nullpicture; + + addto positive doublepath (z+(1.05ssize,0))--(z+(1.45ssize,0)) withpen misc; + addto positive doublepath (z+(1.25ssize,-.2ssize))--(z+(1.25ssize,.2ssize)) withpen misc; + addto negative doublepath (z+(.95ssize,0))--(z+(.55ssize,0)) withpen misc; + + seno:=nullpicture; + addto seno doublepath (z+(2ssize/3,0)){dir 45} + ..{right}.5[z+(2ssize/3,.2ssize),z+(ssize,.2ssize)]..{dir -45}(z+(ssize,0)) + ..{right}.5[z+(ssize,-.2ssize),z+(4ssize/3,-.2ssize)]..{dir 45}(z+(4ssize/3,0)) + withpen line; + + fuente:=nullpicture; + if (type=AC) or (type=I) or (type=V): + addto fuente doublepath z--(z+(.5ssize,0)) withpen line; + addto fuente doublepath (z+(1.5ssize,0))--(z+(2ssize,0)) withpen line; + addto fuente doublepath fullcircle scaled ssize shifted (z+(ssize,0)) + withpen line; + if type=AC: + addto fuente also seno rotatedaround((z+(ssize,0)),-ang); + elseif type=I: + ahlength:=4ssize/15; ahangle:=30; + addto fuente doublepath (z+(ssize-ssize/3,0))--(z+(ssize+ssize/3,0)) + withpen line; + addto fuente contour arrowhead (z+(ssize-ssize/3,0))--(z+(ssize+ssize/3,0)) + withpen line; + ahlength:=4; ahangle:=45; + elseif type=V: + addto fuente also positive rotatedaround(z+(1.25ssize,0),-ang); + addto fuente also negative rotatedaround(z+(.75ssize,0),-ang); + fi; + elseif type=DC: + addto fuente doublepath z--(z+(0.4ssize,0)) withpen line; + addto fuente doublepath (z+(.6ssize,0))--(z+(ssize,0)) withpen line; + addto fuente doublepath (z+(.4ssize,-.2ssize))--(z+(.4ssize,.2ssize)) withpen line; + addto fuente doublepath (z+(.6ssize,-.6ssize))--(z+(.6ssize,.6ssize)) withpen line; + fi; + + if (type=AC) or (type=V) or (type=I): + putlabel(S@#.n,S@#.p,.5ssize,.5ssize,ang,name,val); + elseif (type=DC): + putlabel(S@#.n,S@#.p,.6ssize,.6ssize,ang,name,val); + fi; + + draw fuente rotatedaround (z,ang); +enddef; + +%%%<---Resistor (Resistencia)--->%%% + +newinternal rstlth; +rstlth:=2mm; + +vardef resistor@#(expr z,type,ang,name,val)= + save rst; + pair R@#.l,R@#.r; % pines % + R@#.l:=z; + R@#.r:=(z+(7rstlth,0)) rotatedaround(z,ang); + picture rst; + rst:=nullpicture; + addto rst doublepath z--(z+(2rstlth,0))--(z+(2.25rstlth,.75rstlth))-- + for i=.5 step .5 until 2.5: (z+((2.25+i)*rstlth,((-1)**(2i))*.75rstlth))-- + endfor (z+(5rstlth,0))--(z+(7rstlth,0)) withpen line; + if type=normal: + % no change % + elseif type=variable: + ahlength:=.8rstlth; + addto rst doublepath (z+(2rstlth,-rstlth))--(z+(5.5rstlth,rstlth)) withpen misc; + addto rst contour miscahead (z+(2rstlth,-rstlth))--(z+(5.5rstlth,rstlth)) + withpen misc; + fi; + + putlabel(R@#.l,R@#.r,.8rstlth,.8rstlth,ang,name,val); + + draw rst rotatedaround(z,ang); +enddef; + +%%%<--- Diode (diodo) --->%%% +newinternal zener, LED, diodeht, pinK, pinA; +zener:=1; LED:=2; diodeht:=3.5mm; pinK:=3; pinA:=4; + +vardef diode@#(expr z,type,ang,pin,name,val)= + save diodo; + pair D@#.K,D@#.A; % pines % + picture diodo; + diodo:=nullpicture; + + addto diodo doublepath z--(z+(diodeht,0))--(z+(diodeht,.5diodeht)) + --(z+(2diodeht,0))--(z+(diodeht,-.5diodeht))--(z+(diodeht,0)) withpen line; + addto diodo doublepath (z+(2diodeht,0))--(z+(3diodeht,0)) withpen line; + + if type=normal: + addto diodo doublepath (z+(2diodeht,-.5diodeht))--(z+(2diodeht,.5diodeht)) + withpen line; + elseif type=zener: + addto diodo doublepath (z+(2.5diodeht,-.5diodeht))--(z+(2diodeht,-.5diodeht)) + --(z+(2diodeht,.5diodeht))--(z+(1.5diodeht,.5diodeht)) withpen line; + elseif type=LED: + addto diodo doublepath (z+(2diodeht,-.5diodeht))--(z+(2diodeht,.5diodeht)) + withpen line; + + addto diodo doublepath (0.25diodeht*dir + (angle(xpart(z+(diodeht,.5diodeht))-xpart(z+(2diodeht,0)), + ypart(z+(diodeht,.5diodeht))-ypart(z+(2diodeht,0)))) shifted (z+(2diodeht,.5diodeht))) + --(diodeht*dir(angle(xpart(z+(diodeht,.5diodeht))-xpart(z+(2diodeht,0)), + ypart(z+(diodeht,.5diodeht))-ypart(z+(2diodeht,0)))+270) shifted + (0.25diodeht*dir(angle(xpart(z+(diodeht,.5diodeht))-xpart(z+(2diodeht,0)), + ypart(z+(diodeht,.5diodeht))-ypart(z+(2diodeht,0)))) shifted + (z+(2diodeht,.5diodeht)))) withpen misc; + + addto diodo doublepath (0.6diodeht*dir + (angle(xpart(z+(diodeht,.5diodeht))-xpart(z+(2diodeht,0)), + ypart(z+(diodeht,.5diodeht))-ypart(z+(2diodeht,0)))) shifted (z+(2diodeht,.5diodeht))) + --(diodeht*dir(angle(xpart(z+(diodeht,.5diodeht))-xpart(z+(2diodeht,0)), + ypart(z+(diodeht,.5diodeht))-ypart(z+(2diodeht,0)))+270) shifted + (0.6diodeht*dir(angle(xpart(z+(diodeht,.5diodeht))-xpart(z+(2diodeht,0)), + ypart(z+(diodeht,.5diodeht))-ypart(z+(2diodeht,0)))) shifted + (z+(2diodeht,.5diodeht)))) withpen misc; + + ahlength:=.4diodeht; ahangle:=30; + addto diodo contour arrowhead (0.25diodeht*dir + (angle(xpart(z+(diodeht,.5diodeht))-xpart(z+(2diodeht,0)), + ypart(z+(diodeht,.5diodeht))-ypart(z+(2diodeht,0)))) shifted (z+(2diodeht,.5diodeht))) + --(diodeht*dir(angle(xpart(z+(diodeht,.5diodeht))-xpart(z+(2diodeht,0)), + ypart(z+(diodeht,.5diodeht))-ypart(z+(2diodeht,0)))+270) shifted + (0.25diodeht*dir(angle(xpart(z+(diodeht,.5diodeht))-xpart(z+(2diodeht,0)), + ypart(z+(diodeht,.5diodeht))-ypart(z+(2diodeht,0)))) shifted + (z+(2diodeht,.5diodeht)))) withpen misc; + + addto diodo contour arrowhead (0.6diodeht*dir + (angle(xpart(z+(diodeht,.5diodeht))-xpart(z+(2diodeht,0)), + ypart(z+(diodeht,.5diodeht))-ypart(z+(2diodeht,0)))) shifted (z+(2diodeht,.5diodeht))) + --(diodeht*dir(angle(xpart(z+(diodeht,.5diodeht))-xpart(z+(2diodeht,0)), + ypart(z+(diodeht,.5diodeht))-ypart(z+(2diodeht,0)))+270) shifted + (0.6diodeht*dir(angle(xpart(z+(diodeht,.5diodeht))-xpart(z+(2diodeht,0)), + ypart(z+(diodeht,.5diodeht))-ypart(z+(2diodeht,0)))) shifted + (z+(2diodeht,.5diodeht)))) withpen misc; + ahlength:=4; ahangle:=45; + fi; + + if pin=pinA: + D@#.A:=z; + D@#.K:=(z+(3diodeht,0)) rotatedaround(z,ang); + draw diodo rotatedaround(z,ang); + elseif pin=pinK: + D@#.K:=z; + D@#.A:=(z+(3diodeht,0)) rotatedaround(z,ang); + diodo:=diodo rotatedaround(.5[z,(z+(3diodeht,0))],180); + draw diodo rotatedaround(z,ang); + fi; + + if (type=normal) or (type=zener): + putlabel(D@#.A,D@#.K,.6diodeht,.6diodeht,ang,name,val); + elseif (type=LED): + putlabel(D@#.A,D@#.K,1.5diodeht,.6diodeht,ang,name,val); + fi; +enddef; + +%%%<--- Transistor --->%%% +newinternal npn, pnp, cnpn, cpnp, bjtlth; +npn:=1; pnp:=-1; cnpn:=0; cpnp:=2; bjtlth:=7mm; + +vardef transistor@#(expr z,type,ang)= + save BJT; + pair T@#.B,T@#.E,T@#.C; % pines: Base, Emisor, Colector % + T@#.B:=z; + T@#.E:=(z+(bjtlth,-.75bjtlth)) rotatedaround(z,ang); + T@#.C:=(z+(bjtlth,.75bjtlth)) rotatedaround(z,ang); + picture BJT; + BJT:=nullpicture; + + addto BJT doublepath z--(z+(.5bjtlth,0)) withpen line; + addto BJT doublepath (z+(.5bjtlth,-.5bjtlth))--(z+(.5bjtlth,.5bjtlth)) withpen line; + addto BJT doublepath (z+(.5bjtlth,.2bjtlth))--(z+(bjtlth,.5bjtlth)) + --(z+(bjtlth,.75bjtlth)) withpen line; + + if type=npn: + addto BJT doublepath (z+(.5bjtlth,-.2bjtlth))--(z+(bjtlth,-.5bjtlth)) + --(z+(bjtlth,-.75bjtlth)) withpen line; + addto BJT contour bjtahead (z+(.5bjtlth,-.2bjtlth)) + --(z+(bjtlth,-.5bjtlth)) withpen line; + elseif type=cnpn: + addto BJT doublepath (z+(.5bjtlth,-.2bjtlth))--(z+(bjtlth,-.5bjtlth)) + --(z+(bjtlth,-.75bjtlth)) withpen line; + addto BJT contour bjtahead (z+(.5bjtlth,-.2bjtlth)) + --(z+(bjtlth,-.5bjtlth)) withpen line; + addto BJT doublepath fullcircle scaled 1.3bjtlth shifted (z+(.65bjtlth,0)) + withpen line; + elseif type=pnp: + addto BJT doublepath (z+(bjtlth,-.75bjtlth))--(z+(bjtlth,-.5bjtlth)) + --(z+(.5bjtlth,-.2bjtlth)) withpen line; + addto BJT contour bjtahead (z+(bjtlth,-.5bjtlth)) + --(z+(.5bjtlth,-.2bjtlth)) withpen line; + elseif type=cpnp: + addto BJT doublepath (z+(bjtlth,-.75bjtlth))--(z+(bjtlth,-.5bjtlth)) + --(z+(.5bjtlth,-.2bjtlth)) withpen line; + addto BJT contour bjtahead (z+(bjtlth,-.5bjtlth)) + --(z+(.5bjtlth,-.2bjtlth)) withpen line; + addto BJT doublepath fullcircle scaled 1.3bjtlth shifted (z+(.65bjtlth,0)) withpen line; + fi; + + draw BJT rotatedaround(z,ang); +enddef; + +%%%<--- Measurement instruments (Intrumentos de medicion)--->%%% +newinternal volt, ampere, watt; +volt:=0; ampere:=1; watt:=2; + +vardef meains@#(expr z,type,ang,name)= + save meter; + pair mi@#.l, mi@#.r, mi@#.p; % pines % + mi@#.l:=z; mi@#.r:=(z+(2ssize,0)) rotatedaround(z,ang); + + picture meter; meter:=nullpicture; + addto meter doublepath z--(z+(.5ssize,0)); + addto meter doublepath (z+(1.5ssize,0))--(z+(2ssize,0)); + if (type=volt) or (type=ampere): + addto meter doublepath fullcircle scaled ssize shifted (z+(ssize,0)); + if type=volt: + addto meter also thelabel(latex("\textsf{V}") scaled (ssize/6mm) + rotated (-ang), (z+(ssize,0))); + elseif type=ampere: + addto meter also thelabel(latex("\textsf{A}") scaled (ssize/6mm) + rotated (-ang), (z+(ssize,0))); + fi; + elseif (type=watt): + mi@#.p:=(z+(ssize,-ssize)) rotatedaround(z,ang); + addto meter doublepath (z+(.5ssize,-.5ssize))--(z+(.5ssize,.5ssize)) + --(z+(1.5ssize,.5ssize))--(z+(1.5ssize,-.5ssize))--cycle; + addto meter doublepath (z+(ssize,-.5ssize))--(z+(ssize,-ssize)); + addto meter also thelabel(latex("\textsf{W}") scaled (ssize/6mm) + rotated (-ang), (z+(ssize,0))); + fi; + + draw meter rotatedaround(z,ang) withpen line; + + if labeling=rotatelabel: + if ((ang > (-90)) and (ang <= 90)) or ((ang > 270) and (ang <= 450)): + label(latex(name) rotatedaround (.5[mi@#.l,mi@#.r],ang), + (.5ssize+lbsep)*dir (90+ang) shifted .5[mi@#.l,mi@#.r]); + elseif ((ang > 90) and (ang <= 270)) or ((ang > (-270)) and (ang <= (-90))): + label(latex(name) rotatedaround (.5[mi@#.l,mi@#.r],180+ang), + (.5ssize+lbsep)*dir (90+ang) shifted .5[mi@#.l,mi@#.r]); + fi; + elseif labeling=norotatelabel: + if (ang = 0): + label.top(latex(name), (.5ssize+.25lbsep)*dir (90+ang) + shifted .5[mi@#.l,mi@#.r]); + elseif (ang > 0) and (ang < 90): + label.ulft(latex(name), (.5ssize)*dir (90+ang) + shifted .5[mi@#.l,mi@#.r]); + elseif (ang = 90): + label.lft(latex(name),(.5ssize+.25lbsep)*dir (90+ang) + shifted .5[mi@#.l,mi@#.r]); + elseif (90 < ang) and (ang < 180): + label.llft(latex(name),(.5ssize)*dir (90+ang) + shifted .5[mi@#.l,mi@#.r]); + elseif (ang = 180) or (ang = (-180)): + label.bot(latex(name), (.5ssize+.25lbsep)*dir (90+ang) + shifted .5[mi@#.l,mi@#.r]); + elseif ((ang > 180) and (ang < 270)) or ((ang > (-180)) and (ang < (-90))): + label.lrt(latex(name),(.5ssize)*dir (90+ang) + shifted .5[mi@#.l,mi@#.r]); + elseif (ang = 270) or (ang = (-90)): + label.rt(latex(name), (.5ssize+.25lbsep)*dir (90+ang) + shifted .5[mi@#.l,mi@#.r]); + elseif ((270 < ang) and (ang < 360)) or ((ang < 0) and (ang > (-90))): + label.urt(latex(name),(.5ssize)*dir (90+ang) + shifted .5[mi@#.l,mi@#.r]); + fi; + fi; +enddef; + +%%%<--- Miscellaneous symbols --->%%% + +newinternal gndlth, implth, simple, shield; +gndlth:=5mm; implth:=7mm; simple:=1; shield:=2; + +vardef ground@#(expr z,type,ang)= + save GND; + pair gnd@#; % unico pin % + gnd@#:=z; + picture GND; GND:=nullpicture; + addto GND doublepath z--(z+(0,-.5gndlth)) withpen line; + if type=shield: + addto GND doublepath (z+(-.5gndlth,-.5gndlth))--(z+(.5gndlth,-.5gndlth)) withpen line; + addto GND doublepath (z+(-.35gndlth,-.6gndlth))--(z+(.35gndlth,-.6gndlth)) withpen line; + addto GND doublepath (z+(-.2gndlth,-.7gndlth))--(z+(.2gndlth,-.7gndlth)) withpen line; + elseif type=simple: + addto GND doublepath (z+(-.5gndlth,-.5gndlth))--(z+(.5gndlth,-.5gndlth)) + withpen pencircle scaled 2linewd; + fi; + draw GND rotatedaround(z,ang); +enddef; + +newinternal junctiondiam; +junctiondiam:=1.25mm; + +vardef junction@#(expr z,name)(suffix $)= + pair J@#; J@#:=z; + draw z withpen pencircle scaled junctiondiam; + label.$(latex(name),z); +enddef; + +vardef impedance@#(expr z,ang,name,val)= + save imp; + pair Z@#.l, Z@#.r; % pines % + Z@#.l:=z; + Z@#.r:=(z+(1.5implth,0)) rotatedaround(z,ang); + picture imp; imp:=nullpicture; + + addto imp doublepath z--(z+(.25implth,0)); + addto imp doublepath (z+(.25implth,-.18implth))--(z+(.25implth,.18implth)) + --(z+(1.25implth,.18implth))--(z+(1.25implth,-.18implth))--cycle; + addto imp doublepath (z+(1.25implth,0))--(z+(1.5implth,0)); + + draw imp rotatedaround(z,ang) withpen line; + + putlabel(Z@#.l,Z@#.r,.2implth,.2implth,ang,name,val); +enddef; + +vardef lamp@#(expr z,ang,name,val)= + save ampl, p, q, r, s; + pair La@#.l,La@#.r; % pines % + La@#.l:=z; La@#.r:=(z+(2ssize,0)) rotatedaround(z,ang); + + picture ampl; ampl:=nullpicture; + + addto ampl doublepath z--(z+(.5ssize,0)); + addto ampl doublepath fullcircle scaled ssize shifted (z+(ssize,0)); + addto ampl doublepath (z+(1.5ssize,0))--(z+(2ssize,0)); + + pair p, q, r, s; + p=(-ssize*dir 45 shifted (z+(ssize,0))--(z+(ssize,0))) intersectionpoint + (fullcircle scaled ssize shifted (z+(ssize,0))); + q=(ssize*dir 45 shifted (z+(ssize,0))--(z+(ssize,0))) intersectionpoint + (fullcircle scaled ssize shifted (z+(ssize,0))); + r=(-ssize*dir (-45) shifted (z+(ssize,0))--(z+(ssize,0))) intersectionpoint + (fullcircle scaled ssize shifted (z+(ssize,0))); + s=(ssize*dir (-45) shifted (z+(ssize,0))--(z+(ssize,0))) intersectionpoint + (fullcircle scaled ssize shifted (z+(ssize,0))); + + addto ampl doublepath p--q; + addto ampl doublepath r--s; + + draw ampl rotatedaround(z,ang) withpen line; + + putlabel(La@#.l,La@#.r,.5ssize,.5ssize,ang,name,val); +enddef; + +%%%<--- Switches (Llaves) --->%%% + +newinternal NO, NC, ssep, swt; +NO:=0; NC:=1; ssep:=3mm; swt:=1.2ssep; + +vardef switch@#(expr z,type,ang,name,val)= + save swt; + pair st@#.l, st@#.r; + st@#.l:=z; st@#.r:= (z+(2.4ssep,0)) rotatedaround(z,ang); + picture swt; swt:=nullpicture; + + addto swt doublepath z--(z+(.7ssep,0)); + addto swt doublepath (z+(1.7ssep,ssep/3))--(z+(1.7ssep,0))--(z+(2.4ssep,0)); + + if type=NO: + addto swt doublepath (z+(.7ssep,0))--(z+(1.8ssep,.7ssep)); + elseif type=NC: + addto swt doublepath (z+(.7ssep,0))--(z+(2ssep,ssep/3)); + fi; + + draw swt rotatedaround(z,ang) withpen line; + + putlabel(st@#.l,st@#.r,.6ssep,.6ssep,ang,name,val); +enddef; + +%%%<--- Battery (bater'ia) --->%%% + +vardef battery@#(expr z,ang,name,val)= + save bat; + pair B@#.n, B@#.p; + B@#.n:=z; B@#.p:=(z+(1.8ssize,0)) rotatedaround(z,ang); + + picture bat; bat:=nullpicture; + addto bat doublepath z--(z+(0.4ssize,0)) withpen line; + addto bat doublepath (z+(1.4ssize,0))--(z+(1.8ssize,0)); + for i=0 upto 2: + addto bat doublepath (z+((.4+.4i)*ssize,-.2ssize))--(z+((.4+.4i)*ssize,.2ssize)); + addto bat doublepath (z+((.6+.4i)*ssize,-.6ssize))--(z+((.6+.4i)*ssize,.6ssize)); + endfor; + + draw bat rotatedaround(z,ang) withpen line; + + putlabel(B@#.n,B@#.p,.6ssize,.6ssize,ang,name,val); +enddef; + +%%%<--- Current (Corriente) --->%%% + +vardef current@#(expr z,ang,name,val)= + save cur; + pair i@#.s,i@#.d; + i@#.s:=z; i@#.d:=(z+(3platsep,0)) rotatedaround(z,ang); + ahangle:=20; ahlength:=3platsep; + picture cur; cur:=nullpicture; + addto cur contour arrowhead z--(z+(3platsep,0)); + + draw cur rotatedaround(z,ang) withpen line; + + putlabel(i@#.s,i@#.d,.5platsep,.5platsep,ang,name,val); + + ahangle:=45; ahlength:=4; +enddef; + +%%%<--- Mesh current (corriente de malla) --->%%% + +newinternal cw, ccw; +cw:=0; ccw:=1; + +def imesh(expr c,wd,ht,dire,ang,name)= + save im,r; picture im; numeric r; + ahlength:=3platsep; ahangle:=20; + if ht > wd: r=.2wd elseif ht < wd: r=.2ht fi; + im:=nullpicture; + if dire=cw: + addto im doublepath (xpart c - .5wd, ypart c - .5ht) + --(xpart c - .5wd, ypart c + .5ht-r){up} + ..{right}(xpart c - .5wd + r, ypart c + .5ht) + --(xpart c + .5wd - r, ypart c + .5ht){right} + ..{down}(xpart c + .5wd,ypart c + .5ht - r) + --(xpart c + .5wd,ypart c - .5ht + r){down} + ..{left}(xpart c + .5wd - r,ypart c - .5ht) + --(xpart c - .25wd, ypart c - .5ht); + addto im contour arrowhead (xpart c - .5wd, ypart c - .5ht) + --(xpart c - .5wd, ypart c + .5ht-r){up} + ..{right}(xpart c - .5wd + r, ypart c + .5ht) + --(xpart c + .5wd - r, ypart c + .5ht){right} + ..{down}(xpart c + .5wd,ypart c + .5ht - r) + --(xpart c + .5wd,ypart c - .5ht + r){down} + ..{left}(xpart c + .5wd - r,ypart c - .5ht) + --(xpart c - .25wd, ypart c - .5ht); + elseif dire=ccw: + addto im doublepath (xpart c + .5wd, ypart c - .5ht) + --(xpart c + .5wd, ypart c + .5ht-r){up} + ..{left}(xpart c + .5wd - r, ypart c + .5ht) + --(xpart c - .5wd + r, ypart c + .5ht){left} + ..{down}(xpart c - .5wd,ypart c + .5ht - r) + --(xpart c - .5wd,ypart c - .5ht + r){down} + ..{right}(xpart c - .5wd + r,ypart c - .5ht) + --(xpart c + .25wd, ypart c - .5ht); + addto im contour arrowhead (xpart c + .5wd, ypart c - .5ht) + --(xpart c + .5wd, ypart c + .5ht-r){up} + ..{left}(xpart c + .5wd - r, ypart c + .5ht) + --(xpart c - .5wd + r, ypart c + .5ht){left} + ..{down}(xpart c + .5wd,ypart c + .5ht - r) + --(xpart c - .5wd,ypart c - .5ht + r){down} + ..{right}(xpart c - .5wd + r,ypart c - .5ht) + --(xpart c + .25wd, ypart c - .5ht); + fi; + + if labeling=rotatelabel: + addto im also thelabel(latex("$" & name & "$"),c); + elseif labeling=norotatelabel: + addto im also thelabel(latex("$" & name & "$") rotatedaround(c,-ang),c); + fi; + + draw im rotatedaround (c,ang) withpen line; +enddef; + +%%%<--- Reostatos --->%%% + +newinternal rheolth, Rrheo, Lrheo; +rheolth:=2mm; Rrheo:=1; Lrheo:=2; + +vardef rheostat@#(expr z,type,ang)= + save reo; picture reo; reo:=nullpicture; + pair rh@#.i, rh@#.s, rh@#.r; + rh@#.i:=z; rh@#.s:=(z+(0,6rheolth)) rotatedaround(z,ang); + rh@#.r:=(z+(3rheolth,6rheolth)) rotatedaround(z,ang); + + ahangle:=20; ahlength:=rheolth; + + if type=Lrheo: + addto reo doublepath (z+(6rheolth,-3rheolth))--(z+(4rheolth,-3rheolth)) + --(z+(4rheolth,-.7rheolth)); + addto reo contour arrowhead (z+(6rheolth,-3rheolth))--(z+(4rheolth,-3rheolth)) + --(z+(4rheolth,-.9rheolth)); + + addto reo doublepath z--(z+(rheolth,0)){down}.. for i=2 upto 4: + {up}(z+(i*rheolth,0)){down}.. endfor {up}(z+(5rheolth,0))--(z+(6rheolth,0)); + + reo:=reo rotatedaround(z,90); + elseif type=Rrheo: + addto reo doublepath (z+(6rheolth,-3rheolth))--(z+(4rheolth,-3rheolth)) + --(z+(4rheolth,-.7rheolth)); + addto reo contour arrowhead (z+(6rheolth,-3rheolth))--(z+(4rheolth,-3rheolth)) + --(z+(4rheolth,-.9rheolth)); + + addto reo doublepath z--(z+(1.5rheolth,0))--(z+(1.75rheolth,.75rheolth))-- + for i=.5 step .5 until 2.5: (z+((1.75+i)*rheolth,((-1)**(2i))*.75rheolth))-- + endfor (z+(4.5rheolth,0))--(z+(6rheolth,0)) withpen line; + + reo:=reo rotatedaround(z,90); + fi; + draw reo rotatedaround(z,ang) withpen line; +enddef; + +% Definiciones de las longitudes de centrado, +% las hago como macros para que cambien de +% valor cuando lo hagan las dimensiones +% caracter'isticas de cada s'imbolo. + +def res = 3.5rstlth enddef; % 1 +def ind = 3coil enddef; % 2 +def cap = 3.5platsep enddef; % 3 +def sac = ssize enddef; % 4 +def sv = ssize enddef; % 5 +def si = ssize enddef; % 6 +def sdc = .5ssize enddef; % 7 +def mot = ssize enddef; % 8 +def gen = ssize enddef; % 9 +def tra = 4coil enddef; %10 +def ins = ssize enddef; %11 +def dio = 1.5diodeht enddef; %12 +def bjt = .5bjtlth enddef; %13 +def imp = .75implth enddef; %14 +def lam = ssize enddef; %15 +def swt = 1.2ssep enddef; %16 +def bat = .9ssize enddef; %17 +def cur = 1.5platsep enddef; %18 + +%% END %% \ No newline at end of file -- cgit v1.2.3