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!
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:
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.
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.
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.
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
- Oct 2024 – 2
- Sep 2024 – 6
- 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