There are two hard problems in IT: transferring large files and, apparently, drawing circles.
I’m writing a lot of demo prototyping tools in Java and Kotlin. Doing that, an exotic requirement came up: I wanted to draw a filled circle. Outrageous, I know, but how hard can it be?
Since there is no fillCircle
, let’s try fillOval
.
According to the documentation, “fills an oval bounded by the specified rectangle with the current color” – just what we need!
![](/blog/you-re-breaking-my-balls/fillOval.png)
Weird, the circle was supposed to span the bounding box, but the first column and row are empty. Also, there are ugly jaggies. Hm, why not try to move the circle up and left by 1 pixel and increase the size by 1 to make up for that:
![](/blog/you-re-breaking-my-balls/fillOval2.png)
That’s somewhat better, but now we have a single stray pixel outside of the bounding box!
fillArc
with angles from 0 to 360 gives the same result.
Maybe we can use drawOval
instead and fill that? Of course,
that method behaves slightly different
(“covers an area that is
width+1 pixels wide
and
height+1 pixels tall”), but we keep that in mind.
![](/blog/you-re-breaking-my-balls/drawOval.png)
At least the outline fills the bounding box neatly now. But wait… the circles aren’t even symmetrical?! You gotta be kidding me.
At this point, I’m not really in the mood to investigate if this is a problem of the specific JRE* or something, and do the obvious thing: Use the circle equation and plot every pixel by hand.
![](/blog/you-re-breaking-my-balls/formula.png)
Huzzah! That was easy. As a bonus, these circles don’t seem to suffer from ugly jaggies, and they mostly match up with the circles PersonalPaint and DeluxePaint would draw.
![](/blog/you-re-breaking-my-balls/amigatest.png)
Why didn’t I do it that way from the start? Stupid me. /s
*) For reference: Amazon Corretto 17.0.10 on Windows 10
Blog
- Sep 2024 – 2
- Aug 2024 – 5
- Jul 2024 – 6
- Jun 2024 – 6
- May 2024 – 7
- Apr 2024 – 8
- Mar 2024 – 4
- Feb 2024 – 9
- Jan 2024 – 10
- Dec 2023 – 8
- Nov 2023 – 1
- Oct 2023 – 5
- Sep 2023 – 5
- Aug 2023 – 8
- Jul 2023 – 1
- Apr 2023 – 1
Recently updated pages
- hrrngh!
- Knob-Out
- B.S.I. – Byte Scene Investigation
- Coppenheimer
- Hold mode minutiae
- Shall we play a game?
- Worms VBI
- strss
- Modding the Amiga boot hand
- rotz