Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Plasma
#1
Here is a Plasma demo that I found on QB64pe site (coded by Dav)

There are 20 pre-sets. Roughly 5 seconds between each. Space key to advance the count. Frame rates may need tweaking a little...

   


Code:
set window "Plasma", 720, 720, false
'   Coded by Dav for QB64PE, NOV/2025
'   N7 version johnno56 DEC/2025
set redraw off

visible cx = width(primary) / 2
visible cy = height(primary) / 2
visible plasma
visible radd

fnt = createfont("arial", 48, true, false, false, true)
set font fnt

t = clock()
oldt = 0 'clock()
plasma = 1

set color 0, 0, 0; cls

do
    pulse = sin(t) * 0.8
   
    t = clock()
    if t - oldt >= 5000
        plasma = plasma + 1
        if plasma > 20  plasma = 1
        oldt = t
    endif
   
    for y = 0 to height(primary) step 4
        for x = 0 to width(primary) 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(radd * 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) * radd 'spiral radius
                case 5
                    a = a + atan2(y - cy, x - cx) + sin(t * 4 + (x / width(primary))) * 0.5 'edge wave
                case 6
                    a = a + atan2(y - cy, x - cx) + (x / width(primary)) * sin(t) * 5 'distort
                case 7
                    a = a + atan2(y - cy, x - cx) + cos(t) * 3 + sin(x / width(primary) + t * 3) 'better wave
                case 8
                    a = a + atan2(y - cy, x - cx) + sin(t * 2) * cos(radd * 2) 'double twist!
                case 9
                    a = a + atan2(y - cy, x - cx) + sin(radd * 1.5 + t * 4) 'inward spiral
                case 10
                    a = a + atan2(y - cy, x - cx) + sin(x * 0.01 + t) * cos(y * 0.01 + t) 'mumps!
                    'new effects
                case 11
                    a = a + atan2(y - cy, x - cx) + sin(t * 0.5 + radd * 0.3) * 2 'slower spiral wave
                case 12
                    a = a + atan2(y - cy, x - cx) + cos(t * 1.5 + radd * 0.7) * 3 'another twist
                case 13
                    a = a + atan2(y - cy, x - cx) + sin(radd * 4 + t * 0.8) * 1.5 'radial ripple
                case 14
                    a = a + atan2(y - cy, x - cx) + sin(x * 0.05 + t) * 2 'horizontal wave
                case 15
                    a = a + atan2(y - cy, x - cx) + cos(y * 0.05 + t) * 2 'vertical wave
                case 16
                    a = a + atan2(y - cy, x - cx) + sin(radd * 6 + t * 1.2) * 2 'higher ripples
                case 17
                    a = a + atan2(y - cy, x - cx) + sin(x * 0.02 + t * 2) * cos(y * 0.02 + t * 2) 'more wave
                case 18
                    a = a + atan2(y - cy, x - cx) + sin(radd * 3 + t * 1.5) * sin(radd * 3 + t * 1.5) 'more ripples
                case 19
                    a = a + atan2(y - cy, x - cx) + sin(radd * 3 + t * 2) * 3 'wavy circles
                case 20
                    a = a + atan2(y - cy, x - cx) + sin(radd * 6 + t) + sin(a * 3 + t * 2) 'more wavy pattern
            endsel
           
            radd = sqr((x - cx) ^ 2 + (y - cy) ^ 2) / 100
           
            '   Plasma colours
            r1 = (sin(radd * 2 + t) + sin(a * 5 + t)) * 127 + 128
            g1 = (sin(radd * 2 + t + 1) + sin(a * 5 + t + 1)) * 127 + 128
            b1 = (sin(radd * 2 + t + 2) + sin(a * 5 + t + 2)) * 127 + 128
            r2 = (sin(radd * 3 + t) + sin(a * 3 + t + 1)) * 127 + 128
            g2 = (sin(radd * 3 + t + 2) + sin(a * 3 + t + 3)) * 127 + 128
            b2 = (sin(radd * 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
           
            set color r, g, b, 150
            draw rect x, y, 4, 4, true
        next
    next

    set color 0, 0, 0
    set caret 5, 5
    wln str(plasma)
    set color 255, 255, 255
    set caret 3, 3
    wln str(plasma)
                   
    if keydown(KEY_ESCAPE, true)    break
    if keydown(KEY_SPACE)
        plasma = plasma + 1
        if plasma > 20  plasma = 1
        oldt = t
    endif
   
    redraw
    fwait 10
loop

Big Grin
Logic is the beginning of wisdom.
Reply
#2
I have a very simple hypnotic circle .... 

Code:
set window "Hypnotic Circle", 360, 360, false
set redraw off

w = 360
h = 360
cx = w / 2
cy = h / 2

do
    t = clock() * 0.001

    for y = 0 to h - 1 step 4
        for x = 0 to w - 1 step 4
            dx = x - cx
            dy = y - cy

            ' Euclidean distance from center
            r = sqr(dx*dx + dy*dy)

            ' Single clean ripple wave: sin(r - t)
            wave = sin(r * 0.2 - t)
            wave2 = sin(r * 0.6 - t * 2.7)
            value = (wave + wave2) * 0.5

            ' Map [-1, 1] to [0, 255]
            c = (value * 127) + 128

            ' Color adjustment
            rcol = (sin(value + t) * 127) + 128
            gcol = (sin(value + t + 2.094) * 127) + 128
            bcol = (sin(value + t + 4.188) * 127) + 128

            set color rcol, gcol, bcol
            draw rect x, y, 4, 4, true
        next
    next

    redraw
    fwait 16
loop
Reply
#3
My eyes! My eyes! I cannot feel my eyes!

lol... Very cool...!!
Logic is the beginning of wisdom.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)