Last version probably. Orbs now each have twirling plasma colors, and I add a space portal that randomly opens and closes in the center of the screen now and then. It may be too distracting, but I like the colors better than the other versions. Not running in qbjs yet, so here's the qb64 code box...
- Dav
- Dav
Code: (Select All)
'=============
'SpaceOrbs3.bas
'=============
'Screesaver of Orbs pulsating in space
'Coded by Dav for QB64-PE, AUGUST/2023
'v3 - Gave orbs a more of a twirling plasma color effect.
' - Added space portal that randomly opens/closes, now and then.
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), OrbDir(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
OrbDir(i) = INT(RND * 4) 'random direction orb can drift (4 different ways)
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 * 175), BF
NEXT
'=== grab screen image for repeated use
back& = _COPYIMAGE(_DISPLAY)
BackX = 0
DO
'=== scroll starry background first
_PUTIMAGE (BackX, 0)-(BackX + _WIDTH, _HEIGHT), back&
_PUTIMAGE (BackX - _WIDTH, 0)-(BackX, _HEIGHT), back&
BackX = BackX + 4: IF BackX >= _WIDTH THEN BackX = 0
'=== do the space portal
IF INT(RND * 80) = 1 THEN portal = 1 'randomly turn portal on
IF portal = 1 THEN
v = RND * 50 + 10
FOR t = 1 TO (_WIDTH / 2)
x1 = (COS(t) * z) + (_WIDTH / 2)
y1 = (SIN(t) * z) + (_HEIGHT / 2)
LINE (x1, y1)-(x1 + (z / v), y1 + (z / v)), _RGBA(r, g, b, 25 + RND * 50), BF
CIRCLE (x1, y1), z / 30, _RGBA(r, g, b, 25 + RND * 50)
IF INT(RND * 2) = 0 THEN z = z - 2 ELSE z = z + 2
IF z > (_WIDTH / 2) OR z < -(_WIDTH / 2) THEN z = 1
r = r + 1: IF r > 255 THEN r = RND * 255
g = g + 1: IF g > 255 THEN g = RND * 255
b = b + 1: IF b > 255 THEN b = RND * 255
NEXT
IF INT(RND * 50) = 1 THEN portal = 0 'randomly turn portal off
END IF
'=== 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, 50), 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(x2 / (OrbSize(i) / 4)) + SIN(y2 / OrbSize(i) / 2)) * 128 + 128
g = (SIN(x2 / (OrbSize(i) / 6)) + COS(y2 / (OrbSize(i) / 4))) * 128 + 128
b = (COS(x2 / (OrbSize(i) / 4)) + SIN(y2 / (OrbSize(i) / 6))) * 128 + 128
LINE (x2, y2)-STEP(2, 2), _RGBA(clr * r, clr * g, clr * b, 20 + RND * 25), 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
'and reset x/y pos
IF OrbSize(i) <= OrbSizeMin THEN
OrbGrowth(i) = 1
OrbX(i) = RND * _WIDTH
OrbY(i) = RND * _HEIGHT
END IF
'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
'drift orb in 1 of 4 directions we generated, and +x,-x,+y,-y to it.
IF OrbDir(i) = 0 THEN OrbX(i) = OrbX(i) + 2 'drift right
IF OrbDir(i) = 1 THEN OrbX(i) = OrbX(i) - 2 'drift left
IF OrbDir(i) = 2 THEN OrbY(i) = OrbY(i) + 2 'drift down
IF OrbDir(i) = 3 THEN OrbY(i) = OrbY(i) - 2 'drift up
'below handles if ball goes off screen, let it dissapear completely
IF OrbX(i) > _WIDTH + OrbSize(i) THEN OrbX(i) = -OrbSize(i)
IF OrbX(i) < -OrbSize(i) THEN OrbX(i) = _WIDTH + OrbSize(i)
IF OrbY(i) > _HEIGHT + OrbSize(i) THEN OrbY(i) = -OrbSize(i)
IF OrbY(i) < -OrbSize(i) THEN OrbY(i) = _HEIGHT + OrbSize(i)
NEXT
'== screen blur trick to make it more misty looking
tmpback& = _COPYIMAGE(_DISPLAY)
_SETALPHA 50, , tmpback&
_PUTIMAGE (-1, 0), tmpback&: _PUTIMAGE (1, 0), tmpback&
_PUTIMAGE (0, -1), tmpback&: _PUTIMAGE (0, 1), tmpback&
_PUTIMAGE (-1, -1), tmpback&: _PUTIMAGE (1, -1), tmpback&
_FREEIMAGE tmpback&
_DISPLAY
_LIMIT 15
LOOP UNTIL INKEY$ <> ""