Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Plasma Studies
#6
Then I start attempting faster frame Plasma letting small squares of color replace pixels:
Code: (Select All)
Option _Explicit
_Title "Plasmatic 5.1 Speed Tests" ' b+ 2020-01-26
' Try no SQR for distance

Const xxmax = 700, yymax = 500, xmax = 900, ymax = 740, xoff = (xmax - xxmax) \ 2, yoff = (ymax - yymax) \ 2
Type xy
    x As Single
    y As Single
    dx As Single
    dy As Single
End Type
Screen _NewImage(xmax, ymax, 32)
_ScreenMove 250, 0
Randomize Timer
Dim c(1440) As _Unsigned Long, p(6) As xy, f(6)
Dim i As Integer, m As Integer, n As Integer, mode As Integer, cnt As Integer, k$, t, x, y, d, dx, dy, dist, s, stepper, tot
Dim r As Integer, g As Integer, b As Integer, r1 As Integer, g1 As Integer, b1 As Integer, r2 As Integer, g2 As Integer, b2 As Integer

restart: 'select rgb1 and rgb2 based on mode of color mixing
If mode = 0 Then 'new plasma option ANY color for border and ANY color for middle
    r1 = Rnd * 255: g1 = Rnd * 255: b1 = Rnd * 255: r2 = Rnd * 255: g2 = Rnd * 255: b2 = Rnd * 255
Else ' traditional high contrast plasma black borders, white centers
    r1 = 0: g1 = 0: b1 = 0: r2 = 255: g2 = 255: b2 = 255 'regular Plasma
End If

' create 6 x 60 bands of color palette based on coloring mode (rgb1 set and rgb2 set)
For i = 0 To 720
    If i Mod 60 = 0 Then r = Rnd * 255: g = Rnd * 255: b = Rnd * 255
    m = i Mod 60
    s = 1 - ((30 - m + .5) / 30) ^ 2
    Select Case m
        Case Is < 15: c(i) = midInk(s * r1, s * g1, s * b1, s * r, s * g, s * b, m / 15) '        1st stage increase rgb1 towards rgb color in 15 steps
        Case Is < 30: c(i) = midInk(s * r, s * g, s * b, s * r2, s * g2, s * b2, (m - 15) / 15) ' 2nd stage increase rgb color towards rgb2 set in 15 steps
        Case Is < 45: c(i) = midInk(s * r2, s * g2, s * b2, s * r, s * g, s * b, (m - 30) / 15) ' 3rd stage decrease rgb2 color back to rgb color in 15 steps
        Case Is < 60: c(i) = midInk(s * r, s * g, s * b, s * r1, s * g1, s * b1, (m - 45) / 15) ' 4th and finally decrease rgb back to starting rgb1 set in 15 steps
    End Select
Next

' behind the scenes variables for motion, weighting and shaping color mixing
For n = 0 To 6
    p(n).x = Rnd * xmax: p(n).y = Rnd * yymax: p(n).dx = Rnd * 2 - 1: p(n).dy = Rnd * 2 - 1
    f(n) = .09 * Rnd
Next

'screen labeling 3 lines for title above, 1 line instructions below
Cls
If mode = 0 Then
    yCP yoff - 60, "New Color Options for Plasma:"
Else
    yCP yoff - 60, "Traditional High Contrast Plasma: Black Borders and White Centers"
End If
yCP yoff - 40, "Shaded Borders: RGB(" + TS$(r1 \ 1) + ", " + TS$(g1 \ 1) + ", " + TS$(b1 \ 1) + ")"
yCP yoff - 20, "Centers: RGB(" + TS$(r2 \ 1) + ", " + TS$(g2 \ 1) + ", " + TS$(b2 \ 1) + ")"
yCP yoff + yymax + 10, "Press t to toggle between Traditional and New Color Options Plasma"
yCP yoff + yymax + 30, "Press spacebar to get a new color set."

While _KeyDown(27) = 0
    k$ = InKey$
    If k$ = " " Then GoTo restart
    If k$ = "t" Then mode = 1 - mode: GoTo restart
    t = Timer(.001)
    For i = 0 To 6
        p(i).x = p(i).x + p(i).dx
        If p(i).x > 2 * xxmax Then p(i).dx = -p(i).dx: p(i).x = 2 * xxmax
        If p(i).x < -xxmax Then p(i).dx = -p(i).dx: p(i).x = -xxmax
        p(i).y = p(i).y + p(i).dy
        If p(i).y > 2 * yymax Then p(i).dy = -p(i).dy: p(i).y = 2 * yymax
        If p(i).y < -yymax Then p(i).dy = -p(i).dy: p(i).y = -yymax
    Next
    stepper = 3
    For y = 0 To yymax - 1 Step stepper
        For x = 0 To xxmax - 1 Step stepper
            d = 0
            For n = 0 To 6
                dx = x - p(n).x: dy = y - p(n).y
                dist = .0005 * (dx * dx + dy * dy)
                'dist = SQR(dx * dx + dy * dy)
                'dist = _HYPOT(dx, dy)    'this may work faster on another system
                d = d + (Sin(dist * f(n)) + 1) / 2
            Next n: d = d * 120
            Line (x + xoff, y + yoff)-Step(stepper, stepper), c(d), BF
        Next
    Next
    cnt = cnt + 1
    tot = tot + Timer(.001) - t
    If cnt = 100 Then
        yCP yoff + yymax + 50, Space$(50)
        yCP yoff + yymax + 50, Right$("   " + TS$(Int(1000 * tot / 100)), 4) + " ms per frame"
        cnt = 0: tot = 0
    End If
    _Display
Wend

Function midInk~& (r1%, g1%, b1%, r2%, g2%, b2%, fr##)
    midInk~& = _RGBA32(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##, 255)
End Function

Sub yCP (y, s$) 'for xmax pixel wide graphics screen Center Print at pixel y row
    _PrintString ((_Width - Len(s$) * 8) / 2, y), s$
End Sub

Function TS$ (n As Integer)
    TS$ = _Trim$(Str$(n))
End Function


Attached Files Image(s)
   
b = b + ...
Reply


Messages In This Thread
Plasma Studies - by bplus - 05-03-2022, 08:03 PM
RE: Plasma Studies - by bplus - 05-03-2022, 08:08 PM
RE: Plasma Studies - by bplus - 05-03-2022, 08:12 PM
RE: Plasma Studies - by bplus - 05-03-2022, 08:16 PM
RE: Plasma Studies - by bplus - 05-03-2022, 08:21 PM
RE: Plasma Studies - by bplus - 05-03-2022, 08:26 PM
RE: Plasma Studies - by bplus - 05-03-2022, 08:31 PM
RE: Plasma Studies - by bplus - 05-03-2022, 08:35 PM
RE: Plasma Studies - by bplus - 05-03-2022, 08:38 PM
RE: Plasma Studies - by bplus - 05-03-2022, 08:45 PM
RE: Plasma Studies - by bplus - 05-03-2022, 08:49 PM
RE: Plasma Studies - by Dav - 05-03-2022, 11:16 PM
RE: Plasma Studies - by bplus - 05-03-2022, 11:53 PM
RE: Plasma Studies - by Coolman - 05-04-2022, 11:00 AM
RE: Plasma Studies - by vince - 05-05-2022, 12:34 AM



Users browsing this thread: 3 Guest(s)