Tutorial - Getting Started

This tutorial gives a quick introduction to get you started with the system and allows you to check that it is working. There will be a lot of detail left out.

I will be using very simple examples to avoid getting distracted by details; this will allow us to concentrate on the language features. As a result it will appear at times that the approach is overkill. As we go along try to think of your own examples where a specific feature would make the programming easier.

To save space on these pages and on the disk the sample output will be generated for a page size of 320 x 200 pixels. The main text of the tutorial will usually contain just the sections of the code relevant to the topic being discussed but there will always be a link to the fully functioning program that was used to generate the output.

Minimal Program

The program shown below is about the smallest program file that will actually produce an output.

Program( )

    Begin

	Line({100,100}, {200, 100});

    End;

Running the Program

This sample is in "minimal.grs". The program can be compiled and run with the following command :-

grarls minimal.grs

when run like this a lot of the default settings are read in from the "grarls.ini" file. The sample source code in these tutorials have a header with details of the full command line used for the sample output supplied.

minimal.grs

Output of minimal.grs minimal.png

The Program keyword defines the entry point for the program. The parentheses that follow it are required even, as in this case, where there is nothing inside. The actual statements to be executed will occur between the Begin and End keywords.

This program has a single statement that draws a line. It should be fairly intuitive how it works. The start and end points are two-dimensional coordinates ( hence two values with the braces ). The first value of the coordinate pair is the distance in pixels for the left hand side, the second is the distance in pixels from the top. A value of {0,0} will refer to the top left pixel.

Before we go on I would like to introduce the idea of comments. When writing code it is always a good idea to add comments to the code so that someone else ( or even you at a later date ) can see what the code is meant to do. Comments appear as follows :-

	[= draw a single horizontal line =]
	Line( { 100,100 }, { 200, 100 } );

Comments may be nested :-

    Begin

	[=

	Comment out the code and the comment. 

	[= draw a single horizontal line =]
	Line( { 100,100 }, { 200, 100 } );

	=]

    End;

Variables

It is possible to add variables to a program. Variables are a way of holding a value that may be used more that once and possible be changed between uses. All variables must be declared before used. In this case we will declare a variable that can be used within the Program routine.
Program( )
	Number displacement;
    Begin
	displacement := 50;	
	Line( { 100,displacement }, { 200, displacement } );
	displacement := 100;
	Line( { 100,displacement }, { 200, displacement } );
    End;

The Number keyword says that the variable will be a numeric value. You can also have Logical variable ( which may be True or False ) and Text variables as well as more complex types. You may also define your own complex types.

All variable should be set to a value before they are used. Any variable not set will be initialised to Null ( which will be type specific ). It is possible to explicitly test a variable to see if it is Null.

A variable may be initialises when it is declared :-

Program( )
	Number displacement = 100;
    Begin
	Line( { 100,displacement }, { 200, displacement } );
    End;

Output Statement

Before going further I want to introduce a special statements that is intended for printing out diagnostic information to the screen ( rather than to the graphics file ).

Program()
	Number cats = 10, dogs;
    Begin
	Output cats, dogs;
    End;

This will print out the value of the variables 'cats' and 'dogs' to the screen.

10, Null

Notice that if the variable does not have a value then 'Null' will be displayed.