Flying UK

Navigation game

Introduction

You can use program FlyingUK, now available here as a web version, to improve your knowledge of the relative positions of towns and cities in Wales and most of England. The flying speed depends on the distance from cursor to the plane (represented by a line), so you can use your mouse to control both the speed and direction of the plane.

The following screen shot shows program FlyingUK in action.

FlyingUK in action

FlyingUK in action

Procedure setPointsUp first draws lines approximating to the coastline and then uses a line of text in places.txt for the data in a single town or city. Each line of text consists of the x and y coordinates of a town/city and its name. For example, the data for three Welsh places is:

b3662 6477 Cardiff
3631 6262 Caerphilly
a3923 6246 Newport

The prefix code code (no prefix, a or b) represents size the of the place. The code governs the mark (point, small square or larger square) and font for the name on the map representing the place. Peter generated the points for coast and for towns automatically by clicking on a map in a support program.

You need to add the text file places.txt to the program folder. Download data file places.txt. In order to run program FlyingUK, you will need to have downloaded also Stefan Berinde`s wingraph.zip file as described in our Graphics tutorial. You should copy the unzipped wincrt.pas, wingraph.pas and winmouse.pas (from the src folder) into your program folder. (The compiled units are included in the zip file but you might as well have the source code available for reference). You should find these three files useful for your own motion graphics programs.

How quickly can you fly over Bridlington, Sheffield, Manchester, Wrexham then Southampton? Can you find Hessle?

The Program

program FlyingUK;
{
    Copyright (c) 2011 Peter Hearnshaw

    Licensed under the Apache License, Version 2.0 (the "License"); you may not
    use this file except in compliance with the License, as described at
    http://www.apache.org/licenses/ and http://www.pp4s.co.uk/licenses/
}
uses crt, sysutils, winmouse, wincrt, wingraph;

var
  Gd, Gm : smallint;
  degr,x1,x2,y1,y2,movex,movey,distanceAway,Tsize: integer;
  xmiddle, ymiddle : integer;

procedure placePoint(x : integer; y : integer;place : string; Tsize : integer);
begin
  case Tsize of
     1: begin
          Putpixel(-movex+x,-movey+y, yellow);
          Putpixel(-movex+x,-movey+1+y, yellow);
          Putpixel(-movex+1+x,-movey+y, yellow);
          SetTextStyle(DefaultFont,HorizDir,3);
        end;
     2: begin
          setcolor (yellow);
          SetFillStyle(solidfill, yellow);
          fillrect(-movex+x,-movey+y,-movex+x+3,-movey+y+3);
          SetTextStyle(BoldFont,HorizDir,4);
        end;
     3: begin
          setcolor (yellow);
          SetFillStyle(solidfill, yellow);
          fillrect(-movex+x,-movey+y,-movex+x+8,-movey+y+8);
          SetTextStyle(BoldFont,HorizDir,5);
         end;
  end;
  SetColor(red);
  outTextXY(-movex+x+5,-movey+y-5,place);
end;

procedure setPointsUp();
var
  f : text;
  TFile, x, y, name : string;
begin
  //coast
  SetColor(lightblue);
  moveTo(-movex+3477,-movey+0);
  lineTo(-movex+3585,-movey+169);
  lineTo(-movex+3662,-movey+46);
  lineTo(-movex+3569,-movey+292);
  lineTo(-movex+3708,-movey+446);
  lineTo(-movex+3877,-movey+154);
  lineTo(-movex+3985,-movey+338);
  lineTo(-movex+4108,-movey+154);
  lineTo(-movex+4231,-movey+369);
  lineTo(-movex+4062,-movey+538);
  lineTo(-movex+4123,-movey+738);
  lineTo(-movex+3969,-movey+815);
  lineTo(-movex+3815,-movey+938);
  lineTo(-movex+3846,-movey+1138);
  lineTo(-movex+3969,-movey+1277);
  lineTo(-movex+4062,-movey+1277);
  lineTo(-movex+3938,-movey+1431);
  lineTo(-movex+3815,-movey+1708);
  lineTo(-movex+3846,-movey+1862);
  lineTo(-movex+3908,-movey+2077);
  lineTo(-movex+4062,-movey+2200);
  lineTo(-movex+4262,-movey+2246);
  lineTo(-movex+4077,-movey+2338);
  lineTo(-movex+3938,-movey+2185);
  lineTo(-movex+3831,-movey+2015);
  lineTo(-movex+3646,-movey+2077);
  lineTo(-movex+3754,-movey+2231);
  lineTo(-movex+3846,-movey+2431);
  lineTo(-movex+3462,-movey+2185);
  lineTo(-movex+3077,-movey+2308);
  lineTo(-movex+2708,-movey+2185);
  lineTo(-movex+2400,-movey+2462);
  lineTo(-movex+2354,-movey+2400);
  lineTo(-movex+2431,-movey+2308);
  lineTo(-movex+2262,-movey+2231);
  lineTo(-movex+2154,-movey+2046);
  lineTo(-movex+1938,-movey+2000);
  lineTo(-movex+1738,-movey+2062);
  lineTo(-movex+1585,-movey+2231);
  lineTo(-movex+1646,-movey+2400);
  lineTo(-movex+1892,-movey+2615);
  lineTo(-movex+2000,-movey+2692);
  lineTo(-movex+2154,-movey+2615);
  lineTo(-movex+2092,-movey+2708);
  lineTo(-movex+2015,-movey+2908);
  lineTo(-movex+1738,-movey+3154);
  lineTo(-movex+1523,-movey+3338);
  lineTo(-movex+1462,-movey+3523);
  lineTo(-movex+1708,-movey+3431);
  lineTo(-movex+1831,-movey+3462);
  lineTo(-movex+1877,-movey+3308);
  lineTo(-movex+2031,-movey+3262);
  lineTo(-movex+2277,-movey+3185);
  lineTo(-movex+2338,-movey+3431);
  lineTo(-movex+2462,-movey+3677);
  lineTo(-movex+2338,-movey+3892);
  lineTo(-movex+2431,-movey+4077);
  lineTo(-movex+2400,-movey+4308);
  lineTo(-movex+2292,-movey+4662);
  lineTo(-movex+2031,-movey+4800);
  lineTo(-movex+1785,-movey+4985);
  lineTo(-movex+1523,-movey+5015);
  lineTo(-movex+1323,-movey+5231);
  lineTo(-movex+1169,-movey+5292);
  lineTo(-movex+1031,-movey+5215);
  lineTo(-movex+1015,-movey+5338);
  lineTo(-movex+738,-movey+5508);
  lineTo(-movex+800,-movey+5677);
  lineTo(-movex+985,-movey+5723);
  lineTo(-movex+938,-movey+5923);
  lineTo(-movex+1031,-movey+6123);
  lineTo(-movex+1231,-movey+6185);
  lineTo(-movex+1385,-movey+6108);
  lineTo(-movex+1523,-movey+6062);
  lineTo(-movex+1585,-movey+5923);
  lineTo(-movex+1908,-movey+5908);
  lineTo(-movex+2031,-movey+5815);
  lineTo(-movex+2077,-movey+5938);
  lineTo(-movex+2169,-movey+6046);
  lineTo(-movex+2369,-movey+6077);
  lineTo(-movex+2108,-movey+6200);
  lineTo(-movex+2077,-movey+6369);
  lineTo(-movex+2308,-movey+6338);
  lineTo(-movex+2523,-movey+6400);
  lineTo(-movex+2538,-movey+6231);
  lineTo(-movex+2708,-movey+6169);
  lineTo(-movex+2846,-movey+6338);
  lineTo(-movex+3000,-movey+6554);
  lineTo(-movex+3415,-movey+6723);
  lineTo(-movex+3585,-movey+6662);
  lineTo(-movex+3692,-movey+6662);
  lineTo(-movex+3738,-movey+6477);
  lineTo(-movex+3969,-movey+6323);
  lineTo(-movex+4200,-movey+6323);
  lineTo(-movex+4354,-movey+6185);
  lineTo(-movex+4492,-movey+6046);
  lineTo(-movex+4631,-movey+5938);
  lineTo(-movex+4523,-movey+6169);
  lineTo(-movex+4292,-movey+6415);
  lineTo(-movex+4092,-movey+6523);
  lineTo(-movex+4000,-movey+6677);
  lineTo(-movex+3923,-movey+6800);
  lineTo(-movex+3923,-movey+7077);
  lineTo(-movex+3585,-movey+7154);
  lineTo(-movex+3215,-movey+7062);
  lineTo(-movex+3046,-movey+7062);
  lineTo(-movex+2846,-movey+7015);
  lineTo(-movex+2508,-movey+7077);
  lineTo(-movex+2200,-movey+7169);
  lineTo(-movex+2215,-movey+7415);
  lineTo(-movex+2077,-movey+7554);
  lineTo(-movex+1831,-movey+7508);
  lineTo(-movex+1708,-movey+7831);
  lineTo(-movex+1662,-movey+8077);
  lineTo(-movex+1492,-movey+8292);
  lineTo(-movex+1400,-movey+8446);
  lineTo(-movex+1154,-movey+8554);
  lineTo(-movex+1000,-movey+8815);
  lineTo(-movex+800,-movey+9108);
  lineTo(-movex+569,-movey+9292);
  lineTo(-movex+169,-movey+9385);
  lineTo(-movex+185,-movey+9662);
  lineTo(-movex+338,-movey+9631);
  lineTo(-movex+415,-movey+9492);
  lineTo(-movex+723,-movey+9615);
  lineTo(-movex+815,-movey+9846);
  lineTo(-movex+1031,-movey+9677);
  lineTo(-movex+1000,-movey+9477);
  lineTo(-movex+1154,-movey+9323);
  lineTo(-movex+1415,-movey+9231);
  lineTo(-movex+1492,-movey+9031);
  lineTo(-movex+1831,-movey+9046);
  lineTo(-movex+2092,-movey+8923);
  lineTo(-movex+2369,-movey+9015);
  lineTo(-movex+2785,-movey+9277);
  lineTo(-movex+3015,-movey+9262);
  lineTo(-movex+3154,-movey+8985);
  lineTo(-movex+3246,-movey+8585);
  lineTo(-movex+3308,-movey+8462);
  lineTo(-movex+3431,-movey+8415);
  lineTo(-movex+3600,-movey+8262);
  lineTo(-movex+3892,-movey+8215);
  lineTo(-movex+4046,-movey+8154);
  lineTo(-movex+4338,-movey+8246);
  lineTo(-movex+4677,-movey+8462);
  lineTo(-movex+4754,-movey+8385);
  lineTo(-movex+4908,-movey+8385);
  lineTo(-movex+5231,-movey+8477);
  lineTo(-movex+5369,-movey+8446);
  lineTo(-movex+5431,-movey+8369);
  lineTo(-movex+5354,-movey+8262);
  lineTo(-movex+5446,-movey+8215);
  lineTo(-movex+5662,-movey+8185);
  lineTo(-movex+5815,-movey+8154);
  lineTo(-movex+5923,-movey+8200);
  lineTo(-movex+6062,-movey+8062);
  lineTo(-movex+6262,-movey+7985);
  lineTo(-movex+6200,-movey+7862);
  lineTo(-movex+6538,-movey+8077);
  lineTo(-movex+6862,-movey+8062);
  lineTo(-movex+7015,-movey+8169);
  lineTo(-movex+7369,-movey+7985);
  lineTo(-movex+7723,-movey+7954);
  lineTo(-movex+8123,-movey+8031);
  lineTo(-movex+8446,-movey+8185);
  lineTo(-movex+8569,-movey+8108);
  lineTo(-movex+8662,-movey+7985);
  lineTo(-movex+8892,-movey+7908);
  lineTo(-movex+9138,-movey+7831);
  lineTo(-movex+9246,-movey+7708);
  lineTo(-movex+9492,-movey+7769);
  lineTo(-movex+9462,-movey+7600);
  lineTo(-movex+9615,-movey+7431);
  lineTo(-movex+9892,-movey+7323);
  lineTo(-movex+10092,-movey+7246);
  lineTo(-movex+10108,-movey+7046);
  lineTo(-movex+10046,-movey+6831);
  lineTo(-movex+10108,-movey+6723);
  lineTo(-movex+9923,-movey+6708);
  lineTo(-movex+9615,-movey+6754);
  lineTo(-movex+9431,-movey+6769);
  lineTo(-movex+9477,-movey+6708);
  lineTo(-movex+9369,-movey+6631);
  lineTo(-movex+9185,-movey+6554);
  lineTo(-movex+9108,-movey+6646);
  lineTo(-movex+9077,-movey+6523);
  lineTo(-movex+8815,-movey+6477);
  lineTo(-movex+8677,-movey+6569);
  lineTo(-movex+8492,-movey+6538);
  lineTo(-movex+8338,-movey+6508);
  lineTo(-movex+8523,-movey+6492);
  lineTo(-movex+8708,-movey+6523);
  lineTo(-movex+8769,-movey+6431);
  lineTo(-movex+9077,-movey+6385);
  lineTo(-movex+9323,-movey+6446);
  lineTo(-movex+9385,-movey+6277);
  lineTo(-movex+9477,-movey+6108);
  lineTo(-movex+9446,-movey+5908);
  lineTo(-movex+9138,-movey+5954);
  lineTo(-movex+9431,-movey+5815);
  lineTo(-movex+9738,-movey+5831);
  lineTo(-movex+9923,-movey+5631);
  lineTo(-movex+9831,-movey+5569);
  lineTo(-movex+9938,-movey+5400);
  lineTo(-movex+10246,-movey+5154);
  lineTo(-movex+10415,-movey+4969);
  lineTo(-movex+10415,-movey+4631);
  lineTo(-movex+10554,-movey+4400);
  lineTo(-movex+10631,-movey+4200);
  lineTo(-movex+10600,-movey+3846);
  lineTo(-movex+10462,-movey+3538);
  lineTo(-movex+10277,-movey+3400);
  lineTo(-movex+10062,-movey+3215);
  lineTo(-movex+9800,-movey+3138);
  lineTo(-movex+9354,-movey+3062);
  lineTo(-movex+8877,-movey+3062);
  lineTo(-movex+8800,-movey+3215);
  lineTo(-movex+8754,-movey+3323);
  lineTo(-movex+8615,-movey+3462);
  lineTo(-movex+8400,-movey+3369);
  lineTo(-movex+8231,-movey+3231);
  lineTo(-movex+8354,-movey+2969);
  lineTo(-movex+8615,-movey+2738);
  lineTo(-movex+8615,-movey+2523);
  lineTo(-movex+8492,-movey+2169);
  lineTo(-movex+8292,-movey+1846);
  lineTo(-movex+8092,-movey+1662);
  lineTo(-movex+7862,-movey+1554);
  lineTo(-movex+7723,-movey+1277);
  lineTo(-movex+7985,-movey+1523);
  lineTo(-movex+8154,-movey+1554);
  lineTo(-movex+8354,-movey+1523);
  lineTo(-movex+8169,-movey+1292);
  lineTo(-movex+7969,-movey+1000);
  lineTo(-movex+7831,-movey+615);
  lineTo(-movex+7908,-movey+385);
  lineTo(-movex+7785,-movey+200);
  lineTo(-movex+7585,-movey+0);
  lineTo(-movex+3477,-movey+0);

  //points
  Assign(f,'places.txt');
  Reset(f); {'Reset(x)' - means open the file x}
  repeat
    Tsize := 1;
    Readln(f,TFile);
    x := leftstr(TFile,pos(' ',TFile)-1);
    delete(TFile,1,pos(' ',TFile));
    y := leftstr(TFile,pos(' ',TFile)-1);
    delete(TFile,1,pos(' ',TFile));
    name := TFile;
    if(x[1]='a')then
      begin
        delete(x,1,1);
        Tsize := 2;
      end;
    if(x[1]='b')then
      begin
        delete(x,1,1);
        Tsize := 3;
      end;
    placePoint(strtoint(x),strtoint(y),name,Tsize);
  until Eof(f);
  Close(f);
end;

begin
  Gd := Detect;  //Set graphics driver to 0.
  Gm := 0;       //Graphics mode will be set automatically.
  InitGraph(Gd, Gm, ''); //Open the graph window
  movex := 4380;//238
  movey := 4750;//175
  xmiddle := round(getmaxX/2);
  ymiddle := round(getmaxY/2);
  repeat
    setPointsUp;
    sleep(21);
    clearDevice;
    clrscr;

    //get bearing from line to cursor
    if not((getmousex-XMIDDLE)=0)then
      degr := 90+round((arctan((getmousey-ymiddle)/(getmousex-xmiddle)))/3.141*180);
    if(xmiddle-getmousex>0)then
      degr := degr + 180;
    x1 := XMIDDLE+round(12*sin(-(degr+180)/180*3.141));
    y1 := YMIDDLE+round(12*cos(-(degr+180)/180*3.141));
    x2 := XMIDDLE+round(12*sin(-(degr)/180*3.141));
    y2 := YMIDDLE+round(12*cos(-(degr)/180*3.141));
    SetColor(lightgreen);
    SetLineStyle(SolidLn,UserBitLn,triplewidth);
    line(x1,y1,x2,y2);

    distanceAway := round(0.15*sqrt((getmousey-ymiddle)*(getmousey-ymiddle) + (getmousex-xmiddle)*(getmousex-xmiddle)));
    if(distanceAway>1)then
      begin
        movex := movex+round(distanceAway*sin(-(degr+180)/180*3.141));
        movey := movey+round(distanceAway*cos(-(degr+180)/180*3.141));
      end;

    writeln(movex);
    if(movey<-220)then
       movey := -220;
    if(movey>10000)then
      movey := 10000;
    if(movex<-840)then
      movex := -840;
    if(movex>11000)then
      movex := 0;

  until 1=2;
end.

Remarks

Could you write a program using wincrt, wingraph and winmouse?

Programming - a skill for life!

Fourteen programs (with five web versions) including 3D-Driving, GASP and Knowledge by Peter Hearnshaw