Page 1 of 1

Sierpinski's Gasket

Posted: Thu Oct 02, 2008 12:53 am
by Nexion
Image

Thought I'd show off some fractal goodness I made with LOVE.
The code is retardedly simple, I used the Chaos Game method.
(pick a point, and pick a corner of the triangle randomly, then draw a point 1/2 way between the two. with enough points picked, you see the Sierpinksi's Gasket

Re: Sierpinski's Gasket

Posted: Thu Oct 02, 2008 2:05 pm
by Nexion
Blegh, that old one looks friggin ugly. Here's a newer version that looks a LOT smoother.
Image

How would I check to make sure the points are within the base 3 triangle points? They're defined by 6 variables, topPointX/Y, leftPointX/Y, rightPointX/Y, each being the X and Y positions of the corners respectively.

Re: Sierpinski's Gasket

Posted: Thu Oct 02, 2008 6:52 pm
by Merkoth
A .love would be much cooler my friend. But it sure looks cool :)

Re: Sierpinski's Gasket

Posted: Sun Oct 05, 2008 10:01 pm
by muku
For your "point in triangle" problem, there are some simple algorithms; see e.g. here: http://www.blackpawn.com/texts/pointinpoly/default.html

However, since you only want to generate points within the triangle anyway, you can do the following:

set h := height of your triangle
for each point to be generated:
... set y = h * (1 - sqrt(1 - random(0,1))) -- this is the height of the new point within the triangle
... choose x uniformly from between the left and right slope at height y within the triangle
... use point (x, y)
end

(random(0,1) means a uniformly distributed random value between 0 and 1.)

This algorithm generates uniformly distributed points within the triangle, so you never have to discard any points.