OK check it out. 4 versions of the function in order of speed, with the box commands commented out. Your original first, then an altered version with different looping, the same again with ^2 not used, then the sqrt version. The sqrt one is significantly quicker.
timestart=timer()
fillCircle(100,100,550)
fillCircle(300,300,2050)
time1=timer()-timestart
timestart=timer()
fillCirclea(100,100,550)
fillCirclea(300,300,2050)
time2=timer()-timestart
timestart=timer()
fillCirclea1(100,100,550)
fillCirclea1(300,300,2050)
time3=timer()-timestart
timestart=timer()
fillCirclenew(100,100,550)
fillCirclenew(300,300,2050)
time4=timer()-timestart
print time1
print time2
print time3
print time4
wait key
end
function fillCircle(x,y,r)
for yy = y-r to y
for xx = x-r to x
d# = (xx-x)^2 + (yy-y)^2
if d# <= r*r
` box xx,yy,x+(x-xx)+1,yy+1
` if yy <> y then box xx,y+(y-yy),x+(x-xx)+1,y+(y-yy)+1
exit
endif
next xx
next yy
endfunction
function fillCirclea(x,y,r)
xs=x-r
lasty=y+r
for yy = y to lasty
ysq=(yy-y)^2
for xx = xs to x
d = (xx-x)^2 + ysq
if d <= r*r
` box xx,yy,x+(x-xx)+1,yy+1
` if yy <> y then box xx,y+(y-yy),x+(x-xx)+1,y+(y-yy)+1
exit
endif
next xx
xs=xx
next yy
endfunction
function fillCirclea1(x,y,r)
xs=x-r
lasty=y+r
for yy = y to lasty
ysq=(yy-y)*(yy-y)
for xx = xs to x
d = (xx-x)*(xx-x) + ysq
if d <= r*r
` box xx,yy,x+(x-xx)+1,yy+1
` if yy <> y then box xx,y+(y-yy),x+(x-xx)+1,y+(y-yy)+1
exit
endif
next xx
xs=xx
next yy
endfunction
function fillCirclenew(x,y,r)
for yy = y-r to y
xx= x - sqrt(r*r - (yy-y)^2 )
` box xx,yy,x+(x-xx)+1,yy+1
` if yy <> y then box xx,y+(y-yy),x+(x-xx)+1,y+(y-yy)+1
next yy
endfunction
here's with the drawing commands back in:
sync on
timestart=timer()
fillCircle(100,100,550)
fillCircle(300,300,2050)
time1=timer()-timestart
timestart=timer()
fillCirclea(100,100,550)
fillCirclea(300,300,2050)
time2=timer()-timestart
timestart=timer()
fillCirclea1(100,100,550)
fillCirclea1(300,300,2050)
time3=timer()-timestart
timestart=timer()
fillCirclenew(100,100,550)
fillCirclenew(300,300,2050)
time4=timer()-timestart
sync
ink 0,0
print time1
print time2
print time3
print time4
sync
wait key
end
function fillCircle(x,y,r)
for yy = y-r to y
for xx = x-r to x
d# = (xx-x)^2 + (yy-y)^2
if d# <= r*r
box xx,yy,x+(x-xx)+1,yy+1
if yy <> y then box xx,y+(y-yy),x+(x-xx)+1,y+(y-yy)+1
exit
endif
next xx
next yy
endfunction
function fillCirclea(x,y,r)
xs=x-r
lasty=y+r
for yy = y to lasty
ysq=(yy-y)^2
for xx = xs to x
d = (xx-x)^2 + ysq
if d <= r*r
box xx,yy,x+(x-xx)+1,yy+1
if yy <> y then box xx,y+(y-yy),x+(x-xx)+1,y+(y-yy)+1
exit
endif
next xx
xs=xx
next yy
endfunction
function fillCirclea1(x,y,r)
xs=x-r
lasty=y+r
for yy = y to lasty
ysq=(yy-y)*(yy-y)
for xx = xs to x
d = (xx-x)*(xx-x) + ysq
if d <= r*r
box xx,yy,x+(x-xx)+1,yy+1
if yy <> y then box xx,y+(y-yy),x+(x-xx)+1,y+(y-yy)+1
exit
endif
next xx
xs=xx
next yy
endfunction
function fillCirclenew(x,y,r)
for yy = y-r to y
xx= x - sqrt(r*r - (yy-y)^2 )
box xx,yy,x+(x-xx)+1,yy+1
if yy <> y then box xx,y+(y-yy),x+(x-xx)+1,y+(y-yy)+1
next yy
endfunction
BTW i have no idea why the 3rd command appears to be slower than the 2nd one!! Also, you can get a tiny bit more speed by calculating r*r at the start of the function.