Here's my code, I wrote this in khan's processing JS because that's all I was able to work with at the time. (I.E. math class)

I'm not really sure how it works, and all other attempts to replicate it by me failed, as there are some really strange processingJS quirks I have yet to understand.

Here's the formula the program uses, put into pseudocode:

Code:
```for all x coords on screen for all y coords on screen set variable "Z" to 255 * floor((x^2 + y^2)/abs(x+y)) Set the pen color to a shade of gray, dependant on "Z". If "Z" is  >= 255 (pure white), set var "Z" to 255 draw a point at (x, y) end both for loops ```

I'm not sure about the code working exactly like this, as similar code morphed into TI-BASIC does not work.
Sorry if this makes no sense, it doesn't to me either...
_iPhoenix_ wrote:
Here's my code, I wrote this in khan's processing JS because that's all I was able to work with at the time. (I.E. math class)

I'm not really sure how it works, and all other attempts to replicate it by me failed, as there are some really strange processingJS quirks I have yet to understand.

Here's the formula the program uses, put into pseudocode:

Code:
```for all x coords on screen for all y coords on screen set variable "Z" to 255 * floor((x^2 + y^2)/abs(x+y)) Set the pen color to a shade of gray, dependant on "Z". If "Z" is  >= 255 (pure white), set var "Z" to 255 draw a point at (x, y) end both for loops ```

I'm not sure about the code working exactly like this, as similar code morphed into TI-BASIC does not work.
Sorry if this makes no sense, it doesn't to me either...

This is quite a simple algorithm, all it's doing is essentially taking pascal's triangle mod 2, which produces a Sierpinski sieve. The important part is the formula 255*floor((x^2 + y^2)/abs(x+y)) which just checks the value of pascal's triangle at x,y, and if it is odd or even. If it is odd, then don't set z to 255, if it is even, set z to 255. 255 is the color white, and you don't want dots where pascal's triangle evaluates at an even number. Then you just loop that across your entire drawing area, and boom! Sierpinski triangle!
Here is an algorithm implemented by Weregoose in 2013, which displays a Sierpinski triangle in ti-basic. This one I am quite curious to know how it works

Code:
```0 Repeat 0 .5(Ans+e^(.5iπint(3rand Pt-On(real(Ans),imag(Ans End```
mr womp womp wrote:
Here is an algorithm implemented by Weregoose in 2013, which displays a Sierpinski triangle in ti-basic. This one I am quite curious to know how it works

Code:
```0 Repeat 0 .5(Ans+e^(.5iπint(3rand Pt-On(real(Ans),imag(Ans End```

I might be able to put some insight into this.

From Wikipedia, here is a valid algorithm to generate the Sierpinski triangle:
1. Take 3 points in a plane to form a triangle, you need not draw it.
2. Randomly select any point inside the triangle and consider that your current position.
3. Randomly select any one of the 3 vertex points.
4. Move half the distance from your current position to the selected vertex.
5. Plot the current position.
6. Repeat from step 3.

And all of these steps are followed in the program, in this way:
1. The three points that make the vertices of the triangle, according to the program, are -1, i, and 1 (in the complex plane).
2. The point is selected as 0 (it can literally be anything, but this is less code ).
3. The selection of the vertex point is done with the e^() code. As you should recognize, e^iτ = 1, or more generally, e^iθ = cos(θ) + i*sin(θ). The result, then, is randomly either (after simplifying) e^(iτ/2), e^(iτ/4), or e^(0), which (as on the unit circle plotted on the complex plane) is either -1, i, or 1. Recognize these?
4. This is just the midpoint of the two positions (the generated vertex, and Ans).
5. Self-explanatory.
6. So is this (although not using While 1 is a bit weird).

Simple, once you go through it step by step.

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» All times are UTC - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum