It's not that I want to break down your code, but I think I found kindof a faster algorithm.
What you do, is going off the whole boxed area of the circle and check for every point if the point is on the circles line. However, small circles are good, but when going to big circles, this causes a major slowdown.
So, I started searching. What if we worked with lines? Boxes are out of the question because we have to deal with an empty centre. (Not for filled circles). Ok, this works. And it can even faster. As you know, a circle has infinite symmetry-axes, wich allows us to do only 1 calculation for the 4 quadrants and quadruple speed.
The algorithm:
- go off the i from center to radius.
- find the height with the calculation sqrt(rad^2 - i^2). This is used in every loop anyway.
- if i < r - t or in other words, the smaller circle "hole", then you have to create a broken line.
The smaller height will be sqrt(srad^2 - i^2) which will never be negative because i has to be smaller than r - t.
- else, you can draw a complete line from height to -height.
function circ2(x, y, r, t)
for i = 0 to r
`base calculations
h = sqrt(r*r - (i*i))
if i < r - t
thickrad = t - r
h2 = sqrt(thickrad*thickrad - (i*i))
line x - i, y - h, x - i, y - h2
line x - i, y + h2, x - i, y + h
line x + i, y - h, x + i, y - h2
line x + i, y + h2, x + i, y + h
else
line x - i, y - h, x - i, y + h
line x + i, y - h, x + i, y + h
endif
next i
endfunction
The filled circle code looks like it but is much faster and shorter. (Also off topic so I wont post it
)
Immunity and Annihalation makes Immunihalation...