Sierpinski's Gasket

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Nexion
Prole
Posts: 46
Joined: Fri Sep 05, 2008 1:40 pm

Sierpinski's Gasket

Post 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
User avatar
Nexion
Prole
Posts: 46
Joined: Fri Sep 05, 2008 1:40 pm

Re: Sierpinski's Gasket

Post 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.
User avatar
Merkoth
Party member
Posts: 186
Joined: Mon Feb 04, 2008 11:43 pm
Location: Buenos Aires, Argentina

Re: Sierpinski's Gasket

Post by Merkoth »

A .love would be much cooler my friend. But it sure looks cool :)
User avatar
muku
Prole
Posts: 18
Joined: Wed Aug 20, 2008 11:35 am

Re: Sierpinski's Gasket

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 184 guests