GameZero.jl
GameZero.jl copied to clipboard
Better circle drawing algorithm
The current algorithm for drawing circles is not very good (though it is fast). It looks pretty ugly if the cirle is more than a about 10 pixels in diameter.
Current implementation is here: https://github.com/aviks/GameZero.jl/blob/7884b8531b09d5fdb3abac69e73a745399c4175a/src/screen.jl#L163
I have been playing with making a better algorithm the last couple of days. Mine could use some more optimization, but as it is it isn't too much slower than the current one. It completely fills in the circle and so far shows no problems with being absurdly slow or not filling properly. When it only draws the circle outline it is sometimes thicker than necessary by a pixel in places, though it is only noticeable if you look close. My fork with the changes is here: https://github.com/potato-programming/GameZero.jl/blob/master/src/screen.jl
Yeah, the current implementation is pretty poor, so anything else is probably an improvement. I'd be really happy to see a PR.
It'd be good to get a sense of how fast the new method is, using @time
(run it more than once). It is not necessary for the new method to be be as fast as the old one to be accepted, but it shouldn't be, say 10x slower.
I used @time, and one implementation was in fact 10x slower, but I managed to get it working quite a bit better. The current one seems to be about 2 - 3x slower, which isn't too bad.
I have tested the algorithm as a custom function is a game program, but I have been unable to test it as a function that is inside the GameZero module because of issues with the current way that the game is run. I am going to try and install my version as a custom package to test it, I will send a PR when I have done all necessary testing.
There are still some bugs when fill=true
with the new implementation. I mentioned this bug in the PR if anyone wants to take a swing at it.