diff options
author | Oliver Schinagl <oliver@schinagl.nl> | 2007-12-14 19:05:02 (GMT) |
---|---|---|
committer | Oliver Schinagl <oliver@schinagl.nl> | 2007-12-14 19:05:02 (GMT) |
commit | 1d771540b16ba07cb02be5490892465a2a5ab89a (patch) | |
tree | 56aa05fd872a9fc30aa7f80a59680d3c326227a0 /Smoke/palette.c | |
parent | 5a422dac78479f396437b5f9c1e8efbecf2c9b0f (diff) | |
download | 2iv35-1d771540b16ba07cb02be5490892465a2a5ab89a.zip 2iv35-1d771540b16ba07cb02be5490892465a2a5ab89a.tar.gz 2iv35-1d771540b16ba07cb02be5490892465a2a5ab89a.tar.bz2 |
new home for set_colormap
Diffstat (limited to 'Smoke/palette.c')
-rw-r--r-- | Smoke/palette.c | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/Smoke/palette.c b/Smoke/palette.c new file mode 100644 index 0000000..df24f04 --- /dev/null +++ b/Smoke/palette.c @@ -0,0 +1,114 @@ +#ifdef G_OS_WIN32 +#define WIN32_LEAN_AND_MEAN 1 +#include <windows.h> +#endif + + +#include <math.h> + +#include "funcs.h" +#include "palette.h" + + +//rainbow: Implements a color palette, mapping the scalar 'value' to a rainbow color RGB +void rainbow(float value, float *R, float *G, float *B) +{ + const float dx = 0.8f; + + if (value < 0) value = 0; + if (value > 1) value = 1; + + value = (6 - 2 * dx) * value + dx; + + *R = (float)max(0.0f, (3 - fabs(value - 4.0f) - fabs(value - 5.0f)) / 2.0f); + *G = (float)max(0.0f, (4 - fabs(value - 2.0f) - fabs(value - 4.0f)) / 2.0f); + *B = (float)max(0.0f, (3 - fabs(value - 1.0f) - fabs(value - 2.0f)) / 2.0f); +} + +void colormap_fire(float value, float *R, float *G, float *B) +{ + /* Colormap Fire + * A fire effect deals with two parts, first a drop from red to yellow (halfway) + * during which time the Red component remains full e.g. 1. The Green component is + * slowly added to turn the red into orange, and then yellow (R & G =Y). After this + * point, the Red and Green component (e.g. yellow) have to drop simulataniously + * to go from yellow down to black. + */ + *B = 0; + *G = 0; + *R = 0; + + if (value <= (0.01)) { + /* whilst value is 0 - 0.5 both red and green equally change to create yellow */ + *R = *G = value; + } else { + /* whilst value is 0.5 - 1 Red is always fully on while the Green component is + * added in steps to go from red to orange to yellow. + */ + *G = 0.9f - value; + *R = 0.8f; // not 1, makes red deeper, more intense + } +} + +//set_colormap: Sets three different types of colormaps +struct color4f set_colormap(int colormap_sort, float vy, float alpha) +{ + float R, G, B; + struct color4f return_value; + const int NLEVELS = 7; + +// vy *= olivers_color; +// vy = (float)(int)(vy); + // vy /= olivers_color; + + switch (colormap_sort) + { + case COLOR_BLACKWHITE: + R = G = B = vy; + break; + case COLOR_RAINBOW: + rainbow(vy,&R,&G,&B); + break; + case COLOR_BANDS: + vy *= NLEVELS; vy = (float)(int)(vy); vy/= NLEVELS; + rainbow(vy,&R,&G,&B); + break; + case COLOR_BLUE_GREEN_RED: + if (vy < -0.1) + { + R = G = 0; + vy -= -0.1f; + vy /= 0.9f; + B = -vy; + } + else if (vy < 0.1) + { + R = B = 0; + vy += 0.1f; + vy /= 0.2f; + G = vy; + } + else + { + vy -= 0.1f; + vy /= 0.9f; + R = vy; + G = B = 0; + } + break; + case COLOR_WILRIK: + colormap_fire(vy, &R, &G, &B); + break; + case COLOR_OLIVER: + rainbow(vy, &R, &G, &B); + break; + + } + + return_value.r = R; + return_value.g = G; + return_value.b = B; + return_value.a = alpha; + + return return_value; +} |