gamercade-io / gamercade_console

A Neo-Retro Fantasy Console. Make WASM-powered, networked multiplayer games.
https://gamercade.io
Apache License 2.0
166 stars 10 forks source link

feat(draw_api): Add `circle_filled` #39

Closed Cardosaum closed 1 year ago

Cardosaum commented 1 year ago

Closes #5.

The main logic for the circle_filled was shamelessly borrowed from circle function. There might be room for optimization, but curious to know what would be your take on this.

RobDavenport commented 1 year ago

Thanks for the PR! This mostly looks good, but I think we are over drawing some pixels here due to doing both horizontal and vertical lines.

Its possible to do this with only horizontal lines. This post explains a way to do it: https://stackoverflow.com/questions/5607946/bresenhams-circle-algorithm-filling-question using the same algorithm, Bresenham Circle.

Cardosaum commented 1 year ago

Thanks for pointing out the algorithm you were using, it was really helpful!

I optimized the code as you said, now we're only painting pixels once per loop instead of having overlapping ones as previously observed.

I also made a small change in circle function, removing some unnecessary type coercion.