Next Previous Contents

3. Simple Applications

We begin our tour of GLE with some basic examples of what can be done. For each we will present both the finished diagram and the script used to produce it along with a discussion of the important points raised within the script.

3.1 Hello world

This program demonstrates the use of absolute and relative movment and some basic text editing.


!Helloworld.gle - Illustrates the use of basic GLE commands

size 24 18                      !Sets the size of the graphic in cm

amove 2 2                       !Demonstrates the difference between relative
aline 10 2                      !and absolute movement
rline -8 2
rline 8 0 
amove 7 7
                                !Displays some basic text
text Hello world                
set font plge
set hei 0.5 
amove 4 4
text How are you today?

rmove 0 5                       !Displays some simple shapes
circle 1
amove 8 9
circle 1 fill grey20

The small choice of commands in GLE means the syntax has not deviated too far from recognisable English. Even if the exact meaning of all the lines in the above code is not clear, it should be possible to follow through the steps which produce the results in the diagram.

The GLE code

Like all other programming languages GLE breaks down the task into a series of small steps. These are represented by the series of lines in the code, each line represents an individual step and the end of line character (produced whenever the return key is pressed) tells GLE where each step begins and ends. Although, as we shall see later, it is possible to combine several steps in the same command it is always necessary to begin each command on a separate line.

Most GLE commands require some sort of qualifier, an additional string of information that tells GLE how and where to perform the operation. In the above program we can see that the qualifiers are mainly numbers, in this case representing coordinates.

It is also worth noting early on the use of comments , as in many other high level programming languages GLE provides a system for the programmer to leave notes or descriptive passages within the code. These comments are invisible to the compiler and are not present in the finished diagram. Their sole purpose is to make the programming script both easier to read and more transparent when making revisions. In GLE we denote a comment by the use of the exclamation mark (!), any text entered between the excamlation mark and the end of line character that signifies the start of a new line is ignored entirley by the compiler. The text command is an exception to this rule, an exclamation placed after a text command is treated as an exclamation, and will appear in the diagram.

With the exception of the end of line character GLE ignores all whitespace in a program. The constructive use of this whitespace combined with suitable comments can make a program much easier to error check and revise, both for the original programmer and for others. Similarly GLE is case insensitive. The commands,

size 20 18
SIZE 20 18
sIZe 20 18
Are all, from the point of view of the compiler, identical. Again through the use of capitals we can make a script easier to read. There are no accepted conventions, but it make sense to stick to the same format throughout a program.

Measurments in the GLE environment

The first line of the ‘Hello world’ program is size 24 18. This defines the size of the diagram in cm, so that our working area is now 24cm by 18cm. Commands are referred to a grid of points from (0,0) to (24,18), any command that refers to a point outside this range will not appear in the final graphic. With a few exceptions GLE diagrams start with a size command, and should at least contain one somewhere within the program.

Notice that GLE will still compile a program with an illegal coordinate reference, one that refers to a point outside of our working area. The diagram will only show the part of the diagram that lies within the dimensions of the size command. This can be useful in cases where the diagram has a particular symmetry. For example, we may be interested in the lines of an electric field caused by a charge distribution. We can set up the equations that govern this distribution and then, using the size command, look only at a small portion of the field. Of course, the fact that GLE understands illegal coordinate references is no guarantee that any other publishing program will. Often a second graphics package will ignore the size command and attempt to draw out the entire graphic in all its glory. If this happens then the best solution is to add a clip command, covered in section Clipping, to the start of the program such that only the desired portion is viewed.

Fractional coordinates are also allowed, and in many cases essential. The resolution depends upon the output device but in general structures below 0.1 mm are not well resolved and lines less than 0.0001 mm are very faint. Negative coordinates are also allowed, although obviously lines cannot have a negative width nor fonts a negative height.

Relative and absolute motion

A GLE script consists of a set of instructions that GLE interprets to build up the completed picture. Each operation is referred to a coordinate point. At the start of the program the first command refers to the point (0,0) at the bottom left hand corner of the page. Thereafter the current point is defined by the end of the last operation, though what GLE defines as the end of an operation and what we define as the end of an operation may differ.

We have four basic commands for moving around the diagram, each expressed in terms of relative or absolute motion.

amove x y

Moves the cursor to the absolute coordinates (x,y).

aline x y

Draws a line from the current point to the coordinates (x,y).

rmove x y

Moves the cursor by a relative amount such that the new coordinates are the sum of the initial coordinates and the values of x and y.

rline x y

Draws a line from the current point to the point a vector (x,y) away.

Clearly both sets of commands are very similar, and the same diagram can be drawn with any combination of the above. However, absolute movements are less prone to errors and are easier to visualize. Relative movements are important when creating figures that can be expressed in terms of a continuous path or set of operations and can help simplify the construction of complex diagrams considerably.

We can add arrow heads to the lines we draw, both relative and absolute, by the arrow start, arrow end or arrow both commands. For example in our program we can draw an arrow on the final line with the command

rline 8 0 arrow end
The first few lines of our program therefore draws a simple shape using a combination of the above commands. Because of the nature of the GLE interface there is a lack of immediate feedback from any alteration to the program. To save time and typing it is a good idea to plan out the commands on graph paper, to get a general feel for the layout of the diagram, before attempting the GLE script.

Basic text support

The next section of our program deals with the basics of introducing text onto a diagram. The command text tells GLE that everything from the first character following the command to the next end of line character is to be printed onto the page. If the line of text is too long then the text will not all appear on the diagram; there is no provision for the text to run onto the next line. Writing text at a given coordinate point also does not change that coordinate point so if we had written:

text Hello
text How are you?
Then the ‘How are you’ would have been superimposed over the ‘Hello’ . To add a line of text after a previously written one we must instruct GLE to move the cursor to the end of the text box. For most fonts which do not have a constant letter width this would be difficult to do, however there is a command which we can use to simplify the problem. xend() and yend() are qualifiers which will return the coordinates of the last point drawn, thus to write a following string of text we would write:
text Hello
amove xend() yend()
text How are you

Where the command amove xend() yend() instructs GLE to move to the coordinates of the last letter of ‘Hello’ . Notice that we could not have solved the problem by writing:

text Hello
text       How are you?

As GLE does not recognise the spaces placed immediately after the text command. GLE will, however, recognise many of the LaTeX special characters. In particular we may use \: to represent a space, and \glass to indicate the beginning of a line.

text Hello
text \glass \: \: \: \: \: How are you
The \glass command is neccessary as, by default, GLE will not print either real spaces or the character representation unless preeceded by another character.

A list of related LaTeX commands supported by GLE is given in the index. Note however that GLE is not a dedicated text compiler. The following program illistrates some of the problems that can occur in the use of some special characters.


!sub.gle - Demonstrates the problems that can occur when using sub- and superscripts
size 10 10
set font texcmr

amove 1 9       !Single sub- and super scripts work fine        
text E=mc^2

amove 1 7.5
text h_2O

amove 1 5.5             !Problems occur when we try to add both sub- and 
                        !superscripts
text \omega_{Debye}^{2}   

amove 1 3.5             !We can of course nest expressions within each other
                        !using brackets
text e^{v^{2}/2k_{b}T}    
amove 1 1                       !Without brackets GLE takes the first single
                                !character
text Problems_{with}^scripts       

The LaTeX commands for the use of subscripts and superscripts are _{} and ^{}, where the curly brackets can be replaced by normal brackets. In the absence of any brackets GLE will assume that only the first single character is to form the subscript or superscript. Greek letters are normally produced by a \ followed by the name of the letter.

The set command has a special role in GLE. It allows the defalt values for a number of commands to be specified. They will remain this way until another set command changes them, or until the program ends. Thus the command set font plge sets the font to Plotter Gothic English (plge), any text command that follows will display text in the Gothic font. We can also set the width of the lines in the stroked (plotter) fonts using the set fontlwidth 0.2 command, which will set the line width to 0.2cm.

The set hei 0.5 command defines the height of the font. For reasons stemming from the original typesetting of letters on printing presses a 10cm high font has letters that are only about 6.5cm high. Again the set command remebers the height, and includes it in all following text. If no set command is issued the default height is 1cm.

To write longer sections of text and tables there are dedicated commands that more accurately control the formatting. We mention one here, and defer a fuller treatment to another example. The set just command aligns the text either to the left, right or center. For example,

amove 4 4 
set just right
text Hello
rmove -2 -2 
set just center 
text How are you
Will print two lines of text, one justified right of (4,4) and the other centred on (2,2).

Shapes and Sizes

The final section to our program draws some basic shapes. Many of these can be constructed from the aline and rline commands (though circles are difficult), but it makes sense to have dedicated keywords for the more common shapes. Following each shape command we add a qualifier that defines the size, and there are also optional qualifiers that can add fill shades and colours to the shape. The various fill styles are provided in a reference chart at the end of this document, they can take the form of either a named colour (black, white, red...), a grayscale (grey1 to grey100), or a predefined pattern. There is a difference between a white fill style and no fill style - a shape filled in white will obscure any drawing that has taken place beneath it, no fill style will allow it to show through.

We may also define the colour of the circle outline using the set color command (note the American spelling). We could have drawn a red circle with a blue filling using:

set color red
circle 2 fill blue

Another common predefined shape is the box, this requires two size variables a height and a width. Again we may specify line and fill styles as with the circle. For example:

set color red
box 5 2 fill grey20
Draws a grey box with a red outline. To remove the outline we can add the qualifier nobox to the end of the box command which will tell GLE not to add an outline.
box 5 2 nobox

3.2 More text examples

In this section we take a longer look at some of the different text options we may use.


!text.gle - Demonstrates some of the text options available within GLE

size 20 17                      !Sets the size of the window

amove 1 10.5                    !Writes a poem
set color red
set hei 0.8
begin text
        Mary had a little lamb
        Its fleece was white as snow
        And everywhere that Mary went
        The lamb was sure to go
end text

amove 12 15                     !Writes an explanation
set color black
set hei 0.5
begin text width 5
        The begin and end text commands allow longer passagest of text to be 
incorporated within a GLE file. If we specify the width of the text then GLE 
will wrap lines around at that width. Without a width qualifier GLE will att
empt to recreate the format of the text in the program script, as we see w
ith the poem.
end text

amove 1 5                       !Draws a table
begin table

This is a table, GLE maintains the format seen in the program script

Field (T)       Displacment (mm)        Frequency (GHz)
0.1             0.445                   4.22
0.2             0.454                   4.23
0.3             0.470                   4.87
0.4             0.479                   5.22
0.5             0.487                   5.97

end table

The code demonstrates how the begin text and end text commands can be used to construct longer passages of text. Everything between the two commands is treated as a text file, GLE does not recognise any keywords or comments within the text however it will recognise most LaTeX commands for displaying special character. A list of these can be found in the appendix.

If no width is specified then GLE will attempt to format the text as it is set out in the script. With a width specified (in cm) GLE will wrap text around to the required width; though it will still respect end of line characters and multiple spaces.

The table option is used when the text must be aligned into columns. GLE reads the spaces and tabs and aligns the text accordingly. When creating tables it is best to use a fixed pitch font, that is one with a constant letter width, rather than a variable one. This aligns not only the left hand side of the text but the right hand ones as well.

3.3 All shapes and sizes

Here we look at more complex shapes that can be drawn as well as many shorthand commands that make the construction of flow diagrams or charts much easier. Be aware however that this section does not use the full programming ability of GLE. Some of the commands introduced in section 4 can make the following program much more compact.

So far we have accepted the default positioning of the shapes we have drawn. However it is possible to have a far greater control, both over the shapes and over the orientation of the text. The following program shows the naming convention that is used.


!justify.gle - Illistrates the shorthand names for the justify and join commands

size 20 20              !Sets the size of the viewing window

set just CC             !All text from now on will be center justified

amove 10 10             !Draws the box in the center and adds text
set hei 0.2
box 4 2 just CC name centerbox

begin text width 3.5
        The justify and join commands refer to the corners of a box with the shown 
convention. TL stands for 'Top Left', CR for 'Center Right' etc.
end text

set hei 0.5             !Formats the following text

!The following commands write out the shorthand labels and draw boxes around them
amove 10 15                             
begin box add 0.2 name topbox
text TC
end box

amove 15 15
begin box add 0.2 name toprightbox
text TR
end box

amove 15 10
begin box add 0.2 name rightbox
text CR
end box

amove 15 5
begin box add 0.2 name bottomrightbox
text BR
end box

amove 10 5
begin box add 0.2 name bottombox
text BC
end box

amove 5 5
begin box add 0.2 name bottomleftbox 
text BL
end box

amove 5 10
begin box add 0.2 name leftbox
text CL
end box

amove 5 15
begin box add 0.2 name topleftbox
text TL
end box

!These commands join the central box to the others with arrows
join centerbox.tc <- topbox.bc
join centerbox.tr <- toprightbox.bl
join centerbox.cr <- rightbox.cl
join centerbox.br <- bottomrightbox.tl
join centerbox.bc <- bottombox.tc
join centerbox.bl <- bottomleftbox.tr
join centerbox.cl <- leftbox.cr
join centerbox.tl <- topleftbox.br

Naming objects

Within GLE we can refer to a point on the screen or an object by a predefined names, GLE will substitute the absolute coordinates of the point. This has the advantage that, in a subsequent line of programming, any given point can be referred to by name as opposed to a string of coordinates. Thus, if we require the coordinates of the top left hand corner of a box, we can refer to it by its name followed by an extension for the left hand corner. We can also save an individual point for later use,

amove 4 4 
save point1
amove 3 3
save fred
join fred - point1
This will join the two points (4,4) and (3,3).

The justify commands

The second line of the program set just CC tells GLE that all following text should be centered over the reference point. Notice that this is different from the center command which positions the text according to its bottom center. Similarly left is identical to BL (bottom left), and right is identical to BR (bottom right). We may use the labels interchangably, and we may also swap the order of letters, so BR is the same command as RB or rb.

The set justify command only applies to text, so when we come to draw the box around the text with the command,

box 4 2 just CC name centerbox
We must specify the positioning with the just command. CC can be replaced with any other handle as required.

The join command

The usefulness of naming objects is shown above when we wish to join together two objects. We could, of course, have used the aline command, but then we would need to know the coordinates of each point on the boxes. It is far easier to refer to each point by its name and let GLE work out exactly where it is.

The join command draws a line between two named points in the same way that the aline command draws a line from the reference point to the given coordinate. So the command:

join abox.tl - anotherbox.br
Will connect the top left hand corner of ‘abox’ to the bottom right hand corner of ‘anotherbox’. The ‘-’ can be replaced with a ‘<-’ for a single arrow; a ‘->’ for an arrow in the opposite direction; or ‘<->’ for a double headed arrow.

Along with the commands above there are four other options we should look at. The first occurs if we fail to specify any justification at all on an object:

join object1 - object2.tl
In this case GLE will join the top left hand corner of object2 to the centre of object1, however the line will be clipped at the edge of object1.

We may also specify that the line joining two objects be either horizontal or vertical, using the h and v qualifiers.

join object1.h object2
Indicates that object1 should be joined to object2 by a horizontal line. If two statements are present then GLE will draw a line which satifies both, but the lines will no longer neccesarly connect the two objects.

Finally we can use the command ci. This is similar to the absence of any justify type, but in this case GLE will clip the line at the circumference of the largest circle that can be drawn within the confines of the box. Obviously, the main application of the ci command is to join circles.

The following code demonstrates many of these remaining points:


!just2.gle - Demonstrates the remaining justify commands
size 10 10

amove 5 5 
                                !Draws the centre circle
begin box name circle nobox
circle 1 
end box

amove 0 8                       !Draws two boxes
box 9 0.5 name topbox nobox fill grey20

amove 8 0
box 0.5 9 name rightbox nobox fill grey20

join circle.v <-> topbox.rb          !Joins the various objects
join circle -> rightbox.h
join circle.ci - topbox.lb 
join circle.tl - topbox.lb
join circle.v <-> topbox.rb

Notice that the circle.v <-> topbox.rb creates a line that does not come into contact with the circle itself. We also see that using the command circle.tl - topbox.lb joins to the corner of the box containing the circle. If we wish to connect to the circle itself then we must use the ci justifier.

Begin box and end box

Although we now have a fair degree of control over the positioning of the shapes, in many cases it is an advantage not to have to specify the dimensions of the shape at all. We may instead merely wish to have a box that encloses some text with a margin on each side, without having to worry about the text overrunning the sides of the box. For this the begin box command is provided. This draws a box around everything in between the begin box and end box command. This includes text, other shapes, or graphs. The usual qualifiers can be added to the box command with the addition of add which specifies the margin left between the extent of the enclosed object and the edge of the box. For example,

begin box fill grey20 add 1.5 nobox name mybox
        (...)
end box
Will draw a grey box without a border aroung the enclosed commands (...), the add 1.5 command gives a 1.5cm margin on all sides. In the remaining program it will be possible to refer to the coordinates of the box using the name mybox and one of the corners. For this we do not know, or need to know, the absolute coordinates of the box.

3.4 Lines and line widths

We look at another example of the use of graphics. Notice how this program makes the distinction between absolute and relative movement. Relative movement is used in the construction of each individual block and absolute movement is used in moving between the blocks. In an ideal world there would be no advantage to either, but using this form ensures that if we make an error and wish to move one of the blocks then only one coordinate must be changed. Similarly, if we wish to resize one of the elements of the diagram then it is easier to deal in relative measures rather than having to work out the absolute position of each point.


!lines.gle - Demonstrates the various options for lines and markers
size 10 8

set hei 0.5 
set just CC                     !Adds a title
amove 5 7.5
text Line styles and markers

set hei 0.3 
set just LC             !Adds a title and box to the different line styles
amove 0.7 6.5

begin box add 0.25 
        text Different line styles

        rmove 0 -0.5                    !Draws the various line style options
        set lstyle 0                    !Ideally this should be placed 
                                        !within a subroutine
        rline 2 0                       !See following section
        text \glass \: \: 0

        rmove -2 -0.5
        set lstyle 1
        rline 2 0
        text \glass \: \: 1

        rmove -2 -0.5
        set lstyle 2
        rline 2 0
        text \glass \: \: 2

        rmove -2 -0.5
        text \glass \: \: ...and so on

        rmove 0 -0.5
        set lstyle 8
        rline 2 0
        text \glass \: \: 8

        rmove -2 -0.5
        set lstyle 9
        rline 2 0
        text \glass \: \: 9

        rmove -2 -0.7           !We can produce a line from a combination of    
        set lstyle 9229         !the other line styles
        rline 2 0
        text \glass \: \: 9229

        set lstyle 1
end box


amove 4.6 6.5                   !Demonstrates the different markers available

set lwidth 0.05 
rline 0 -2

set lwidth 0.0001
rmove 0 0.5
marker wcircle 0.8
text \glass \: wcircle

rmove 0 0.5
marker fcircle 0.8
text \glass \: fcircle

rmove 0 0.5 
marker circle 0.8
text \glass \: circle

amove 6.4 6.5
 
set lwidth 0.05
rline 0 -2

set lwidth 0.0001
rmove 0 0.5
marker wsquare 0.8
text \glass \: wsquare

rmove 0 0.5
marker fsquare 0.8
text \glass \: fsquare

rmove 0 0.5
marker square 0.8
text \glass \: square

amove 8.4 6.5

set lwidth 0.05 
rline 0 -2

set lwidth 0.0001
rmove 0 0.5
marker wdiamond
text \glass \: wdiamond

rmove 0 0.5 
marker fdiamond
text \glass \: fdiamond

rmove 0 0.5
marker diamond
text \glass \: diamond



amove 5 4                       !Draws examples of the different line widths
set lwidth 0.2
rline 1 0
text \glass \: 0.2

rmove -1 -0.3
set lwidth 0.1
rline 1 0
text \glass \: 0.1

rmove -1 -0.3
set lwidth 0.05
rline 1 0
text \glass \: 0.05

rmove -1 -0.3
set lwidth 0.02
rline 1 0
text \glass \: 0.02

amove 7.5 4

set lwidth 0.01
rline 1 0
text \glass \: 0.01

rmove -1 -0.3
set lwidth 0.005
rline 1 0
text \glass \: 0.005

rmove -1 -0.3
set lwidth 0.0001
rline 1 0
text \glass \: 0.0001

rmove -1 -0.3
set lwidth 0
rline 1 0
text \glass \: 0

 
amove 0.5 0.5                   !Shows the different options for ending a line
box 2 1.5

rmove 0 0.25
set cap square 
set lwidth 0.2 
set hei 0.3
rline 2 0 
text \glass \: set cap square

rmove -2 0.5
set cap round 
rline 2 0
text \glass \: set cap round

rmove -2 0.5
set cap butt
rline 2 0
text \glass \: set cap butt


amove 5.5 2.5                   !Shows the different options for joining lines
set lwidth 0.1 
set just CC                     !Notice that the path is split - this is significant
set join mitre
rline 4 0
rline 0 -1
set join round
rline 0 -1
rline -2 0
set join bevel
rline -2 0
rline 0 2

rmove 0.5 -0.25                 !Adds text labels to the various joins
rmove 3 0                       !We could not have done this within the 
                                !join commands themselves - see main text
text mitre
rmove 0 -1.5
text round
rmove -3 0
text bevel

The purpose of many of the commands can be seen from the graphical output, this kind of program with a lot of repeated steps can be simplified greatly by the use of subroutines. However, we will postpone a discussion of other possible programming structures until the following section, dealing here only with the commands' literal meaning.

After defining the size of the page and adding a title, the script draws a number of different line styles using the command:

set lstyle n
Where n is an integer which represents the different line styles, there are 10 (0..9) pre-defined styles. We can make additional ones by combining digits,
set lstyle 9229
This produces a line style that is a sum of individual styles, we begin with a black line style 9, then superimpose on top a style 2 in white, followed by a style 2 in black and a style 9 in white.

Markers are shapes that are attached to a given point in a diagram, we are free to define their size using a height in cm following the marker command. As with fonts the actual height of the marker is only about 65% of the specified height.

We can also specify the width of a line created either with the rline and aline commands or with a join command. We use,

set lwidth 0.2
Which sets the line width to 0.2 cm. The default setting for the width is 0.02, if we set the line width to zero then GLE will adopt the default value. Thus, a line width of 0.0002 is (100 times) thiner than a line width of zero.

When working with significant line widths we can specify how the lines begin, end, or join. The first two are controlled by the set cap command. This can either produce a line that is clipped exactly, a line that has a rounded cap at each end, or a line that has a square cap at each end. The various forms are illustrated above.

The set join command is more complex, by default GLE will simply overlap two lines that are connected to the same point. To invoke the different types of join we must form a continuous path from one point through another and onto a third. That is,

set join round
amove 1 1
aline 1 2
aline 2 1
Will form a rounded join at (1,2). If we break the path by inserting a command in between,
set join round
amove 1 1
aline 1 2
text This is not a rounded join
aline 2 1
Then the join style will not apply. If either the incoming line or outgoing line is under a different join style then, again, the style will not apply.
set join mitre
amove 1 1 
rline 1 0
rline 0 1
set join round
rline -1 0
This will produce a mitred join at (2,1) but the rounded join will not apply at (2,2) as the incomming line still has the previous set join mitre style. If we were to produce a rounded join then, as in the script above, we would need to split the line into two parallel, colinear, segments.


Next Previous Contents