As you will probably see, I'm on a retro/demo type kick ATM
Two lines are not indented, to highlight them for your - this is so you can amend them and play around with the speed and pattern if you want.
The first is the speed that the pattern changes - make it larger to run faster.
The second is used to assign a pallet colour to a pixel, using the standard maths functions - this sets the pattern.
The code then just shifts the pallet and redraws it with the new colours.
OffsetSpeed = 6
sync on : sync rate 0 :Width = screen width() : Height = screen height() : MaxHoriz = Width - 1 : MaxVert = Height - 1 : global dim Colour(359) as dword : global dim Plasma(MaxHoriz, MaxVert) as integer : for Offset = 0 to 359 : Colour(Offset) = HSVtoRGB(Offset, 1.0, 1.0) : next : for x = MaxHoriz to 0 step -1 : for y = MaxVert to 0 step -1 : cx = x - Width/2 : cy = y - Height/2
Plasma(x, y) = int(sin(sqrt( cx * cx + cy * cy ) * 16.0) * 64.0 - 180.0 * sin( cx * 2.0) + 180.0 * sin( cy * 2.0 ) ) / 2
next : next : make memblock 1, Width * Height * 4 : Offset = 0 : do : MemPtr = 0 : for y = 0 to MaxVert : for x = 0 to MaxHoriz : write memblock dword 1, MemPtr, Colour( int(wrapvalue((Plasma(x, y) + Offset))) )
inc MemPtr, 4 : next x : next y : lock pixels : copy memory get pixels pointer(), get memblock ptr(1), get memblock size(1) : unlock pixels : sync : Offset = wrapvalue( Offset + OffsetSpeed ) : loop
function HSVtoRGB(H#, S#, V#)
if S# = 0.0 : exitfunction rgb(V#*255, V#*255, V#*255) : endif : H# = H# / 60.0 : F# = H# - int(H#) : P# = V# * (1.0 - S#) : Q# = V# * (1.0 - S# * F#) : T# = V# * (1.0 - S# * (1.0 - F#)) : select int(H#) : case 0 : exitfunction rgb(V#*255, T#*255, P#*255) : endcase : case 1 : exitfunction rgb(Q#*255, V#*255, P#*255) : endcase
case 2 : exitfunction rgb(P#*255, V#*255, T#*255) : endcase : case 3 : exitfunction rgb(P#*255, Q#*255, V#*255) : endcase : case 4 : exitfunction rgb(T#*255, P#*255, V#*255) : endcase : case 5 : exitfunction rgb(V#*255, P#*255, Q#*255) : endcase : endselect
endfunction 0
This also contains a HSV to RGB conversion function I've hacked down into a couple of lines ... it's easier to get a continuous colour pattern with HSV than RGB.