Sierpinski Triangle C++ Code
If you like pretty pictures, and I know you do, below is a plot of Sierpinski’s Triangle which you can generate with the short C++ program I wrote. This is an example of a fractal–an object that is self similar at all levels of magnification.
On a Linux/UNIX system, to compile and run the code type:
$ g++ sierpinski.cc -o sierpinski $ ./sierpinski >out Enter depth (integer > 0, usually 10 is good): 10 Enter contraction mapping constant (for example 0.5): 0.5 $
Now the points are stored in a file called ‘out’. To plot them you can use gnuplot like so:
$ gnuplot gnuplot> plot 'out' with points pointtype 0


I see that you are using Gnuplot, so I thought you might be interested to know that there is now a book on it: “Gnuplot in Action”. You can pre-order it directly from the publisher: Manning: Gnuplot in Action.
If you want to learn more about the book and the author, check out my book page at Principal Value – Gnuplot in Action.
Let me know if you are interested in a review copy.
Philipp K. Janert
March 19, 2008 at 8:30 pm
very nice work!
Iannis
April 9, 2008 at 2:00 pm
Thanks!,
Xqlomgsl
December 13, 2008 at 9:23 am