gd-codes / dragoncurve

Generating and drawing the Dragon Curve fractal, in C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dragoncurve

The Dragon Curve fractal is formed by beginning with a line segment, and recursively rotating or "unfolding" it to create a copy of the shape angled 90° to the previous one, as illustrated in the wikipedia link.

Files

This repo has a collection of individual scripts written in C++11, using the SFML library for GUI, to recursively generate and draw this fractal.

The shape is kept track of using an std::vector<bool> which represents the sequence of turn directions (Left/Right) for each rotation / corner of the linear path. Iterators over this vector keep looping over it and appending bits at the end to continually keep generating the next order (recursive stage) of the curve.

dc2 draws the Regular Dragon Curve, dc3 the Terdragon (variant with 2 unfolds / rotations of angle 120° in each recursive step, instead of just 1 of angle 90°). dc2_mt and dc3_mt generate the curve in a separate thread from the GUI, which causes it to finish much faster (the "drawing" of the curve is barely visible & finishes in a few frames)

Compiling and Running

Steps to install SFML, build it (with makefile / from source), and link this code to the binaries are available on the SFML website (Links : Download page | Installation & Usage tutorials on various platforms | Using g++ on *nix)

About

Generating and drawing the Dragon Curve fractal, in C++


Languages

Language:C++ 100.0%