Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another small filled circe sub (not as fast as fcirc)
#36
(08-30-2024, 04:21 AM)Pete Wrote: Yes, I recall how Bill didn't think using SQR could possibly work, until I did exactly that. Mostly thanks to _INTEGER64, it worked.

That reminds me....
Code: (Select All)
Sub FC3 (cx, cy, r, clr&)
    Line (cx - r, cy)-(cx + r, cy), clr&, BF
    y = 1
    r2 = r * r ' Dav mod
    While y <= r
        y2 = y * y
        If y2 < r2 Then
            x = Int(Sqr(r2 - y2))
            Line (cx - x, cy + y)-(cx + x, cy + y), clr&, BF
            Line (cx - x, cy - y)-(cx + x, cy - y), clr&, BF
        End If
        y = y + 1
    Wend
End Sub

Could be modified to...
Code: (Select All)
Sub FC3 (cx, cy, r, clr&)
    Dim x as Integer
    Line (cx - r, cy)-(cx + r, cy), clr&, BF
    r2 = r * r ' Dav mod
    Do Until y > r
        y = y + 1
        y2 = y * y
        If y2 < r2 Then
            x = Sqr(r2 - y2)
            Line (cx - x, cy + y)-(cx + x, cy + y), clr&, BF
            Line (cx - x, cy - y)-(cx + x, cy - y), clr&, BF
        End If
    Loop
End Sub

Pete

My thinking was to make use of something like this:
Code: (Select All)
Sub PreCalcX
    For r = 0 To 500 'circles with a radius from 0 to 500
        r2 = r * r
        For y = 0 To r
            y2 = y * y
            x = Int(Sqr(r2 - y2))
            CircleXPos(r, y) = x
        Next
    Next
End Sub

Precalculate all that math, and get rid of it completely.  Just one quick lookup for that value rather than multiplying and all that.

It would seem to me that *this* should be much faster than everything else is:
Code: (Select All)
Sub StevePreCalcCircle (cx, cy, r, clr&)
    $Checking:Off
    For y = 0 To r
        x = CircleXPos(r, y)
        Line (cx - x, cy - y)-(cx + x, cy - y), clr&, BF
        Line (cx - x, cy + y)-(cx + x, cy + y), clr&, BF
    Next
    $Checking:On
End Sub

Just look up that one value from a precalculated list.   And yet... almost impossibly... it's often not the fastest method we have available, when resting those speeds all side by side!

Are our arrays that slow?
Is the timer routine screwing up somewhere?
WTF is going on to give us the figures that we're getting??

I have no clue.  I just found the results upper astonishing.
Reply


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

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

Forum Jump:


Users browsing this thread: 1 Guest(s)