Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another small filled circe sub (not as fast as fcirc)
#29
the test with better FC3 code
Code: (Select All)
Screen _NewImage(1000, 700, 32)

For i = 1 To 10

    'time the fcirc sub
    t# = Timer(.001)
    For c = 1 To 500
        fcirc 400, 400, 350, _RGB(128, 128, 128)
    Next
    t1# = t1# + Timer(.001) - t#

    'time the fc sub
    t# = Timer(.001)
    For c = 1 To 500
        fc 400, 400, 350, _RGB(255, 128, 128)
    Next
    t2# = t2# + Timer(.001) - t#

    'time the fc3 sub
    t# = Timer(.001)
    For c = 1 To 500
        FC3 400, 400, 350, _RGB(128, 255, 128)
    Next
    t3# = t3# + Timer(.001) - t#

    'time the fc4 sub
    t# = Timer(.001)
    For c = 1 To 500
        fc4 400, 400, 350, _RGB(128, 128, 255)
    Next
    t4# = t4# + Timer(.001) - t#
    ' Print t1#, t2#, t3#, t4#
Next
Cls
Print
Print "  fcirc           ", "        fc ", "                  fc3           ", "          fc4  "
Print

Print "Final Total:"
Print t1#, t2#, t3#, t4#

Sub fc (cx, cy, r, clr&)
    For y = -r To r
        x = Int(Sqr(r * r - y * y))
        Line (cx - x, cy + y)-(cx + x, cy + y), clr&, BF
    Next
End Sub

Sub fc4 (cx, cy, r, clr&)
    r2 = r * r
    For y = 0 To 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
    Next
End Sub

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
        x = Int(Sqr(r2 - y * y)) ' r2 Dav
        Line (cx - x, cy + y)-(cx + x, cy + y), clr&, BF
        Line (cx - x, cy - y)-(cx + x, cy - y), clr&, BF
        y = y + 1
    Wend
End Sub


Sub fcirc (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
    Dim Radius As Integer, RadiusError As Integer
    Dim X As Integer, Y As Integer
    Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
    If Radius = 0 Then PSet (CX, CY), C: Exit Sub
    Line (CX - X, CY)-(CX + X, CY), C, BF
    While X > Y
        RadiusError = RadiusError + Y * 2 + 1
        If RadiusError >= 0 Then
            If X <> Y + 1 Then
                Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
                Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
            End If
            X = X - 1
            RadiusError = RadiusError - X * 2
        End If
        Y = Y + 1
        Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
        Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
    Wend
End Sub

A sample of results with the better FC3 code
   
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Messages In This Thread
RE: Another small filled circe sub (not as fast as fcirc) - by bplus - 08-30-2024, 12:40 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)