MoveLetter

The film and computer game industries have developed sophisticated techniques for showing moving objects. This example covers some basic principles. Program MoveLetter shows the basics of movement very simply: draw an object, wait, restore the background then draw the object in a new position. In this program the object is the character 'N' and it traces its own shape.

program MoveLetter;
  {$mode objfpc}{$H+}
uses
  Classes, SysUtils, CRT;
const
  SLEEP_TIME = 25;
  HEIGHT = 24;
  CHARACTER = 'N';
var
  Width : integer;

procedure Diagonal;
var
  i : integer;
begin
  for i := 1 to HEIGHT do
    begin
      goToXY(i, i);
      write(CHARACTER);
      sleep(SLEEP_TIME);
      goToXY(i, i);
      write(' ');
    end;
end;

procedure Up (Column : integer);
var
  i : integer;
begin
  for i := HEIGHT downto 1 do
    begin
      goToXY(Column, i);
      write(CHARACTER);
      sleep(SLEEP_TIME);
      goToXY(Column, i);
      write(' ');
    end;
end;

begin
  Width := HEIGHT;
  cursorOff;
  Up(1);
  Diagonal;
  Up(Width);
  //Replace the deleted letter in its final position 
  write(CHR(8), CHARACTER);
  cursorOn;
  readln;
end.
Programming - a skill for life!

Introduction to Motion Graphics