05-03-2022, 08:35 PM
This one is for johnno:
Code: (Select All)
Option _Explicit
_Title "Plasmatic Water Textures maybe" ' b+ 2020-01-26
' Hopefully this will add shading to the new color options found in Pasmatic 4.
' 2022-01-31 try water textures
Const xxmax = 800, yymax = 600, 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(360) As _Unsigned Long, p(10) As xy, f(10)
Dim i As Integer, m As Integer, n As Integer, mode As Integer, k$, t, x, y, d, dx, dy, dist, s
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 = 0: g1 = 0: b1 = 100 + Rnd * 155: r2 = 255: g2 = 255: b2 = 200 + Rnd * 55
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 360
If i Mod 60 = 0 Then r = 0: g = 0: b = 100 + Rnd * 155
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 2
p(n).x = Rnd * xmax: p(n).y = Rnd * yymax: p(n).dx = Rnd * 2 - 1: p(n).dy = Rnd * 2 - 1
f(n) = .1 * 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 5
p(i).x = p(i).x + p(i).dx
If p(i).x > xxmax Then p(i).dx = -p(i).dx: p(i).x = xxmax
If p(i).x < 0 Then p(i).dx = -p(i).dx: p(i).x = 0
p(i).y = p(i).y + p(i).dy
If p(i).y > xxmax Then p(i).dy = -p(i).dy: p(i).y = yymax
If p(i).y < 0 Then p(i).dy = -p(i).dy: p(i).y = 0
Next
For y = 0 To yymax - 1 Step 2
For x = 0 To xxmax - 1 Step 2
d = 0
For n = 0 To 5
dx = x - p(n).x: dy = y - p(n).y
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 * 60
Line (x + xoff, y + yoff)-Step(2, 2), c(d), BF
Next
Next
yCP yoff + yymax + 50, Space$(50)
yCP yoff + yymax + 50, TS$(Int(1000 * (Timer(.001) - t))) + " ms per frame"
_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
b = b + ...