Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / 1D midpoint displacement example

Author
Message
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 26th May 2006 06:11
Demonstrates the midpoint displacement algorithm in 1 dimension(X) by drawing a ridge line of mountains.


"space bar" creates a new random ridge line.
"s" will smooth the current line on the screen
"esc" quits


"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 26th May 2006 09:39
That is so cool, can you make it so the edges will be seamless with a slight curve?
and this is a quick post before i examine the code, can we find the lets say height of an x coordinate?

Too Sexy
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 26th May 2006 15:31 Edited at: 26th May 2006 15:35
yea, just determine which 2 points 'X' is between. If you don't know which points, then use 1 and numOfPts to recursively find it. Since the points are technically sorted by 'X', we can use a binary chop method; which is very fast, even with thousands of points to search. It's because the number of entries to check is cut in half at each pass. Probably the best method for when working with sorted data.


If you want the edges to meet, the I'd suggest making them the same height. Take the height of the 2 edges, average them, then set that as the height for each.

Move your mouse on the X-axis to see the circle trace over the line at the proper height.



"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 26th May 2006 16:28
awesome,
just the circle glitches sometimes when you move the mouse but awesome.

Too Sexy

Login to post a reply

Server time is: 2024-11-23 03:20:04
Your offset time is: 2024-11-23 03:20:04