Here's my version with a comparisation with Robot's code...
cls
sync on
sync rate 0
rad=100
start=timer()
for i=1 to 100
rad=20
FillCircle(rnd(640-(2*rad))+rad,rnd(480-(2*rad))+rad,rad)
sync
next i
finish=timer()
print finish-start
wait key
cls
start=timer()
for i=1 to 100
rad=20
SBFillCircle(rnd(640-(2*rad))+rad,rnd(480-(2*rad))+rad,rad)
sync
next i
finish=timer()
print finish-start
sync
wait key
end
function FillCircle( CX, CY, R )
s=R*0.70710678 : ` this number is sin(45) - precalculate!
box CX-s, CY-s, CX+s+1, CY+s+1
s=s+1 : ` Faster than 'inc s'?
i=R*R
for y=s to R
x=sqrt( i-(y*y) )
` Draw top and bottom
box CX-x, CY-y, CX+x+1, (CY-y)+1
box CX-x, CY+y, CX+x+1, CY+y+1
` Draw left and right
box CX-y, CY-x, (CX-y)+1, CY+x+1
box CX+y, CY-x, CX+y+1, CY+x+1
next y
endfunction
function SBFillCircle( CX, CY, R )
for i = 1 to R
h = sqrt( R*R - i*i )
box CX - i, CY - h, CX + i, CY + h
next i
endfunction
I changed the radius to 20 to give a more accurate comparisation.
No offence robot, but my code seems to be faster (and shorter)...
It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.