SHARE
TWEET

inflate_heightmap

rerere284 Apr 14th, 2016 122 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --made by rerere284
  2. function init()
  3.     setName("Inflate Heightmap")
  4.     setDesc("Makes a Heightmap be inflated, and textured with Surface.")
  5.     setSize(100, 24+64+8+8+18+18+7+4)
  6.     addOutput(24+32)
  7.     addInput("Surface", 24+64+8+8)
  8.     addInput("Heightmap", 24+64+8+8+18)
  9.     addParameter("Loop", "Set whether it loops off the top of the screen or not", 24+64+8+8+18+18, 1, 0, 1)
  10. end
  11.  
  12.  
  13.  
  14. function apply()
  15.     tileSize = getTileSize()
  16.    
  17.     layers = {} --onion
  18.     numlayers = 0
  19.     loop = getValue(2, 0, 0, 1)
  20.    
  21.     --go through each pixel
  22.     for i=0, tileSize*tileSize-1 do
  23.         x = i%tileSize
  24.         y = math.floor(i/tileSize)
  25.         rr, rg, rb = getValue(0, x, y, 1) --get pixels at that location for both
  26.         hr, hg, hb = getValue(1, x, y, 1)
  27.         h = ((hr+hg+hb)/3) * (tileSize/2)
  28.         --for each layer in a column at that pixel of height h
  29.         for j=0,math.max(h,0) do
  30.             layer = math.ceil(((tileSize-y)+j) / tileSize)-1
  31.             --for all layers up to your layer
  32.             for k=numlayers,layer do
  33.                 --make that layer if it isn't there
  34.                 if layers[k] == nil then
  35.                     layers[k] = {}
  36.                     numlayers = k
  37.                 end
  38.             end
  39.             --set the pixel at that layer to the first input at the current position
  40.             --if loop == 1 then
  41.                 layers[layer][(((tileSize-y)+j-(tileSize*layer)-1) * tileSize)+x] = {rr,rg,rb}
  42.             --else
  43.                 --layers[layer][(((tileSize-y)+j-1) * tileSize)+x] = {rr,rg,rb}
  44.             --end
  45.         end
  46.     end
  47.    
  48.     if loop == 0 then numlayers = 0 end
  49.    
  50.     for j=0,numlayers do
  51.         if layers[j] ~= nil then
  52.            
  53.             for i=0, tileSize*tileSize-1 do
  54.                 if layers[j][i] ~= nil then
  55.                    
  56.                     x = i%tileSize
  57.                     y = math.floor(i/tileSize)
  58.                     fr = layers[j][i][1]
  59.                     fg = layers[j][i][2]
  60.                     fb = layers[j][i][3]
  61.                     setPixel(0, x, tileSize-y, fr, fg, fb)
  62.                    
  63.                 end
  64.             end
  65.            
  66.         end
  67.     end
  68.    
  69. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top