Skip to content

Instantly share code, notes, and snippets.

@jjimenezshaw
Created August 12, 2021 13:44
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jjimenezshaw/30f5b329b971ef3e8cd243cdc6da3c33 to your computer and use it in GitHub Desktop.
Save jjimenezshaw/30f5b329b971ef3e8cd243cdc6da3c33 to your computer and use it in GitHub Desktop.
Mandelbrot Set in asciiart in 15 lines
#include <complex>
#include <iostream>
int main() {
const size_t limit = 1000, size = 400; // change 'size' to make it more detailed
const char letters[] = " 123456789abcdefghijklmnopqrstuvwxyz*";
for (size_t iy = 0; iy <= size; iy++) {
for (size_t ix = 0, count = 0; ix <= size; ix++, count = 0) {
std::complex<double> c(-2.0+ix*2.5/size, 1.15-iy*2.3/size), z(0.0, 0.0);
while (std::norm(z) < 4.0 && count++ < limit) z = z*z+c;
std::cout << ((count >= limit) ? letters[0] : letters[std::min(count, sizeof(letters)-2)]);
}
std::cout << std::endl;
}
return 0;
}
@jjimenezshaw
Copy link
Author

mandelbrot

@matthiasdaues
Copy link

This looks darn cool. :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment