diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2022-12-28 16:00:22 +0100 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2022-12-28 16:00:22 +0100 |
| commit | 03389d193181128c3911543a52c78a6e7631ab57 (patch) | |
| tree | 964fc75db5931eb06b861b38a544926409ebfc69 | |
| parent | 72b8054ecc4c53cb9a138266fd267f2334f32a37 (diff) | |
Replace an enum with 'const' variables in test/animated.cxx
- replace enum value 'FRAMES' with 'const unsigned int frames'
- replace enum value 'DIM' with 'const unsigned int dim'
- remove commented statements that have never been used.
Note: this also changes uppercase enum values to lowercase constants.
| -rw-r--r-- | test/animated.cxx | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/test/animated.cxx b/test/animated.cxx index cd5172885..e7f8ea793 100644 --- a/test/animated.cxx +++ b/test/animated.cxx @@ -1,7 +1,7 @@ // // Alpha rendering benchmark program for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2018 by Bill Spitzak and others. +// Copyright 1998-2022 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -25,19 +25,19 @@ #include <stdlib.h> #include <string.h> -enum { - FRAMES = 48, - DIM = 256 -}; +// These constants define the image dimensions and +// the number of frames of the animation +const unsigned int dim = 256; +const unsigned int frames = 48; -static Fl_RGB_Image *img[FRAMES]; +static Fl_RGB_Image *img[frames]; static uchar curframe; static void make_images() { unsigned i; - for (i = 0; i < FRAMES; i++) { - const unsigned size = DIM * DIM * 4; + for (i = 0; i < frames; i++) { + const unsigned size = dim * dim * 4; uchar *data = new uchar[size]; memset(data, 0, size); @@ -46,19 +46,19 @@ static void make_images() { int x, y; for (x = 0; x < 10; x++) { for (y = 0; y < 10; y++) { - data[y * DIM * 4 + x * 4 + 3] = 255; + data[y * dim * 4 + x * 4 + 3] = 255; } } // A fading sphere uchar alpha = 255; - if (i < FRAMES / 2) - alpha = uchar(255 * (i / ((float) FRAMES / 2))); + if (i < frames / 2) + alpha = uchar(255 * (i / ((float) frames / 2))); else - alpha = uchar(255 * (((FRAMES / 2) - (i - FRAMES / 2)) / ((float) FRAMES / 2))); + alpha = uchar(255 * (((frames / 2) - (i - frames / 2)) / ((float) frames / 2))); const int spherew = 60; - const int spherex = (DIM - spherew) / 2; + const int spherex = (dim - spherew) / 2; const int maxdist = (spherew / 2) * (spherew / 2); for (x = spherex; x < spherex + spherew; x++) { for (y = 20; y < 20 + spherew; y++) { @@ -77,33 +77,31 @@ static void make_images() { if (fill > 0.9) myalpha *= uchar((1.0f - fill) * 10); - data[y * DIM * 4 + x * 4 + 0] = grey; - data[y * DIM * 4 + x * 4 + 1] = grey; - data[y * DIM * 4 + x * 4 + 2] = grey; - data[y * DIM * 4 + x * 4 + 3] = myalpha; + data[y * dim * 4 + x * 4 + 0] = grey; + data[y * dim * 4 + x * 4 + 1] = grey; + data[y * dim * 4 + x * 4 + 2] = grey; + data[y * dim * 4 + x * 4 + 3] = myalpha; } } // A moving blob - const float pos = (i / (float) FRAMES) * 2 - 0.5f; + const float pos = (i / (float) frames) * 2 - 0.5f; - const int xoffset = int(pos * (int)DIM); + const int xoffset = int(pos * DIM); const int yoffset = 2 * DIM / 3; const int w = DIM / 4; for (x = -w; x < w; x++) { - if (x + xoffset < 0 || x + xoffset >= DIM) + if (x + xoffset < 0 || x + xoffset >= (int)dim) continue; for (y = yoffset - w; y < yoffset + w; y++) { const uchar grey = abs(y - yoffset); -// data[y * DIM * 4 + (x + xoffset) * 4 + 0] = grey; -// data[y * DIM * 4 + (x + xoffset) * 4 + 1] = grey; - data[y * DIM * 4 + (x + xoffset) * 4 + 2] = grey; - data[y * DIM * 4 + (x + xoffset) * 4 + 3] = 127; + data[y * dim * 4 + (x + xoffset) * 4 + 2] = grey; + data[y * dim * 4 + (x + xoffset) * 4 + 3] = 127; } } - img[i] = new Fl_RGB_Image(data, DIM, DIM, 4); + img[i] = new Fl_RGB_Image(data, dim, dim, 4); } } @@ -117,7 +115,7 @@ public: // Test both cx/cy offset and clipping. Both borders should have a 5-pixel edge, // and the upper-left black box should not be visible. fl_push_clip(5, 5, w() - 5, h() - 5); - img[curframe]->draw(0, 0, DIM, DIM, 5, 5); + img[curframe]->draw(0, 0, dim, dim, 5, 5); fl_pop_clip(); } }; @@ -131,7 +129,7 @@ static void cb(void *) { Fl::repeat_timeout(1.0f / 24, cb); curframe++; - curframe %= FRAMES; + curframe %= frames; } int main(int argc, char **argv) { |
