Friday, July 13, 2007

Random Sine Curves...

Randomly generated Sine curves with Cosine thickness and random amplitude, period and displacements. Used the standard fire color gradients: first from white to yellow, then from yellow to red, and then red "fades to black" ;) The code follows the images...

Images:








The main generation code:


int y = g->getHeight() / 2;
int y_period = 1 + rand() % 512;
int y_disp = 1 + rand() % g->getHeight();
int width = 128;
int width_period = 1 + rand() % 256;
int width_amp = 1 + rand() % 128;
int width_disp = 1 + rand() % 128;
for(int x = 0; x <>getWidth(); x++)
{
y = (int)(y_disp + width * sin(M_PI / y_period * x));
width = (int)(width_disp + width_amp * cos(M_PI / width_period * x));
drawVerticalFireLine(g, x, y, width);
}


The code for the line:


void drawVerticalFireLine(Graphics *g, int cx, int cy, int radius)
{
int seg_len = radius / 3;
//
// white to yellow
//
for(int i = 0; i <= seg_len; i++) { int intensity = (int)((1 - (double)i / (double)seg_len) * 255); g->putPixel(cx, cy + i, 255, 255, intensity);
g->putPixel(cx, cy - i, 255, 255, intensity);
}
//
// yellow to red
//
for(int i = 0; i <= seg_len; i++) { int intensity = (int)((1 - (double)i / (double)seg_len) * 255); g->putPixel(cx, cy + seg_len + i, 255, intensity, 0);
g->putPixel(cx, cy - seg_len - i, 255, intensity, 0);
}
//
// red to black
//
for(int i = 0; i <= seg_len; i++) { int intensity = (int)((1 - (double)i / (double)seg_len) * 255); g->putPixel(cx, cy + 2 * seg_len + i, intensity, 0, 0);
g->putPixel(cx, cy - 2 * seg_len - i, intensity, 0, 0);
}
}


More Images:





No comments: