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.

The 20 Line Challenge / [DBP]Terrain Generator

Author
Message
Lewis999
7
Years of Service
User Offline
Joined: 23rd Oct 2010
Location:
Posted: 5th May 2012 16:55
Time for a more serious submission ^^
+ Code Snippet
The longest line has exactly 25 commands
Anyway, it's based of something I posted in the code snippets forum a while ago, with some modifications.
chafari
Valued Member
11
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 5th May 2012 23:57
Quote: "The longest line has exactly 25 commands "

Yeah friend !! I thought that it ends around Australia .
Nice terraing...you use your own perling noise to generate the terrain. You could apply the same to an Advanced terrain as matrix use to slow down PCs, but good work .

Cheers.

I'm not a grumpy grandpa
Lewis999
7
Years of Service
User Offline
Joined: 23rd Oct 2010
Location:
Posted: 6th May 2012 21:15 Edited at: 7th May 2012 01:04
Quote: "Yeah friend !! I thought that it ends around Australia .
Nice terraing...you use your own perling noise to generate the terrain. You could apply the same to an Advanced terrain as matrix use to slow down PCs, but good work .

Cheers."


Thanks ^^

The algorithm is roughly based on the diamond-square algorithm, with some small modifications.

As far as making it faster on slow computers, I also made a memblock version, that generates the terrain in almost the same way. It's a lot faster but I couldn't get it into 20 lines if I tried :p

I'm going to quickly modify it(the code posted above) to export to a bitmap and see what it looks like

edit:
export_bitmap function:
+ Code Snippet

The full, uncompressed code:
+ Code Snippet(when the program runs, it saves a (compressed) heightmap called "test.bmp" in the same directory as the exe)

Right, so it's similar to perlin noise, but it has the same flaw as the diamond-square algorithm, there are sometimes seams in the heightmap. ^^
Also, because some of the positions in the matrix are higher than 255, and some are lower than 0, the values need to be compressed, so a lot of detail is lost in the heightmap.
(one of the heightmaps is attached)

Attachments

Login to view attachments
chafari
Valued Member
11
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 7th May 2012 01:55
Its a huge bitmap..ha ha as big as Australia !!

Quote: "there are sometimes seams in the heightmap"


Yeah I know what you mean...some time ago, I made my own terrain generator, and I wanted to export the heightmap and I had to check for the lowest point the the whole matrix (terrain) and the highest point and then taking the average of the two heights for generating the bitmap. Its a good job...perhaps for a 20 lines challenge we need a smaller map, to fit the code in just 20 lines

Cheers.

I'm not a grumpy grandpa
Lewis999
7
Years of Service
User Offline
Joined: 23rd Oct 2010
Location:
Posted: 7th May 2012 10:54 Edited at: 7th May 2012 10:54
Done

This generates a 512*512 terrain end exports the heightmap as "test.bmp" Unfortunately it's limited to 512*512, the other one was unlimited :p
+ Code Snippet
chafari
Valued Member
11
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 7th May 2012 12:47
Yeah 512*512 is more than enough unless we want to make a extremly realistic landscape ..good job ...I'll keep it

Cheers.

I'm not a grumpy grandpa
jobromedia
5
Years of Service
User Offline
Joined: 9th May 2012
Location: Stockholm, Sweden
Posted: 12th May 2012 12:11
That's not bad at all! Congrats.

Best regards
Johan Brodd

Login to post a reply

Server time is: 2018-01-23 01:52:36
Your offset time is: 2018-01-23 01:52:36