This is the Capstone project of Udacity's C++ Nanodegree.
The mandelbort
program draws a Mandelbrot set on an image with size given by user.
The image size must be one of the values 128, 256, 512, 1024. User can zoom in and zoom out in the image and select the center point for zooming.
i
: zoom ino
: zoom outq
: close window and quitmouse click
: set center point for zooming
- cmake >= 3.7
- All OSes: click here for installation instructions
- make >= 4.1 (Linux, Mac), 3.81 (Windows)
- Linux: make is installed by default on most Linux distros
- Mac: install Xcode command line tools to get make
- Windows: Click here for installation instructions
- gcc/g++ >= 5.4
- Linux: gcc / g++ is installed by default on most Linux distros
- Mac: same deal as make - install Xcode command line tools
- Windows: recommend using MinGW
- OpenCV >= 4.1 https://opencv.org/
- create a
build
folder in the rootmandelbrot
folder cd build && cmake ..
make
./mandelbrot
The project consists of the following files:
main.cpp
- Interface between user and OpenCV. Created acv::Mat
for the image. Receives user's input for zooming in and out and setting the center point for zooming. Creates an instance ofMandelbrot
class and passes user's commands to it.mandelbrot.h
- Header file forMandelbrot
and some auxillary classes. Inspired by this blog post, theMandelbrot
class uses aWindow
class for managing the domain of the Mandelbrot set and the drawn image and conversion between image space (pixel coordinates) and current domain of Mandelbrot set. TheWindow
class also takes care of changing the domain of Mandelbrot set when zooming in and out.mandelbort.cpp
- Implementation ofMandelbrot
class. We use the simple escape time algorithm for drawing the image. The image (acv::Mat
instance) is separated into segments (as much as CPU cores (std::thread::hardware_concurrency()
)). TheMandelbrot:::draw()
method then uses threads to calculate number of iterations for each point and setting the corresponding pixel color in image segment.
- Clone this repo.
- Make a build directory in the top level directory:
mkdir build && cd build
- Compile:
cmake .. && make
- Run it:
./Capstone
. - Follow the instructions.
- View generated images in the
/build/
folder.