Code archives/Algorithms/Create 2D terrains
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Creates a nice 2D terrain. In my oppinion, perect random landscapes | |||||
Graphics 1024,768,32,1 Repeat SetBuffer BackBuffer() Cls CreateMap(GraphicsWidth(),GraphicsHeight()) Flip WaitKey() Until KeyDown(1)=True Function CreateMap(width,height) y2=height y1=(height-100)/2+Rand(50,300) For x=0 To width SeedRnd MilliSecs() y1=y1+Cos(x)*Rand(-(Sin(x)*Rand(5)),(Sin(x)*Rand(5))) If y1>y2 Then y1=y2 If y1<(height-150)/3 Then y1=(height-150)/3 Plot x,y1 Next End Function |
Comments
| ||
Thank you! This has surely helped me! I have made an edit to the code at: http://www.blitzbasic.com/codearcs/codearcs.php?code=1339 Hope you dont mind. |
| ||
And the simple filled terrain edition. Simply replace Plot x,y1 with Line x,y1,x+1,GraphicsHeight() |
Code Archives Forum