QB64 Phoenix Edition
elcircle - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Programs (https://qb64phoenix.com/forum/forumdisplay.php?fid=7)
+---- Thread: elcircle (/showthread.php?tid=1997)



elcircle - James D Jarvis - 09-14-2023

elcircle is a pretty quick subroutine to draw filled ellipses (and circles) that doesn't have the problems using Paint does. It's not a fast as fcircle but it's speedy and it can do ellipses.

Code: (Select All)
'elcircle demo
' by James D. Jarvis
' a fast subroutine to fill an ellipsoid or a circlc without using PAINT
'expanded from a circle routine by Chuck Venoit here https://basicanywheremachine-news.blogspot.com/2023/09/when-circle-feels-to-slow-try-and-test.html?fbclid=IwAR3jd_mR7minVFvWUlAkusEo39H107ZeWIr4h4Nio80Hgkw-VnVdETyxJk4
Screen _NewImage(800, 500, 256)
Randomize Timer
e = 64000
t1 = Timer
For c = 1 To e
    elcircle Rnd * _Width, Rnd * _Height, Int(10 + c / 1000), 1.5, Int(Rnd * 256)
Next c
t2 = Timer
For c = 1 To e
    elcircle2 Rnd * _Width, Rnd * _Height, Int(10 + c / 1000), 0.5, Int(Rnd * 256)
Next c
t3 = Timer
Print "elcircle"; t2 - t1; "  elcircle 2 "; t3 - t2; " press any key to continue"
Sleep
Cls
Print "use standard circle comands if you wish to add a 1 pixel outline to the circles"
elcircle 200, 200, 100, 0.5, 12
Circle (200, 200), 100, 15, , , 0.5
elcircle 400, 200, 100, 3.5, 12
Circle (400, 200), 100, 15, , , 3.5

Sub elcircle (cx, cy, crad, aspectr, klr As _Unsigned Long)
    'elcircle  does not render correctly if ascpect ratio is <1
    If aspectr < 1 Then
        elcircle2 cx, cy, crad, aspectr, klr
    Else
        For xy = 0 To crad * 0.75
            a = Sqr(crad * crad - xy * xy)
            a_ar = a / aspectr
            xy_ar = xy / aspectr
            Line (cx - a_ar, cy - xy)-(cx + a_ar, cy - xy), klr, BF
            Line (cx - a_ar, cy + xy)-(cx + a_ar, cy + xy), klr, BF
            Line (cx - xy_ar, cy - a)-(cx + xy_ar, cy - a), klr, BF
            Line (cx - xy_ar, cy + a)-(cx + xy_ar, cy + a), klr, BF
        Next xy
    End If
End Sub
Sub elcircle2 (cx, cy, crad, aspectr, klr As _Unsigned Long)
    'elcircle2 renders aspect ratios <1 correctly but it is  slower than elcircle itself
    For xy = 0 To (crad * 0.75)
        a = Sqr(crad * crad - xy * xy)
        a_ar = a * aspectr
        xy_ar = xy * aspectr
        Line (cx - xy, cy + a_ar)-(cx + xy, cy - a_ar), klr, BF
        Line (cx - a, cy + xy_ar)-(cx + a, cy - xy_ar), klr, BF
    Next xy
End Sub




RE: elcircle - SMcNeill - 09-14-2023

Reminder we also have these: https://qb64phoenix.com/forum/showthread.php?tid=1806


RE: elcircle - bplus - 09-14-2023

Yes and those have gone through the ringer of Pete, STx and bplus testing ;-))

But as with Charlie it is good to know how to do these on your own for customized effects (they will cost you speed probably).

For example:
```Screen _NewImage(400, 400, 32)
cx = _Width / 2: cy = _Height / 2
r = 100
While r > 0
x = 0: y = r 'reset
While x < y
Color _RGB32(x * 3, 255 - 6 * x, 0)
y = Sqr(r * r - x * x)

PSet (cx - x, cy - y)
PSet (cx + x, cy - y)
PSet (cx - x, cy + y)
PSet (cx + x, cy + y)

PSet (cx - y, cy - x)
PSet (cx + y, cy - x)
PSet (cx - y, cy + x)
PSet (cx + y, cy + x)

x = x + .25
Wend
r = r - .5
Wend```


RE: elcircle - James D Jarvis - 09-14-2023

I have to master the search feature here, not that I wouldn't have done this anyway, but I might have posted it somewhere else if I had seen some of those other ellipse routines in my search this morning.


RE: elcircle - Dav - 09-15-2023

Thanks for sharing it anyway, James.  It's interesting seeing different approaches to things, and kudos for rolling your own functions.

- Dav