Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another small filled circe sub (not as fast as fcirc)
#66
I tried doing this with Steve's earlier suggestion:

Quote:1) draw a center square of maximum size inside the circle first.  Fill it with a single LINE,,,,BF statement.
2) then calculate from the outer axis points inwards until we fill up to that same point that the square has already covered.   This should prevent overlap or any such thing and might speed up the whole process overall.
It gave an interference pattern like a circumscribed square at certain radii. Always a one pixel gap. I thought to increase the size of the central square by one pixel, but it left little points at the quadrant diagonals so that center is already maximized. No point in doing any benchmarking yet. Oh well, back to the drawing board...

Code: (Select All)
$COLOR:32
SCREEN _NEWIMAGE(1024, 512, 32)
CLS
FOR x% = 0 TO 49
    FcircBlk (x% MOD 10) * 100 + 50, (x% \ 10) * 100 + 50, x% + 10, Green
    'FCirc (x% MOD 10) * 100 + 50, (x% \ 10) * 100 + 50, x% + 10, Green
NEXT x%

SUB FcircBlk (CX AS LONG, CY AS LONG, RR AS LONG, C AS _UNSIGNED LONG)
    DIM AS LONG R, RError, X, Y, D
    R = ABS(RR) '                                               radius value along positive x
    RError = -R '                                               opposite side of circle? negative x
    X = R '                                                     point along positive x position
    Y = 0 '                                                     starting at the equator
    D = R * .7071
    IF R = 0 THEN PSET (CX, CY), C: EXIT SUB '                  zero radius is point, not circle
    LINE (CX - D, CY - D)-(CX + D, CY + D), C, BF
    WHILE X > Y
        RError = RError + Y * 2 + 1
        IF RError >= 0 THEN
            IF X <> Y + 1 THEN
                LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF ' south
                LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF ' north
                LINE (CX - X, CY - Y)-(CX - X, CY + Y), C, BF ' west
                LINE (CX + X, CY - Y)-(CX + X, CY + Y), C, BF ' east
            END IF
            X = X - 1
            RError = RError - X * 2
        END IF
        Y = Y + 1
    WEND
    _PRINTMODE _KEEPBACKGROUND
    _PRINTSTRING (CX, CY), STR$(RR)
END SUB 'FcircBlk


SUB FCirc (CX AS LONG, CY AS LONG, RR AS LONG, C AS _UNSIGNED LONG) 'Steve's circle fill unmodified
    DIM AS LONG R, RError, X, Y
    R = ABS(RR) '                                               radius value along positive x
    RError = -R '                                               opposite side of circle? negative x
    X = R '                                                     point along positive x position
    Y = 0 '                                                     starting at the equator
    IF R = 0 THEN PSET (CX, CY), C: EXIT SUB '                  zero radius is point, not circle
    LINE (CX - X, CY)-(CX + X, CY), C, BF '                     draw equatorial line
    WHILE X > Y
        RError = RError + Y * 2 + 1 '
        IF RError >= 0 THEN
            IF X <> Y + 1 THEN
                LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF ' draw lines for south polar latitudes
                LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF ' draw lines for north polar latitudes
            END IF
            X = X - 1
            RError = RError - X * 2
        END IF
        Y = Y + 1
        LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF '         draw lines north equatorial latitudes
        LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF '         draw lines south equatorial latitudes
    WEND
    _PRINTMODE _KEEPBACKGROUND
    _PRINTSTRING (CX, CY), STR$(RR)
END SUB 'FCirc
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Reply


Messages In This Thread
RE: Another small filled circe sub (not as fast as fcirc) - by OldMoses - 08-31-2024, 11:59 AM



Users browsing this thread: 31 Guest(s)