multivibrator.box

A simple electric circuit

../../_images/multivibrator.png

the output produced by Box To run this example you will need the following file(s): ./multivibrator.box. If the example requires more than one file, then you should put them into the same directory. You can then launch Box with box -l g ./multivibrator.box.

// 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[][
  BBox[(-1, -1), (78, 61)] // Bounding box

  // 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 best satisfied.
  r1 = Put[resistor, "rt", Near[0, (x1, y0)], Near[1, (x1, y1)]]
  r2 = Put[resistor, "rt", Near[0, (x2, y0)], Near[1, (x2, y1)]]
  r3 = Put[resistor, "rt", Near[0, (x3, y0)], Near[1, (x3, y1)]]
  r4 = Put[resistor, "rt", Near[0, (x4, y0)], Near[1, (x4, y1)]]
  c1 = Put[capacitor, "rt", Near[0, (x1, y1)], Near[1, (x2, y1)]]
  c2 = Put[capacitor, "rt", Near[0, (x4, y1)], Near[1, (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)]]

  // Do actually draw the components
  r1, r2, r3, r4, c1, c2, t1, t2

  // Trace all the connections between the components
  Lines[0.4, (x0, y0), (x4, y0), r4.Get[0];
        (x1, y0), r1.Get[0]; (x2, y0), r2.Get[0];
        (x3, y0), r3.Get[0];
        r1.Get[1], t1.Get["C"]; r4.Get[1], t2.Get["C"];
        t1.Get["E"], (x1, y2); t2.Get["E"], (x4, y2), (x0, y2);
        r2.Get[1], (x2, y1), c1.Get[1]; c1.Get[0], (x1, y1);
        r3.Get[1], (x3, y1), c2.Get[1]; c2.Get[0], (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
  Circles[0.6, (x1, y0); (x2, y0); (x3, y0); (x1, y2);
            (x2, y1); (x3, y1); (x1, y1); (x4, y1)]

  // Some labels near the components
  Texts[Font["Helvetica", 4.0],
        "T1", t1.Get[0.5], From[(2.1, 0.5)];
        "R1", r1.Get[0.5];
        "R2", r2.Get[0.5], From[(1.9, 0.5)];
        "T2", t2.Get[0.5], From[(-0.9, 0.5)];
        "R3", r3.Get[0.5];
        "R4", r4.Get[0.5];
        "C1", c1.Get[0.5], From[(0.5, -1.5)];
        "C2", c2.Get[0.5]]
]

// Save the figure into a postscript file
w.Save["multivibrator.png", Window["rgb24", .Res[Dpi[100]]]]

Table Of Contents



This Page



Get The figure description language: Box at SourceForge.net. Fast, secure and Free Open Source software downloads