Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another small filled circe sub (not as fast as fcirc)
#51
It should not make a difference which sub tested goes first. I even did not count times in the first cycle through tests AND I put a _Delay .1 before each Timer(.001) reset of T##

This code:
Code: (Select All)
_Title "FC3 versus fcirc" ' b+ 2024-08-30
'Dav, AUG/2024 bplus mod 2024-08-28  try faster FC2 mod of fc

' 2024-08-29 try larger circles all on screen with FC3

' 2024-08-30 test idea who goes first loses!

' fix color in FC3 sub

' remove int() from SQR result in FC3

' 2024-08-30 take reverse order code and reverse back to running fcirc first

' next line uncommented will speed up test time but wont be able to exit until done.
$Checking:Off
Screen _NewImage(1000, 700, 32)
_ScreenMove 150, 0
Randomize Timer
Print "Overlapping lines check of FC3"
FC3 500, 350, 300, _RGB32(0, 0, 255, 100) ' check for overlapping lines
Print "Looking good! no lighter lines." ' FC passes too BTW
Print: Print " zzz... press any for timed test"
Sleep
Cls
For i = 1 To 11
    If i = 1 Then ' in case going first has disadvantage   don't time fisrt round
        t## = Timer(.001) ' get the first call to timer over with
        fcirc Rnd * (_Width - 700) + 350, 350, 350, _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
        FC3 Rnd * (_Width - 700) + 350, 350, 350, _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
    Else
        'time the fcirc sub
        _Delay .1
        t## = Timer(.001)
        For c = 1 To 2000
            fcirc Rnd * (_Width - 700) + 350, 350, 350, _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
            _Display
        Next
        t1## = t1## + Timer(.001) - t##

        'time the fc3 sub
        _Delay .1
        t## = Timer(.001)
        For c = 1 To 2000
            FC3 Rnd * (_Width - 700) + 350, 350, 350, _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
            _Display
        Next
        t2## = t2## + Timer(.001) - t##
    End If
Next
Print
Print "fcirc ="; t1##
Print "  FC3 ="; t2##
Print

If t2## < t1## Then
    Print "FC3 wins!"
ElseIf t1## < t2## Then ' EDIT fixed!
    Print "fcirc wins!"
Else
    Print "Tie fcirc = FC3 time"
End If
_Display

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 = 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

Had FC3 beat fcirc 8 times to 2

This code (reversed the order)
Code: (Select All)
_Title "FC3 versus fcirc reverse order" ' b+ 2024-08-30
'Dav, AUG/2024 bplus mod 2024-08-28  try faster FC2 mod of fc

' 2024-08-29 try larger circles all on screen with FC3

' 2024-08-30 test idea who goes first loses!

' fix color in FC3 sub

' remove int() from SQR result in FC3

' next line uncommented will speed up test time but wont be able to exit until done.
$Checking:Off
Screen _NewImage(1000, 700, 32)
_ScreenMove 150, 0
Randomize Timer
Print "Overlapping lines check of FC3"
FC3 500, 350, 300, _RGB32(0, 0, 255, 100) ' check for overlapping lines
Print "Looking good! no lighter lines." ' FC passes too BTW
Print: Print " zzz... press any for timed test"
Sleep
Cls
For i = 1 To 11
    If i = 1 Then ' in case going first has disadvantage   don't time fisrt round
        t## = Timer(.001) ' get the first call to timer over with
        FC3 Rnd * (_Width - 700) + 350, 350, 350, _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
        fcirc Rnd * (_Width - 700) + 350, 350, 350, _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
    Else
        'time the FC3 sub
        _Delay .1
        t## = Timer(.001)
        For c = 1 To 2000
            FC3 Rnd * (_Width - 700) + 350, 350, 350, _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
            _Display
        Next
        t1## = t1## + Timer(.001) - t##

        'time the fc2 sub
        _Delay .1
        t## = Timer(.001)
        For c = 1 To 2000
            fcirc Rnd * (_Width - 700) + 350, 350, 350, _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
            _Display
        Next
        t2## = t2## + Timer(.001) - t##
    End If
Next
Print
Print "  FC3 ="; t1##
Print "fcirc ="; t2##
Print

If t2## < t1## Then
    Print "fcirc wins!"
ElseIf t1## < t2## Then ' EDIT fixed!
    Print "FC3 wins!"
Else
    Print "Tie fcirc = FC3 time"
End If
_Display

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 = 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

had fcirc beat FC3 6 to 4.

BTW this version of FC3 does not Integer anything because Line does that for us!
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
        x = 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
b = b + ...
Reply


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



Users browsing this thread: 2 Guest(s)