Qbasicnews.com

Full Version: Terrain Gen
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Well, I was thinking back to that fad about terrain generators a while ago on Qbasic.com, etc and decided to make my own

Code:
DECLARE SUB writepal (red!, grn!, blu!, palp!)
RANDOMIZE TIMER
SCREEN 13
sizex = 120
sizey = 70
FOR i = 1 TO 8
writepal 0, 0, 60, i
NEXT
FOR i = 8 TO 12
r = r + 60 / 4
g = g + 50 / 4
B = B - 60 / 4
writepal r, g, B, i
NEXT
FOR i = 12 TO 30
writepal 60, 50, 0, i
NEXT
r = 60
g = 50
FOR i = 30 TO 64
r = r - 40 / 34
g = g - 40 / 34
writepal r, g, 0, i
NEXT
r = 20
g = 10
FOR i = 64 TO 192
r = r - 20 / 128
g = g + 50 / 128
writepal r, g, 0, i
NEXT
r = 0
g = 60
B = 0
FOR i = 192 TO 255
r = r + 45 / 64
g = g - 15 / 64
B = B + 45 / 64
writepal r, g, B, i
NEXT
DIM buffer(sizex, sizey)

FOR x = 1 TO sizex
  FOR y = 1 TO sizey
    buffer(x, y) = 1
  NEXT
NEXT
FOR i = 1 TO 130
  posx = INT(RND * sizex) + 1
  posy = INT(RND * sizey) + 1
  height = INT(RND * 350) + 1
  FOR j = 1 TO 90
    posx2 = (INT(RND * 10) - 5) + posx
    posy2 = (INT(RND * 10) - 5) + posy
    IF posx2 > 1 AND posx2 < sizex AND posy2 > 1 AND posy2 < sizey THEN buffer(posx2, posy2) = height
  NEXT
NEXT
LOCATE 1, 24: PRINT "]"
FOR smth = 1 TO 4
  FOR x = 1 TO sizex - 1
    FOR y = 1 TO sizey - 1
      av = 0
      av = av + buffer(x - 1, y - 1)
      av = av + buffer(x + 1, y - 1)
      av = av + buffer(x - 1, y + 1)
      av = av + buffer(x + 1, y + 1)
      av = av + buffer(x, y)
      av = av / 5
      IF av > 255 THEN av = 255
      IF av < 1 THEN av = 1
      buffer(x, y) = av
    NEXT
    LOCATE 1, 1
    a = a + 1
    PRINT "Generating: [" + STRING$((a / ((sizex - 1) * 4)) * 10, "þ")
  NEXT
NEXT
CLS
FOR x = sizex - 1 TO 1 STEP -1
  FOR y = 10 TO sizey + 9
    'PSET (x, y), buffer(x, y - 10)
    LINE (x * 2 - 2 + y, y * 2 - 2)-(x * 2 + y, y * 2 - buffer(x, y - 10) / 8), buffer(x, y - 10), BF
  NEXT
NEXT
END
FOR x = sizex - 1 TO 2 STEP -2
  FOR y = 12 TO sizey + 9 STEP 2
     LINE (x * 2 + y, y * 2 - buffer(x, y - 10) / 8)-((x - 2) * 2 + y, y * 2 - buffer(x - 2, y - 10) / 8), buffer(x, y - 10)
     LINE (x * 2 + y, y * 2 - buffer(x, y - 10) / 8)-(x * 2 + (y - 2), (y - 2) * 2 - buffer(x, y - 12) / 8), buffer(x, y - 10)
  NEXT
NEXT

SUB writepal (red, grn, blu, palp)
  OUT &H3C8, palp
  OUT &H3C9, red
  OUT &H3C9, grn
  OUT &H3C9, blu
END SUB
Cool work! Now make a map engine that will generate maps for your terrain - then of course a map loading engine...
This could go somewhere. Smile
Dark, how did you do to make it THAT FAST ?

I thought this kind of generators could only live with look-up tables...


As for landscapes generation, TC-Land is one of my next project... I'll try to do do with terrain generation what I've done with raytracing.

Antoni has emailed me a while ago the terrain generator of Entropy, I can post that if you wish. It's impressive...

As for me, that's what I managed to do one year ago:

[Image: BayHR.jpg]
[Image: Land.jpg]

You can download the prog that I used on this page:
http://mandelbrot.dazibao.free.fr/Perlin/Qbground.bas

but be careful: this prog is horrible, that's why I want to make TC-Land, that will look more like this:
[Image: Rayfract.jpg]
This picture uses the original Ken Perlin algorithm, it gives real nice results for clouds, mountains should be nice also.
Hehe, wow. Nice work everyone.

I played with Entropy's terrain generator too..

I made a map generator myself, and it does local convergence too, but with a bit of a different formula: it converges into 2D islands, like a cow's hide.
WOW! Thats awesome Jark!
You could make one hell of a Populous type game with that.
I think I'll scrap my land generator now... :rotfl:
My progs are unfortunately far too slow for games Cry

But they can give ideas :wink:
Heh, thanks guys.

Jark: Im not really sure why you would expect it to be slow, as the generator only uses a simple type of smoothing to generate heights, and the colours are obviously based on heights. Btw, I love your terrain generator!! It is beautiful!

Zack: Im not really sure what you mean by a map engine that will generate maps for the terrain? but what would be cool is if I could somehow change the engine to allow walking around. It would be way cool to be able to walk around a landscape like that and walk across the beaches and everything =D
Dark, just try to generate a terrain with my prog: then you'll see I why I call it slow... It's SVGA, hires stuff... :wink: