deflng a-z
const sw = 640
const sh = 480
dim shared pi as double
pi = 4*atn(1)
declare sub circlef(x, y, r)
declare sub ellipse(x, y, rx, ry)
'screenres sw, sh, 32
screen 12
a = 280
b = 80
ellipse sw/2, sh/2, a, b
ellipse sw/2, sh/2, b, a
color 12'rgb(255,0,0)
dim r as double
dim p as double
p = a*tan(pi/4)/b
r = (a/(cos(pi/4))/sqr(1 + p*p))
circlef sw/2 + r*cos(pi/4), sh/2 - r*sin(pi/4), 10
circlef sw/2 - r*cos(pi/4), sh/2 - r*sin(pi/4), 10
circlef sw/2 - r*cos(pi/4), sh/2 + r*sin(pi/4), 10
circlef sw/2 + r*cos(pi/4), sh/2 + r*sin(pi/4), 10
sleep
system
sub circlef(x, y, r)
x0 = r
y0 = 0
e = -r
do while y0 < x0
if e <=0 then
y0 = y0 + 1
line (x - x0, y + y0)-(x + x0, y + y0),, bf
line (x - x0, y - y0)-(x + x0, y - y0),, bf
e = e + 2*y0
else
line (x - y0, y - x0)-(x + y0, y - x0),, bf
line (x - y0, y + x0)-(x + y0, y + x0),, bf
x0 = x0 - 1
e = e - 2*x0
end if
loop
line (x - r, y)-(x + r, y),, bf
end sub
sub ellipse(x, y, rx, ry)
a = 2*rx*rx
b = 2*ry*ry
x0 = rx
y0 = 0
xx = ry*ry*(1 - 2*rx)
yy = rx*rx
e = 0
sx = b*rx
sy = 0
do while sx >= sy
pset (x - x0, y + y0)
pset (x + x0, y + y0)
pset (x - x0, y - y0)
pset (x + x0, y - y0)
y0 = y0 + 1
sy = sy + a
e = e + yy
yy = yy + a
if 2*e + xx > 0 then
x0 = x0 - 1
sx = sx - b
e = e + xx
xx = xx + b
end if
loop
x0 = 0
y0 = ry
xx = rx*ry
yy = rx*rx*(1 - 2*ry)
e = 0
sx = 0
sy = a*ry
do while sx <= sy
pset (x - x0, y - y0)
pset (x + x0, y - y0)
pset (x - x0, y + y0)
pset (x + x0, y + y0)
x0 = x0 + 1
sx = sx + b
e = e + xx
xx = xx + b
if 2*e + yy > 0 then
y0 = y0 - 1
sy = sy - a
e = e + yy
yy = yy + a
end if
loop
end sub