Tutorial in Pascal Programming Animation

Written by kevin walker | 13/05/2017
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.

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.

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.

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

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).

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.


  • 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.