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.

Sierpinski Triangle

On a Linux/UNIX system, to compile and run the code type:

$ g++ -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

3 thoughts on “Sierpinski Triangle C++ Code

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s