Pascal: Turtlegraphics -- Circles

The program below is supposed to draw a circle, but it doesn't--it draws an
octogon. The drawing routines can calculate exactly where the end of the line
will be, but with a move of only one dot, the result is limited to one of the
eight adjacent dots. For example, if we move a distance of one dot at an
angle of five degrees, then the co-ordinates of the destination are X + 0.09,
Y + 0.99, which are rounded to X + 0, Y + 1.

Calculated Angle Actual Angle
0 - 22.5 0
22.5 - 67.5 45
67.5 - 112.5 90
112.5 - 157.5 135
157.5 - 202.5 180
202.5 - 247.5 225
247.5 - 292.5 270
292.5 - 337.5 315
337.5 - 382.5 0

The next table gives the calculated and actual X and Y coordinates for an
angle of 5 degrees and varying move distances.

X-Coordinate Y-Coordinate
Move Calc Act Calc Act
1 0.09 0 0.99 1
2 0.17 0 1.99 2
3 0.26 0 2.98 3
4 0.35 0 3.98 4
5 0.43 0 4.98 5
6 0.52 1 5.97 6

The next diagram simulates the High-Res graphics display. Clearly, you must
move at least 6 units for 5 degrees to show any effect.

M o v e
1 2 3 4 5 6

*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * *

As you can see, the computer can't display a 5 degree change unless the move
is at least 6 units.

PROGRAM CIRCLE;

USES Turtlegraphics;

VAR I : INTEGER;

BEGIN
INITTURTLE;
PENCOLOR (WHITE);
FOR I := 1 TO 8 DO BEGIN
MOVE (1);
TURN (1);
END;
READLN;
END.

Published Date: Feb 20, 2012