The plasma effect is a visual effect created by applying various functions, notably sine and cosine, to the color values of screen pixels. When animated (not a task requirement) the effect may give the impression of a colorful flowing liquid.



Task
Create a plasma effect.




See also
 Computer Graphics Tutorial (lodev.org)
 Plasma (bidouille.org)


func real Dist(X1, Y1, X2, Y2);
int     X1, Y1, X2, Y2;
return sqrt( float((X1-X2)*(X1-X2) + (Y1-Y2)*(Y1-Y2)) );
 
int     Time, X, Y, Color;
real    Value;
[SetVid($112);  \640x480x24
repeat  Time:= GetTime/50_000;
        for Y:= 0 to 256-1 do
            for X:= 0 to 256-1 do
                [Value:= Sin(Dist(X+Time, Y, 128, 128) / 8.0) +
                         Sin(Dist(X, Y, 64, 64) / 8.0) +
                         Sin(Dist(X, Y+Time/7, 192, 64) / 7.0) +
                         Sin(Dist(X, Y, 192, 100) / 8.0);
                Color:= fix((4.0+Value) * 31.875);      \[0..255]
                Point(X, Y, Color<<16 + ((Color*2)&$FF)<<8 + (255-Color));
                ];
until   KeyHit;
]