About a year ago, in bplus's cool Proggies thread, a few of us had some fun playing with a program showing a small handful of Sin/Cos plasmas. I've added a bunch more to those, 20 patterns now, and put together this little screen saver to show them all. It will randomly show a different plasma pattern every 5 seconds. Current plasma number is shown in TITLE bar. You can skip to a new one by pressing SPACE. ESC ends. You can easily add one of your own, just add it to the SELECT CASE (and update the plasma select RND value).
- Dav
- Dav
Code: (Select All)
'================
'SuperPlasmas.bas
'================
'Coded by Dav for QB64PE, NOV/2025
'Plasma screensaver using Sin/Cos patterns.
'Randomly shows 1 of 20 plasmas every few seconds.
'Current Plasma number used is shown in TITLE bar.
'You can press SPACE to skip to a new Plasma num.
'ESC ends.
Randomize Timer
Screen _NewImage(_DesktopHeight, Int(_DesktopHeight * .75), 32)
cx = _Width / 2
cy = _Height / 2
Do
pulse = Sin(t) * .8 'pulse factor
t = Timer
If t - oldt >= 5 Then
plasma = Int(Rnd * 20) + 1 'get a new plasma every 5 seconds
oldt = t
End If
For y = 0 To _Height Step 4
For x = 0 To _Width Step 4
a = _Atan2(y - cy, x - cx) 'base angle
Select Case plasma
'old effects
Case 1: a = a + _Atan2(y - cy, x - cx) + Sin(rad * 2 + t) 'spiral twist
Case 2: a = a + _Atan2(y - cy, x - cx) + Sin(t) * 4 'churning sin
Case 3: a = a + _Atan2(y - cy, x - cx) + Cos(t) * 4 'churning cos
Case 4: a = a + _Atan2(y - cy, x - cx) + Sin(t) * rad 'spiral radius
Case 5: a = a + _Atan2(y - cy, x - cx) + Sin(t * 4 + (x / _Width)) * .5 'edge wave
Case 6: a = a + _Atan2(y - cy, x - cx) + (x / _Width) * Sin(t) * 5 'distort
Case 7: a = a + _Atan2(y - cy, x - cx) + Cos(t) * 3 + Sin(x / _Width + t * 3) 'better wave
Case 8: a = a + _Atan2(y - cy, x - cx) + Sin(t * 2) * Cos(rad * 2) 'double twist!
Case 9: a = a + _Atan2(y - cy, x - cx) + Sin(rad * 1.5 + t * 4) 'inward spiral
Case 10: a = a + _Atan2(y - cy, x - cx) + Sin(x * .01 + t) * Cos(y * .01 + t) 'mumps!
'new effects
Case 11: a = a + _Atan2(y - cy, x - cx) + Sin(t * .5 + rad * .3) * 2 'slower spiral wave
Case 12: a = a + _Atan2(y - cy, x - cx) + Cos(t * 1.5 + rad * .7) * 3 'another twist
Case 13: a = a + _Atan2(y - cy, x - cx) + Sin(rad * 4 + t * .8) * 1.5 'radial ripple
Case 14: a = a + _Atan2(y - cy, x - cx) + Sin(x * .05 + t) * 2 'horizontal wave
Case 15: a = a + _Atan2(y - cy, x - cx) + Cos(y * .05 + t) * 2 'vertical wave
Case 16: a = a + _Atan2(y - cy, x - cx) + Sin(rad * 6 + t * 1.2) * 2 'higher ripples
Case 17: a = a + _Atan2(y - cy, x - cx) + Sin(x * .02 + t * 2) * Cos(y * .02 + t * 2) 'more wave
Case 18: a = a + _Atan2(y - cy, x - cx) + Sin(rad * 3 + t * 1.5) * Sin(rad * 3 + t * 1.5) 'more ripples
Case 19: a = a + _Atan2(y - cy, x - cx) + Sin(rad * 3 + t * 2) * 3 'wavy circles
Case 20: a = a + _Atan2(y - cy, x - cx) + Sin(rad * 6 + t) + Sin(a * 3 + t * 2) 'more wavy pattern
End Select
rad = Sqr((x - cx) ^ 2 + (y - cy) ^ 2) / 100
'plasma colors
r1 = (Sin(rad * 2 + t) + Sin(a * 5 + t)) * 127 + 128
g1 = (Sin(rad * 2 + t + 1) + Sin(a * 5 + t + 1)) * 127 + 128
b1 = (Sin(rad * 2 + t + 2) + Sin(a * 5 + t + 2)) * 127 + 128
r2 = (Sin(rad * 3 + t) + Sin(a * 3 + t + 1)) * 127 + 128
g2 = (Sin(rad * 3 + t + 2) + Sin(a * 3 + t + 3)) * 127 + 128
b2 = (Sin(rad * 3 + t + 4) + Sin(a * 3 + t + 4)) * 127 + 128
'blend colors with pulse
r = r1 * (1 - pulse) + r2 * pulse
g = g1 * (1 - pulse) + g2 * pulse
b = b1 * (1 - pulse) + b2 * pulse
Line (x, y)-Step(3, 3), _RGBA(r, g, b, 150), BF
Next
Next
Select Case InKey$
Case Chr$(27): Exit Do
Case Chr$(32)
plasma = Int(Rnd * 20) + 1
oldt = t
End Select
_Title "Plasma: " + Str$(plasma) + " (SPACE changes, ESC Quits)"
_Display
_Limit 30
Loop
End


![[Image: image.png]](https://i.ibb.co/qYwjYrYn/image.png)
Maybe add colorshift description to the _Title string? And long term, a pause key and fullscreen mode and perhaps an adjustable speed and/or duration per plasma parameter might be nice. (I say as if there was profit to be made, ha ha! I bet it's been a long time since anyone sold a screen saver. After Dark was awesome!)