Code: Select all
'some useful defines
Const Pi = 4 * Atn(1)
Dim Shared As Double TwoPi = 8 * Atn(1)
Dim Shared As Double RtoD = 180 / Pi ' radians * RtoD = degrees
Dim Shared As Double DtoR = Pi / 180 ' degrees * DtoR = radians
type ELLIPSE
as integer cx,cy 'center of ellipse
as integer r1,r2 'axis of ellipse
as ulong c1,c2 'border color and fill color
as single angle 'rotate by angle
end type
sub drawEllipse(e as ELLIPSE)
dim as single x1,y1,x2,y2,x,y,cosAngle,sinAngle
dim as single steps
dim as single angle
'compute minimum pixels for circumference
steps = (abs(e.r1)+abs(e.r2))/360
cosAngle = cos(e.angle)
sinAngle = sin(e.angle)
x = cos(angle)*e.r1
y = sin(angle)*e.r2
x1 = cosAngle * x - sinAngle * y
y1 = cosAngle * y + sinAngle * x
for angle = 0*DtoR to 361*DtoR step steps*DtoR
x = cos(angle)*e.r1
y = sin(angle)*e.r2
x2 = cosAngle * x - sinAngle * y
y2 = cosAngle * y + sinAngle * x
line (x1+e.cx,y1+e.cy)-(x2+e.cx,y2+e.cy),e.c1 'join points
x1 = x2
y1 = y2
next angle
paint (e.cx,e.cy),e.c2,e.c1
end sub
dim shared as ELLIPSE e1
e1.cx = 320
e1.cy = 240
e1.r1 = 100
e1.r2 = 200
e1.c1 = rgb(255,0,0) 'outline color
e1.c2 = rgb(0,0,255) 'fill color
sub update()
screenlock
cls
drawEllipse(e1)
screenunlock
end sub
screenres 640,480,32
for angle as single = 0 to 360
e1.angle = angle*DtoR
update()
sleep 20
next angle