Next: 3 The Traveling Salesman
Up: APS105S Monday Quiz 2
Previous: 1 Linked List Manipulation
You are to write a Turing program that draws a picture and moves
it around the screen, using Turing graphics functions.
The program inputs two files: the first
file describes a picture by giving a number of (x,y) points
that are the endpoints of lines to be drawn (see below for details
of how this is to be done).
The second file gives a series of (
x,
y) pairs.
Your program should draw the
picture (described by the first file) several times, once for each
(
x,
y) pair in the second file.
Each time, the picture should be displaced from its
original position (described by the first file)
by the amount (
x,
y). That is, a point that is specified
as (x,y) in the first file, should actually be drawn as
(
,
).
The format of the first (picture) file is as follows:
N
X1 Y1
X2 Y2
X3 Y3
.
.
XN YN
N is the number of (x,y) pairs to input.
The picture should be drawn by drawing a line from (X1,Y1) to (X2,Y2),
and then from (X2,Y2) to (X3,Y3) and so on.
You may choose any visible colour to draw with.
The file that describes the motion, which contains the
(
x,
y) pairs, has this same format.
Your program should prompt the user to input the names of the files
to read. Test your program with the files /usr/copy/aps105/pict
for a picture file, and /usr/copy/aps105/moves for the motion file.
The picture is a square with a cross in it. The motion file should cause
the picture to move from your left to the right, twice, once at near
the bottom of the window, and once near the top.
The screen should be erased before each time the picture is drawn,
using the cls procedure call.
Assume that all X,Y pairs are given in Turing screen co-ordinates so that
you don't have to translate them (i.e.
, and
). Also, you don't need to check the input files
for correctness.
- Your program should have the following structure: there should
be a procedure, called DrawPict that takes as its arguments the
(
X,
Y) displacement. It should draw the picture at the
given displacement. The main program will call this procedure
numerous times in order to create the animation.
- The files you read must conform to the format described above.
Be sure to check that your program works with the files
/usr/copy/aps105/pict and /usr/copy/aps105/moves.
A solution
Next: 3 The Traveling Salesman
Up: APS105S Monday Quiz 2
Previous: 1 Linked List Manipulation
Jonathan Rose
Fri Apr 4 13:36:24 EST 1997