Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you would like a high-quality approximation of the Sierpinski triangle, you can use an approach called the <a href="http://en.wikipedia.org/wiki/Chaos_game" rel="noreferrer">chaos game</a>. The idea is as follows - pick three points that you wish to define as the vertices of the Sierpinski triangle and choose one of those points randomly. Then, repeat the following procedure as long as you'd like:</p> <ol> <li>Choose a random vertex of the trangle.</li> <li>Move from the current point to the halfway point between its current location and that vertex of the triangle.</li> <li>Plot a pixel at that point.</li> </ol> <p>As you can see <a href="http://en.wikipedia.org/wiki/File:Sierpinski_chaos_animated.gif" rel="noreferrer">at this animation</a>, this procedure will eventually trace out a high-resolution version of the triangle. If you'd like, you can multithread it to have multiple processes plotting pixels at once, which will end up drawing the triangle more quickly.</p> <p>Alternatively, if you just want to translate your recursive code into iterative code, one option would be to use a worklist approach. Maintain a stack (or queue) that contains a collection of records, each of which holds the vertices of the triangle and the number n. Initially put into this worklist the vertices of the main triangle and the fractal depth. Then:</p> <ul> <li>While the worklist is not empty: <ul> <li>Remove the first element from the worklist.</li> <li>If its n value is not zero: <ul> <li>Draw the triangle connecting the midpoints of the triangle.</li> <li>For each subtriangle, add that triangle with n-value n - 1 to the worklist.</li> </ul></li> </ul></li> </ul> <p>This essentially simulates the recursion iteratively.</p> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload