Tutorial in Pascal Programming Animation

Written by kevin walker
  • Share
  • Tweet
  • Share
  • Pin
  • Email
Tutorial in Pascal Programming Animation
(Photos.com/Photos.com/Getty Images)

The Pascal programming language is often used as an introductory language for teaching computer programming to students. There are many versions of it, but the most common are Borland's Turbo Pascal and Free Pascal. This tutorial was written using Free Pascal, but all versions of Pascal share the same features, so the code should transfer without modification between different versions. Pascal is an imperative, structured programming language. The animation features are provided by the "Graph" function library that comes with the language. It is fully described in Chapter 18 of the Run-Time Library Reference Guide linked to in the first reference.

Skill level:
Moderately Easy

Other People Are Reading


  1. 1

    Create a next file in your favourite text editor. Any plain text editor will do, including Windows Notepad, though you may prefer to use a dedicated Pascal editor like the free program Lazarus.

  2. 2

    Paste the following header data into the text editor to initialise the variables that will be used in the animation tutorial:

    Program Pascal_Animation_Tutorial;

    Uses Crt, Graph;

    Var video Driver, gMode : Integer;

    Var x, y, w, h : Integer;

    Var loop : Boolean;

    Var colour : Integer;

    This imports both the CRT (for dealing with the console) and graphics libraries. Then it declares variables for the graphics driver, the graphics mode, the position and height of a graphic element along with its colour, and a boolean to control the animation loop.

  3. 3

    Paste the following code immediately after the last code to initialise the values of the variables:

    video Driver := DetectGraph;
    InitGraph(video Driver, gMode, '');
    x := 40;
    y := 40;
    w := 10;
    h := 10;
    colour := Red;
    loop := True;

    The video driver provides the interface to the screen and gMode holds the current resolution and colour depth. X, Y, W, and H will hold the X and Y coordinates on the screen to draw the animation, as well as its width and height. Colour will hold the current colour (in this case, Red).

  4. 4

    Paste the following code to create the main loop, which will draw an ellipse, move it a little, and clear the screen to draw it again. When done repeatedly, it will produce an animation of a ball moving across the screen. It will also check for the user to quit by press the "Q" key.

    while (loop)
        FillEllipse(x, y, w, h);
        x := x + 1;
        y := y + 1;
        if (ReadKey == 'Q') then loop := False;

Don't Miss


  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.