Ooops
October 28, 2021, 11:31:51

Author Topic: [bb] Terrain Colormap Generator by Chroma [ 1+ years ago ]  (Read 556 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Terrain Colormap Generator
Author : Chroma
Posted : 1+ years ago

Description : This will cycle thru a heightmap and take the RGB value and average them to a single value which can then be used to color different "heights".  I got some pretty cool results with the current settings and it looks ok textured onto a terrain with a lightmap.  Change the colors around to your liking.  Could be used for weird terrain effects.

Code :
Code: BlitzBasic
  1. ;-Terrain Texture Generator-;
  2. ;-by Chroma-;
  3.  
  4. Graphics 800,600,16,2
  5. SetBuffer BackBuffer()
  6.  
  7. map=LoadImage("hmap2.bmp")
  8.  
  9. mapWidth = ImageWidth(map)
  10. mapHeight = ImageHeight(map)
  11.  
  12. DrawBlock map,0,0
  13.  
  14. ;-Open a Text File-;
  15. myfile=WriteFile("text.txt")
  16.  
  17. ;-----------------------;
  18. ;-Read Map Pixel Values-;
  19. ;-----------------------;
  20. LockBuffer
  21. For y=0 To mapHeight
  22.     For x=0 To mapWidth
  23.         rgb = ReadPixelFast(x,y) And $FFFFFF
  24.         WriteInt myfile,rgb
  25.     Next    
  26. Next
  27. UnlockBuffer
  28. ;-----------------------;
  29. CloseFile myfile
  30.  
  31.  
  32. ;-Open the test map-;
  33. myfile=ReadFile("text.txt")
  34.  
  35. ;-Now let's reconstruct the picture
  36. For y=0 To mapHeight
  37.     For x=0+300 To mapWidth+300
  38.         rgb=ReadInt(myfile)
  39.         r = rgb Shr 16 And %11111111
  40.         g = rgb Shr 8 And %11111111
  41.         b = rgb And %11111111
  42.         ;Average out the value
  43.         bw=(r+g+b)/3
  44.         ;-Discern between the 4 terrain types-;
  45.         ;Region1(Snow) : 256-192
  46.         If bw=>192 Then r=255:g=255:b=255
  47.         ;Region2(Rock) : 192-128
  48.         If bw<192 And bw=>128 Then r=100:g=100:b=100
  49.         ;Region3(Grass): 128-64
  50.         If bw<128 And bw=>64 Then r=100:g=200:b=100
  51.         ;Region4(Sand) : 64-0
  52.         If bw<64 r=100:g=50:b=50
  53.         ;Throw out some color for testing    
  54.         Color r,g,b
  55.         Plot x,y
  56.     Next    
  57. Next
  58.  
  59. CloseFile myfile
  60.  
  61.  
  62. ;MainLoops
  63. While Not KeyHit(1)
  64.  
  65. Text 10,300,"Terrain Texture Generator"
  66.  
  67.  
  68. Flip
  69. Wend
  70. End


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal