Page 1 of 1

Landscape Generator

Posted: Fri Mar 20, 2015 6:20 am
by DrChip

Code: Select all

REM Landscape Generator
REM iPhone 6 plus / 8.3 b3
REM Enjoy...


init:
graphics
graphics clear 0,0,0
sw=screen_width()
sh=screen_height()



Landscape:

draw = 0
draw color 0,0,0
graphics clear 0,0,0


REM Data
lWidth = rnd(50)+60
lHeight = rnd(50)+60
scaleX = rnd(5)+2
scaleY = rnd(3)+2
nrHotspots = rnd(450)+100
originalHeight = rnd(200)+100
XAngle = rnd(110)-55
smoothing = rnd(13)+5

dim l(lWidth+1,lHeight+1)
REM ---Prints landscape information---
draw color 1,1,200/255
draw text  "Landscape data" at 10,10
draw text  "-----------------------" at 10,20
draw text  "Width: " & str$(lWidth) at 10,40
draw text  "Height: " & str$(lHeight) at 10,60
draw text  "ScaleX: " & str$(scaleX) at 10,80
draw text  "ScaleY: " & str$(scaleY) at 10,100
draw text  "Hotspots: " & str$(nrHotspots) at 10,120
draw text  "Hotspot height: " & str$(originalHeight) at 10,140
draw text  "XAngle: " & str$(XAngle) at 10,160
draw text  "Smoothing: " & str$(smoothing) at 10,180

draw color 1,1,1
draw text "Generating hotspots......." at 10,250
REM ---Generate Hotspots---

for i=1 to nrHotspots
  x = rnd(lWidth-8)+4
  y = rnd(lHeight-8)+4
  l(x,y) = originalHeight
  procentDone = (i/nrHotspots)*100
next i 
fill color 0,0,0
fill rect 10,230 to sw,270
draw color 1,1,1
draw text "Generating hotspots.......100% completed" at 10,250



startDrawX = sw/2-((lWidth*scaleX)/2)-(XAngle*1.5)
startDrawY = sh/2-((lHeight*scaleY)/2)

procentDone = 0

draw color 1,1,1
draw text "Smoothing.......loading" at 10,270

for i=1 to smoothing
 for y = 1 to lHeight-1
  for x = 1 to lWidth-1
   l(x,y) = (l(x+1,y)+l(x+1,y+1)+l(x,y+1)+l(x-1,y+1)+l(x-1,y)+l(x-1,y-1)+l(x,y-1)+l(x+1,y+1))*0.125
  next x
 next y
 procentDone = (i/smoothing)*100
 fill color 0,0,1
 fill rect 0,sh-20 to sw,sh
 draw color 1,1,1
 draw text "Smoothing......." & str$(procentDone) & "% " at 10,sh-20
next i

fill color 0,0,1
fill rect 0,sh-20 to sw,sh
draw color 1,1,1
draw text "Smoothing.......100%" at 10,sh-20

REM Let's Draw the landscape
fill color 0,0,110/255
fill rect 0,0 to sw,sh
incXAngle = XAngle/lHeight

for y = 1 to lHeight-1
 for x = 1 to lWidth-1
   x1 = startDrawX+x*scaleX+XAngle
   y1 = startDrawY+y*scaleY
   x2 = x1+scaleX
   y2 = y1+scaleY-(l(x,y)*3)
   if l(x,y) >= 50 then
    fill color (l(x,y)+50)/255,(l(x,y)+50)/255,(l(x,y)+50)/255
    fill rect x1,y1 to x2,y2
   endif
   if l(x,y) < 50 and l(x,y) > 40 then
    fill color l(x,y)/255,l(x,y)/255,l(x,y)/255
    fill rect x1,y1 to x2,y2
   end if

   if l(x,y) <= 40 and l(x,y) > 6 then 
    fill color 0,(l(x,y)+30)/255,0
    fill rect x1,y1 to x2,y2
   endif
   if l(x,y) <= 6 then 
    fill color 0,(l(x,y)*10)/255,110/255
    fill rect x1,y1 to x2,y2
   endif
 next x
 XAngle=XAngle+incXAngle
next y
pause 5
goto Landscape

Re: Landscape Generator

Posted: Fri Mar 20, 2015 7:42 am
by Mr. Kibernetik
Good start for a game...