Implement Diamiond Square fractal?
Go to www.gameprogrammer.com and find his fractal tutorial
"We are the music makers, and we are the dreamers of the dreams."
- Willy Wonka
"We are the music makers, and we are the dreamers of the dreams."
- Willy Wonka
tried that, but he doesn''t have any ideas on how to implement the code, just code and a explnation of what one needs to do.
I''d rather not just copy his code..
I''d rather not just copy his code..
Well, I''d do it recursively. If you''re familiar with recursion I imagine you can see how it would work.
Just some example pseudo-code:
function midpoint (point a, point b, point c, point d)
// this is so we don''t keep endless sub-dividing
if a - b < threshold then
return
end if
calculate midpoints ab, bc, cd, ad, center point.
offset by random amount
// call midpoint on each of the four squares that make up
// the original square.
midpoint (a, ab, center point, ad)
midpoint (ab, b, bc, center point)
midpoint (center point, bc, c, cd)
midpoint (ad, center point, cd, d)
end midpoint
Forgive me if this isn''t the same algo described on gameprogrammer.com... From what I remember it is, or at least is very similar..
The idea of this algo is to start with a start, find its midpoint and randomly displace it. Then, do the same for each of the four squares that is created by the center point.
ie:
a------ab----b
| | |
| | |
ad-----cp----bc
| | |
| | |
d-----cd-----c
cp = center point.
Wrestle with this in your mind, it should become clear.
--------------------------
I guess this is where most people put a famous quote...
"Everything is funnier with monkey''''s" - Unknown
Just some example pseudo-code:
function midpoint (point a, point b, point c, point d)
// this is so we don''t keep endless sub-dividing
if a - b < threshold then
return
end if
calculate midpoints ab, bc, cd, ad, center point.
offset by random amount
// call midpoint on each of the four squares that make up
// the original square.
midpoint (a, ab, center point, ad)
midpoint (ab, b, bc, center point)
midpoint (center point, bc, c, cd)
midpoint (ad, center point, cd, d)
end midpoint
Forgive me if this isn''t the same algo described on gameprogrammer.com... From what I remember it is, or at least is very similar..
The idea of this algo is to start with a start, find its midpoint and randomly displace it. Then, do the same for each of the four squares that is created by the center point.
ie:
a------ab----b
| | |
| | |
ad-----cp----bc
| | |
| | |
d-----cd-----c
cp = center point.
Wrestle with this in your mind, it should become clear.
--------------------------
I guess this is where most people put a famous quote...
"Everything is funnier with monkey''''s" - Unknown
--------------------------I guess this is where most people put a famous quote..."Everything is funnier with monkey''s" - Unknown
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement