Sierpinski's Gasket
Sierpinski's Gasket
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
Blegh, that old one looks friggin ugly. Here's a newer version that looks a LOT smoother.
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.
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
A .love would be much cooler my friend. But it sure looks cool
Teh Blog -> http://cryodreams.com.ar
Re: Sierpinski's Gasket
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.
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.
Who is online
Users browsing this forum: Google [Bot] and 3 guests