Hi,
I was wondering if anyone had a simple algorithm for drawing plasma. I am trying to write an OpenGL program to simulate that plasma before I can implement it in hardware. The problem is that my plasmas have very regular shapes. Also, since they will have to change depending on the audio that is input (like a winamp visualization) I need to be able to affect the plasma by playing with some of the variables. But they need to have smooth changes.
The current algorithm I have right now is as follows:
I have a 512x512 matrix (representing my screen raster) that holds values of intensity from 0 to 511 that were obtained by adding 2 cos and 2 sin. Now when I draw to screen, I go through the matrix and each intensity value refers to a specific color stored in an array. The smoothest results are obtained by storing a gradient in that array. However, it's too regular. I get circles and squares, etc. I'm looking for the more diffuse plasma look. As well as one with variables that affect how the plama behaves but without too drastic a change. I'll post my code just to give you a general idea. It's not the entire thing.
Code:
void initColorArray()
{
int i;
float tempR, tempG, tempB;
long pos1;
tempR = 1.0f;
tempG = 0.0f;
tempB = 0.0f;
colorArray = (Color*)malloc(sizeof(Color)*512);
// Array loaded with a gradient
for(i = 0; i < 512; i++)
{
colorArray[i] = createColor(tempR - i*1.0f/512.0f, tempG, tempB + i*1.0f/512.0f);
}
// A table holding a few cos and sin values so that I only need to compute them once
for (pos1 = 0;pos1 < 360;pos1++)
{
tcos[pos1] = abs(cos(pos1*PI/180) * 128);
tsin[pos1] = abs(sin(pos1*PI/180) * 128);
}
}
void Move_Plasma(long pos1, long pos2, long pos3, long pos4, int pattern)
{
// pos1 through pos4 affect the general shape direction of movement
long i,j,color,p1,p2,p3,p4;
p1 = pos1;
p2 = pos2;
for (i = 0;i < 512;i++)
{
p3 = pos3;
p4 = pos4;
for (j = 0;j < 512;j++)
{
color = tcos[p1 % 360] + tcos[p2 % 360] + tsin[p3 % 360] + tsin[p4 % 360];
// Pattern here affects what colors in the gradient are referenced
if(pattern == 0)
{
// do nothing
}
else if(pattern == 1)
{
color = (color + 10) % 512;
}
else if(pattern == 2)
{
color = (color + 20) % 512;
}
else if(pattern == 3)
{
color = (color + 30) % 512;
}
Color tempC = colorArray[color];
glColor3f(tempC.R, tempC.G, tempC.B);
glVertex3f((float)i*0.0097f, (float)(-1*j*0.0097f), 0);
// p1 through p4 affect the movement and the general shape of the pattern
// however, changing them changes the pattern instantly.
// There is no smooth transition
// these 2 affect the number of patterns along the height
p3 += 1; // + sideways transmutation for this one
p4 += 1; // + vertical transmutation for this one
}
// these 2 affect the number of patterns along the width
p1 += 1; // + vertical transmutation
p2 += 1; // + sideways transmutation
}
}
Thanks in advance