put "Drawing circle of radius 100"

%
%	NOTICE: This code is not to be taken as a good example of a circle
%	generator nor of good Turing style.
%

var x,y: real
var i,s,xn,yn: int
var r, eps: real

setscreen("nocursor")
r := 100
s := 1
i := 0
eps := 1

loop
	exit when r < s
	s := s shl 1			% in other words, s := s*2
	i += 1
end loop
	eps := 1.0/s

% put "r = ", r
% put "log r = ", i
% put "eps = ", eps

x := 100
y := 100
xn := 100
yn := 100

%
%	First let's draw a "circle" directly from our iterative equations.
%
loop
	drawdot(200+xn,200+yn,1)
	x  := x - eps*yn		% we can get away with using xn,yn
	y  := y + eps*xn		% rather than real versions x,y
	xn := round(x)
	yn := round(y)
	exit when xn > 150		% let it run for a while
end loop


x := 100
y := 100
xn := 100
yn := 100

%
%	Next let's draw the visually correct version that compensates for
%	drift in x.
%
loop
	drawdot(500+xn,200+yn,2)
	x  := x - eps*yn		% we can get away with using xn,yn
	xn := round(x)
	y  := y + eps*xn		% rather than real versions x,y
	yn := round(y)
	exit when xn=100 and yn=100
end loop

