Improved my small Gradient Ball drawing SUB
#1
I use a small gradient ball SUB in various programs.  It had a flaw however - large balls with dark color values would have think back edges.  Made a new version to fix that.  Just thought I'd share it here.  If you have one too, please share it - I'd love to see what other people are using.  And if you see a way to improve mine please post it.  Thanks!

- Dav

Code: (Select All)

'================
'GRADIENTBALL.BAS
'================
'Simple SUB that draw gradient balls.
'Coded by Dav, JULY/2023


dh = _DESKTOPHEIGHT * .85
SCREEN _NEWIMAGE(dh, dh, 32)

DO
    ball RND * dh, RND * dh, RND * 500 + 25, RND * 255, RND * 255, RND * 255
    _LIMIT 5
LOOP

SUB ball (x, y, size, r, g, b)
    'This SUB draws a gradient ball with given color.

    'see current display status
    displayStatus%% = _AUTODISPLAY

    'turn off screen updates while we draw
    _DISPLAY

    reg = .4

    'if size is larger than value colors given,
    'adjust the reg value to step down at a slower rate.
    'This prevents thick black rim around larger balls
    'that have a too low a given color value.
    IF size > r AND size > g AND size > b THEN
        IF r > g AND r > b THEN reg = r / size * .4
        IF g > r AND g > b THEN reg = g / size * .4
        IF b > r AND b > g THEN reg = b / size * .4
    END IF

    'now draw the ball using CIRCLE.
    'Using smaller STEP value than 1 prevents gaps.
    FOR s = 0 TO size STEP .4
        CIRCLE (x, y), s, _RGB(r, g, b)
        r = r - reg: g = g - reg: b = b - reg
    NEXT

    'show the ball
    _DISPLAY

    'If autodislay was previously on, turn it back on
    IF displayStatus%% = -1 THEN _AUTODISPLAY

END SUB

Find my programs here in Dav's QB64 Corner
Reply


Messages In This Thread
Improved my small Gradient Ball drawing SUB - by Dav - 07-11-2023, 03:38 AM



Users browsing this thread: 10 Guest(s)