Skip to content

Instantly share code, notes, and snippets.

@Xenakios
Created April 16, 2025 18:52
Show Gist options
  • Save Xenakios/778fc454b0d2fc848460c8474c7cac8d to your computer and use it in GitHub Desktop.
Save Xenakios/778fc454b0d2fc848460c8474c7cac8d to your computer and use it in GitHub Desktop.
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <complex>
#include <vector>
int main()
{
size_t w = 120;
size_t h = 40;
std::vector<char> framebuffer(w * h);
size_t num_iters = 100;
double bound = 2.0;
for (size_t x = 0; x < w; ++x)
{
for (size_t y = 0; y < h; ++y)
{
std::complex<double> c{-2.0 + 4.0 / w * x, -1.0 + 2.0 / h * y};
std::complex<double> z0;
for (size_t i = 0; i < num_iters; ++i)
{
auto z1 = std::pow(z0, 2.0) + c;
z0 = z1;
if (std::abs(z1) > bound)
{
framebuffer[w * y + x] = ' ';
break;
}
else
framebuffer[w * y + x] = '*';
}
}
}
for (size_t y = 0; y < h; ++y)
{
for (size_t x = 0; x < w; ++x)
{
std::cout << framebuffer[w * y + x];
}
std::cout << "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment