Skip to content

Instantly share code, notes, and snippets.

@Centrinia
Created July 11, 2019 08:38
Show Gist options
  • Save Centrinia/f899a58f76e0cefe08abcaaa698dcf93 to your computer and use it in GitHub Desktop.
Save Centrinia/f899a58f76e0cefe08abcaaa698dcf93 to your computer and use it in GitHub Desktop.
Generate all 1000x1000 24 bit color images.
#include <cstdint>
typedef std::size_t size_t;
template <typename color_t, typename Func>
void generate_images(size_t width, size_t height, size_t components, color_t limit, Func visit) {
size_t image_size = width * height * components;
color_t* image;
size_t* focus;
bool* direction;
image = new color_t[image_size];
focus = new size_t[image_size + 1];
direction = new bool[image_size];
for(size_t i = 0; i < image_size; i++) {
image[i] = 0;
direction[i] = true;
}
for(size_t i = 0; i <= image_size; i++) {
focus[i] = i;
}
for(;;) {
visit(width, height, components, image);
size_t update = focus[0];
focus[0] = 0;
if(update >= image_size) {
break;
}
image[update] += direction[update] ? 1 : -1;
if(image[update] == 0 || image[update] == limit) {
direction[update] = !direction[update];
focus[update] = focus[update + 1];
focus[update + 1] = update + 1;
}
}
delete[] focus;
delete[] image;
delete [] direction;
}
int main() {
typedef uint8_t color_t;
size_t width = 1000;
size_t height = 1000;
size_t components = 3;
generate_images<color_t>(width, height, components, ~0, [](size_t width, size_t height, size_t components, color_t* image) {
/* TODO: Do something with the image. */
});
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment