Hello, everybody!
I'm new to this forum. I only started playing with fractals recently but I've been absolutely obsessed. I want to share some code that I think is hilarious:
#include <complex>
#include <iostream>
constexpr auto max_row = 22, max_column = 78, max_iteration = 20;
int main(){
for(auto row = 0; row < max_row; ++row){
for(auto column = 0; column < max_column; ++column){
std::complex<float> z, c = {
(float)column * 2 / max_column - 1.5f,
(float)row * 2 / max_row - 1
};
int iteration = 0;
while(abs(z) < 2 && ++iteration < max_iteration)
z = pow(z, 2) + c;
std::cout << (iteration == max_iteration ? '#' : '.');
}
std::cout << '\n';
}
}
Thanks to the standard library, working with complex numbers is very simple. std::complex has every operator overload and math function you could ever need and it's templated! Read more here:
http://en.cppreference.com/w/cpp/numeric/complexIf you compile and run this code you get this:
..............................................................................
......................................................#.......................
..................................................########....................
.................................................##########...................
....................................##.#....##################.###............
....................................####################################......
................................########################################......
...............................############################################...
.............###.#####.#.......###########################################....
.........#.#################..############################################....
.....#.#..################################################################....
######################################################################........
.....#.#..################################################################....
.........#.#################..############################################....
.............###.#####.#.......###########################################....
...............................############################################...
................................########################################......
....................................####################################......
....................................##.#....##################.###............
.................................................##########...................
..................................................########....................
......................................................#.......................
I've attached a file named "mandelbrot.cpp" which you can download, compile, and run for yourself. If you are using Ubuntu like me, all you need is
PS Don't be shy. I want to get to know you all. If you're working on something that isn't top secret tell me what it is