Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another small filled circe sub (not as fast as fcirc)
#2
The trick with fcirc is that it takes advantage of a circle's mirror-like properties.  You get one point, you've got 8.


For example, let's imagine a circle 100 pixels tall and 100 pixels wide.  (It's got a radius of 50.)

From the very start, we can see that mirroring at work.  
On the X axis, you're going to go 50 pixels left of the center to plot that first set of circle coordinates. 
You're also going to go 50 pixels right from the center to plot that first set of circle coordinates.
And, on the Y axis, you're going to 50 pixels up to plot a point
and 50 pixels down to plot a point.

Knowing one offset (0 from center), you now easily have 4 points of the circle's perimeter. 

Now, if you go one offset away from center, such as UP one point on the Y-axis, you can calculate the X-point once for the matching coordinate for the triangle with 1 height, 50 hypotenuse, and a 90 degree angle...
That point is valid for 1 pixel up from the center, and right that amount.
That point is also valid for 1 pixel up from the center, and left that amount.
That point is valid for 1 pixel down from the center, and right that amount.
That point is valid for 1 pixel down from the center, and left that amount.
...
And if we inverse our X/Y as we're looking at a perfect mirror here,
That point is valid for 1 pixel right from the center, and up that amount.
That point is also valid for 1 pixel right from the center, and down that amount.
That point is valid for 1 pixel left from the center, and up that amount.
That point is valid for 1 pixel left from the center, and down that amount.

You calculated one math point, and in return, you got 8 circle coordinates!

You're not drawing one line at a time, you're drawing a line in ALL FOUR QUADRANTS at a time.  


Minimum points of calculation needed, so maximum performance.

And that's basically how fcirc works in a butshell.  Wink
Reply


Messages In This Thread
RE: Another small filled circe sub (not as fast as fcirc) - by SMcNeill - 08-28-2024, 06:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  A Small Game Tutorial (from 2014) SMcNeill 2 970 11-13-2023, 09:11 PM
Last Post: Kernelpanic
  Small exploding image and fade-out effect Dav 18 3,527 09-08-2023, 11:16 PM
Last Post: dbox
  Space Orbs. Small screen saver. Dav 16 3,134 08-27-2023, 07:52 PM
Last Post: grymmjack
  Ball Sub - draws several kind of filled, textured balls (circles) Dav 15 3,481 08-23-2023, 09:31 PM
Last Post: Dav
  Improved my small Gradient Ball drawing SUB Dav 22 5,303 07-13-2023, 05:23 PM
Last Post: Dav

Forum Jump:


Users browsing this thread: