We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

an iteration involves drawing a triangle with two newer triangles underneath it.

____1_______111_____1***1___111*111_

also, the two new triangles underneath are separated by an inverted triangle of the same size (represented in * above)

so my plan was to write a function that: recursively draws a triangle of height h and recursively draws two further triangles of height h underneath it, seperating the two lower triangles with an inverted triangle

NB the innerPad function, takes the two triangles, inverts one of them and replaces the 1s with underscores then intercalated each row into the two triangles:

so

[["1","1"],["111","111"],["11111","11111"]]

generates

["_____","___","_"]

finally giving

["1_____1","111___111","11111_11111"]

Then the things left to do are: determine triangle heights by dividing the canvas with by 2 to the power of the iteration.

Pad out the elements of the generated lists to fill the width of the canvase

## Functions and Fractals: Sierpinski triangles

You are viewing a single comment's thread. Return to all comments →

if this helps anyone, my approach was:

assume that a base triangle with no iteration.

I draw my triangles via a list of strings in the form

etc I will later pad these elements out to be the length of the width of the canvas ie

an iteration involves drawing a triangle with two newer triangles underneath it.

also, the two new triangles underneath are separated by an inverted triangle of the same size (represented in * above)

so my plan was to write a function that: recursively draws a triangle of height h and recursively draws two further triangles of height h underneath it, seperating the two lower triangles with an inverted triangle

NB the innerPad function, takes the two triangles, inverts one of them and replaces the 1s with underscores then intercalated each row into the two triangles:

so

generates

finally giving

Then the things left to do are: determine triangle heights by dividing the canvas with by 2 to the power of the iteration.

Pad out the elements of the generated lists to fill the width of the canvase