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 |