Skip to content

Instantly share code, notes, and snippets.

@ikr7 ikr7/main.cpp
Created Dec 10, 2018

Embed
What would you like to do?
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <cstdio>
#include <iostream>
#include <vector>
#include <complex>
#include "stb_image.h"
#include "stb_image_write.h"
int main () {
const int image_width = 256;
const int image_height = 256;
std::vector<unsigned char> pixels(image_width * image_height * 4);
const double center_x = 0.3602404434376143632;
const double center_y = 0.6413130610648031748;
double view_width = 5.0;
for (int n = 0; n < 30; n++) {
view_width *= 0.5;
double view_height = view_width * (image_height / image_width);
for (int y = 0; y < image_height; y++) {
int x;
const double ry = double(y) * (view_height / image_height) + center_y - view_height / 2.0;
#pragma omp parallel for
for (x = 0; x < image_width; x++) {
const size_t index = (y * image_width + x) * 4;
pixels[index + 0] = 0x00;
pixels[index + 1] = 0x00;
pixels[index + 2] = 0x00;
pixels[index + 3] = 0xFF;
const std::complex<double> c(
double(x) * (view_width / image_width) + center_x - view_width / 2.0,
ry
);
std::complex<double> z(0.0, 0.0);
for (int n = 0; n < 1024; n++) {
z = z * z + c;
if (std::abs(z) >= 2.0) {
int b = int(255.0 * double(n) / 1024);
pixels[index + 0] = b;
pixels[index + 1] = b;
pixels[index + 2] = b;
break;
}
}
}
}
char filename[64];
std::sprintf(filename, "out/%04d.png", n);
std::cout << "writing " << filename << " ... ";
stbi_write_png(filename, image_width, image_height, STBI_rgb_alpha, &(*pixels.begin()), 0);
std::cout << "done.\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.