Matteo Franchin's corner

wheatstone.gdlΒΆ

Example of how GDL handles figures and places them.

zhangli-2

Figure: after running the GDL program, we obtain this image (MS bitmap format in this case)

' This example shows how the Put instruction can be used to express how
' an object should be placed inside a figure: we will draw the wheatstone
' bridge with some resistors replaced by other electrical components (just
' to show how one can draw them!)
include "stddefs.gdl"

>< Units !mm, !deg, !dpi

' Here we define some electrical symbols
'-------------------------------------------------------------------------------
diode <- Window !type "fig"
a = 2.0
b = 3.0
d1 = 4.0
s = 0.4
>< Poly (0, -a), (0, a), (b, 0)
>< Poly (b-s/2, -a), #0+(s, 0), #0+(0, 2*a), #0-(s, 0)
>< Line Hot[(-d1, 0)], 0.2, Hot[(b+s/2+d1, 0)]

'-------------------------------------------------------------------------------
inductance <- Window !type "fig"
a = 1.1
b = 2.2
d1 = 2.0
v = 0.5
v1 = (a, b) + (v, 0)
v2 = (a, -b) + (v, 0)
v3 = (-a, -b) + (v, 0)
v4 = (-a, b) + (v, 0)
>< Line line_smooth, Hot[(0, 0)], 0.2, #0+(d1, 0), _
  #0+v1, #0+v2, #0+v3, #0+v4, #0+v1, #0+v2, #0+v3, #0+v4, _
  #0+v1, #0+v2, #0+v3, #0+v4, #0+v1, #0+v2, #0+v3, #0+v4, _
  #0+v1, #0+v2, #0+v3, #0+v4, #0+v1, #0+v2, #0+v3, #0+v4, _
  #0+v1, #0+v2, Hot[#0+(d1, 0)]

'-------------------------------------------------------------------------------
resistor <- Window !type "fig"
d1 = 1.0
v1 = (1, 4)
v2 = (1, -4)
R <- Line line_hurtful, Hot[(0, 0)], 0.2, (d1, 0), #0 + v1/2, _
    #0 + v2, #0 + v1, #0 + v2, #0 + v1, #0 + v2, #0 + v1, _
    #0 + v2, #0 + v1, #0 + v2, #0 + v1, #0 + v2, #0 + v1/2, Hot[#0 + (d1, 0)]

'-------------------------------------------------------------------------------
wheatstone <- Window !type "fig"
d1 = 20.0       ' d1 = half diagonal of the wheatstone bridge
p1 = Hot[(0, -d1)]
p2 = Hot[(d1, 0)]
p3 = Hot[(0, d1)]
p4 = Hot[(-d1, 0)]

' Place the resistors
R12 <- Put resistor, "rt", !near[1, p1], !near[2, p2]
R23 <- Put diode, "rt", !near[1, p2], !near[2, p3]
R34 <- Put resistor, "rt", !near[1, p3], !near[2, p4]
R41 <- Put inductance, "rt", !near[1, p4], !near[2, p1]

' Connect them
>< Line p1, R12->1; R12->2, p2; R12->2, p2; p2, R23->1; _
 R23->2, p3; p3, R34->1; R34->2, p4; p4, R41->1; R41->2, p1

' Draw small circles on the nodes
>< Circle 0.8, p1; p2; p3; p4

'-------------------------------------------------------------------------------

>< Print "Opening a new window of type 'bm4' where to put the figure!"
main <- Window (80, 80), !resx 400 , !type "bm4"
>< Put wheatstone, (40, 40)

>< Print "Saving the figure into the file 'wheatstone.bmp'"
main -> Save "wheatstone.bmp"