// Under a shell type: box -l g multivibrator.box
// ---
// Here we show how to draw a small electric circuit.
include "g"
include "electric"
// These parameters control the spacing of the circuit
sx = 15.0, sy = 30.0 // scales along x and y directions
// x offsets and y offsets
x0 = 0.0, x1 = sx, x2 = 2.0*sx, x3 = 3.5*sx, x4 = 4.5*sx
y0 = 0.0, y1 = sy, y2 = 2.0*sy
w = Window[][
// Place the four resistors, the two condenser and the two NPN transistors
// The string "rt" means: automatically rotate and translate such that
// the .Near[] constraints are better satisfied.
r1 = .Put[resistor, "rt", .Near[1, (x1, y0)], .Near[2, (x1, y1)]]
r2 = .Put[resistor, "rt", .Near[1, (x2, y0)], .Near[2, (x2, y1)]]
r3 = .Put[resistor, "rt", .Near[1, (x3, y0)], .Near[2, (x3, y1)]]
r4 = .Put[resistor, "rt", .Near[1, (x4, y0)], .Near[2, (x4, y1)]]
c1 = .Put[capacitor, "rt", .Near[1, (x1, y1)], .Near[2, (x2, y1)]]
c2 = .Put[capacitor, "rt", .Near[1, (x4, y1)], .Near[2, (x3, y1)]]
t1 = .Put[transistor_NPN, "rt", .Near["C", (x1, y1)], .Near["E", (x1, y2)]]
t2 = .Put[transistor_NPN, "rt", .Scale[(1, -1)],
.Near["C", (x4, y1)], .Near["E", (x4, y2)]]
// Trace all the connections between the components
\ .Line[0.2, (x0, y0), (x4, y0), r4.Get[1];
(x1, y0), r1.Get[1]; (x2, y0), r2.Get[1];
(x3, y0), r3.Get[1];
r1.Get[2], t1.Get["C"]; r4.Get[2], t2.Get["C"];
t1.Get["E"], (x1, y2); t2.Get["E"], (x4, y2), (x0, y2);
r2.Get[2], (x2, y1), c1.Get[2]; c1.Get[1], (x1, y1);
r3.Get[2], (x3, y1), c2.Get[2]; c2.Get[1], (x4, y1);
(x2, y1), t2.Get["B"] - (sx*0.2, 0), t2.Get["B"];
(x3, y1), t1.Get["B"] + (sx*0.2, 0), t1.Get["B"]
]
// Insert small circles, where more than 3 lines meet
\ .Circle[0.6, (x1, y0); (x2, y0); (x3, y0); (x1, y2);
(x2, y1); (x3, y1); (x1, y1); (x4, y1)]
// Some labels near the components
\ .Text[.Font["Helvetica", 4.0],
"T1", t1.Get[1.5], .From[(2.1, 0.5)];
"R1", r1.Get[1.5];
"R2", r2.Get[1.5], .From[(1.9, 0.5)];
"T2", t2.Get[1.5], .From[(-0.9, 0.5)];
"R3", r3.Get[1.5];
"R4", r4.Get[1.5];
"C1", c1.Get[1.5], .From[(0.5, -1.5)];
"C2", c2.Get[1.5]]
// Enlarge bounding box: the Show[] instruction specify some points that
// should be visible anyway (the bounding box is enlarged accordingly)
\ .Show[t2.Get[1.5] + (12, 0)]
]
// Save the figure into a postscript file
w.Save["multivibrator.eps"]
|