
I'm going to describe my version of the popular plasma demoscene effect. There may be another way of doing it, but my version works.
The basic effect uses an index into a pallete, which is defined using a sine based equation. The index depends on two variables (x and y). These are the coordinates of the screen point being evaluated. Example:
idx = sin((PI * x) / 45.0f) + sin((PI * y) / 90.0f);
45 and 90 are just values I've chosen randomly. Change them to alter the plasma. To plot this in screen, do this: for each point in the screen, apply the code. Use
idx
as an index into a greyscale pallete. There is a problem : it's static. The effect doesn't move. But don't worry, because it's very easy to animate! Change the first formula to:idx = sin((PI * x) / 45.0f) + sin((PI * y) / 90.0f) + sin((PI * i) / 180.0f);
There's a new element in the formula (
sin((PI * i) / 180.0f)
). There's a new variable in it (i
). If you increment that variable, the effect will animate. You could increment it after a screen draw.