🚩 Home / 💻 Projects / Mandelbrot / Mandelbrot.cpp
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;

class complex
{
public:
    double real, imag;
    void print()                        {printf("%lf", real); if (imag >= 0) putchar('+'); printf("%lfi", imag);}
    double mod()                        {return sqrt(real * real + imag * imag);}
    
    complex()                           {real = imag = 0;}
    complex(double r, double i)         {real = r, imag = i;}
    complex(const complex &t)           {real = t.real, imag = t.imag;}
    complex operator=(const complex &t) {real = t.real, imag = t.imag; return *this;}
    complex operator+(const complex &t) {return complex(real + t.real, imag + t.imag);}
    complex operator-(const complex &t) {return complex(real - t.real, imag - t.imag);}
    complex operator*(const complex &t) {return complex(real * t.real - imag * t.imag, imag * t.real + real * t.imag);}
    complex operator-()                 {return complex(-real, -imag);}
    complex operator*(double t)         {return complex(real * t, imag * t);}
};

const char col[] = {"abcdefghijklmnopqrstuvwxyz"};

const int GEN_MAX = 256;
const double CIRCLE = 2;
const int SIZE = 90;

int main()
{
    for (int i = -SIZE; i <= SIZE; i++)
    {
        for (int j = -SIZE; j <= SIZE; j++)
        {
            complex C((double)i / 40, (double)j / 40), Z(0, 0);
            int ts = 0;
            while (ts <= GEN_MAX && Z.mod() <= CIRCLE) {ts++; Z = (Z * Z) + C;}
            cout << col[ts % 10];
        }
        printf("\n");
    }
    return 0;
}
DOWNLOAD