Context Free Sierpinski Triangle Tutorial

Context Free site tutorial:
http://www.contextfreeart.org/mediawiki/index.php/Tutorials/Fractals

The generated image:
Sierpinski Triangle Fractal

Context Free Code:

startshape B

rule B {
TRIANGLE{}
B {s 0.5 y 0.288 b 0.1}
B {s 0.5 x -0.25 y -0.144 b 0.1}
B {s 0.5 x 0.25 y -0.144 b 0.1}
}

I would like to describe how to derive the values for the triangle shifts as you recursively descend. I will use the following diagram to show the values:
Serpinski Triangle Fractal Design

General description:
For each triangle we want to create three triangles that are scaled down by 50 percent and shifted to the corners of the current triangle. The top scaled triangle needs to be moved up by half of the distance between the center of the triangle and the top point. The bottom two have to be shifted down half the distance between the center and the bottom of the triangle and left and right by half the distance of the base, respectively. Everything is halved because we are scaling the entire shape by half.

Top Triangle:

B {s 0.5 y 0.288 b 0.1}

The distance between the center of the triangle to the top of the triangle is give by x/sqrt(3). The smaller triangle needs to be moved up by half of this magnitude x/2*sqrt(3). We begin with a triangle of length one so 1/2*sqrt(3) is 0.288.

Bottom Left and Right Triangles:

B {s 0.5 x -0.25 y -0.144 b 0.1}
B {s 0.5 x 0.25 y -0.144 b 0.1}

The bottom triangles have to be moved down by half of the distance between the center of the triangle and the bottom. From the diagram this distance is x/2*sqrt(3). Half of the value would be x/4*sqrt(3). Again the x is 1 because we are scaling down. Which gets us 1/4*sqrt(3) = 0.144. The left and right have to be moved left and right by half of the distance of the scaled triangle. So x/2 ==> x/4 ==> 1/4 ==> 0.25.

Advertisements
This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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