Space Orbs. Small screen saver.
#1
Here's a little screen saver showing pulsating orbs over a starry background with plasma clouds.  I was playing around some old code, turned it into something new. Tested and runs OK under Windows and Linux.

- Dav 

Code: (Select All)

'=============
'SpaceOrbs.bas
'=============
'Screensaver of Orbs pulsating in space
'Coded by Dav for QB64-PE, AUGUST/2023

RANDOMIZE TIMER

SCREEN _NEWIMAGE(1000, 640, 32)


'=== orb settings

orbs = 60 'number of orbs on screen
OrbSizeMin = 5 'smallest size an orb can get
OrbSizeMax = 60 'largest size an orb can get

DIM OrbX(orbs), OrbY(orbs), OrbSize(orbs), OrbGrowth(orbs)


'=== generate some random orb values

FOR i = 1 TO orbs
    OrbX(i) = RND * _WIDTH 'x pos
    OrbY(i) = RND * _HEIGHT 'y pos
    OrbSize(i) = OrbSizeMin + (RND * (OrbSizeMax - OrbSizeMin)) 'orb size
    OrbGrowth(i) = INT(RND * 2) 'way orb is changing, 0=shrinking, 1=growing
NEXT


'=== make a space background image

FOR i = 1 TO 100000
    PSET (RND * _WIDTH, RND * _HEIGHT), _RGBA(0, 0, RND * 255, RND * 225)
NEXT
FOR i = 1 TO 1000
    x = RND * _WIDTH: y = RND * _HEIGHT
    LINE (x, y)-(x + RND * 3, y + RND * 3), _RGBA(192, 192, 255, RND * 100), BF
NEXT


'=== grab screen image for repeated use

back& = _COPYIMAGE(_DISPLAY)


DO

    '=== place starry background first

    _PUTIMAGE (0, 0), back&


    '=== draw moving plasma curtain next

    t = TIMER
    FOR x = 0 TO _WIDTH STEP 3
        FOR y = 0 TO _HEIGHT STEP 3
            b = SIN(x / (_WIDTH / 2) + t + y / (_HEIGHT / 2))
            b = b * (SIN(1.1 * t) * (_HEIGHT / 2) - y + (_HEIGHT / 2))
            LINE (x, y)-STEP(2, 2), _RGBA(b / 3, 0, b, RND * 25), BF
        NEXT: t = t + .085
    NEXT


    '=== now process all the orbs

    FOR i = 1 TO orbs

        '=== draw orb on screen

        FOR y2 = OrbY(i) - OrbSize(i) TO OrbY(i) + OrbSize(i) STEP 3
            FOR x2 = OrbX(i) - OrbSize(i) TO OrbX(i) + OrbSize(i) STEP 3
                'make gradient plasma color
                IF SQR((x2 - OrbX(i)) ^ 2 + (y2 - OrbY(i)) ^ 2) <= OrbSize(i) THEN
                    clr = (OrbSize(i) - (SQR((x2 - OrbX(i)) * (x2 - OrbX(i)) + (y2 - OrbY(i)) * (y2 - OrbY(i))))) / OrbSize(i)
                    r = SIN(6.005 * t) * OrbSize(i) - y2 + OrbSize(i) + 255
                    g = SIN(3.001 * t) * OrbSize(i) - x2 + OrbSize(i) + 255
                    b = SIN(2.001 * x2 / OrbSize(i) + t + y2 / OrbSize(i)) * r + 255
                    LINE (x2, y2)-STEP(2, 2), _RGBA(clr * r, clr * g, clr * b, 5 + RND * 15), BF
                END IF
            NEXT
        NEXT

        '=== change orb values

        'if orb is shrinking, subtract from size, else add to it
        IF OrbGrowth(i) = 0 THEN OrbSize(i) = OrbSize(i) - 1 ELSE OrbSize(i) = OrbSize(i) + 1
        'if orb reaches maximum size, switch growth value to 0 to start shrinking now
        IF OrbSize(i) >= OrbSizeMax THEN OrbGrowth(i) = 0
        'if orb reaches minimum size, switch growth value to 1 to start growing now
        IF OrbSize(i) <= OrbSizeMin THEN OrbGrowth(i) = 1
        'creates the shakiness. randomly adjust x/y positions by +/-3 each
        IF INT(RND * 2) = 0 THEN OrbX(i) = OrbX(i) + 3 ELSE OrbX(i) = OrbX(i) - 3
        IF INT(RND * 2) = 0 THEN OrbY(i) = OrbY(i) + 3 ELSE OrbY(i) = OrbY(i) - 3

    NEXT

    _DISPLAY

    _LIMIT 15

LOOP UNTIL INKEY$ <> ""


Find my programs here in Dav's QB64 Corner
Reply


Messages In This Thread
Space Orbs. Small screen saver. - by Dav - 08-22-2023, 01:54 PM
RE: Space Orbs. Small screen saver. - by mrbcx - 08-22-2023, 03:01 PM
RE: Space Orbs. Small screen saver. - by Dav - 08-22-2023, 04:59 PM
RE: Space Orbs. Small screen saver. - by johnno56 - 08-22-2023, 08:38 PM
RE: Space Orbs. Small screen saver. - by Dav - 08-22-2023, 09:38 PM
RE: Space Orbs. Small screen saver. - by bplus - 08-22-2023, 09:54 PM
RE: Space Orbs. Small screen saver. - by dbox - 08-22-2023, 10:22 PM
RE: Space Orbs. Small screen saver. - by Dav - 08-22-2023, 10:30 PM
RE: Space Orbs. Small screen saver. - by dbox - 08-22-2023, 10:37 PM
RE: Space Orbs. Small screen saver. - by Dav - 08-22-2023, 10:44 PM
RE: Space Orbs. Small screen saver. - by Dav - 08-26-2023, 02:27 AM
RE: Space Orbs. Small screen saver. - by bplus - 08-26-2023, 01:18 PM
RE: Space Orbs. Small screen saver. - by Dav - 08-26-2023, 09:17 PM



Users browsing this thread: 4 Guest(s)