Advertisement
marko_rus

geoscan

Oct 19th, 2018
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.65 KB | None | 0 0
  1. local component = require("component")
  2.  
  3. if not component.isAvailable("geolyzer") then
  4.  
  5.   io.stderr:write("This program requires a Geolyzer to run.\n")
  6.  
  7.   return
  8.  
  9. end
  10.  
  11. if not component.isAvailable("hologram") then
  12.  
  13.   io.stderr:write("This program requires a Hologram Projector to run.\n")
  14.  
  15.   return
  16.  
  17. end
  18. local geolyzer =component.geolyzer
  19. local hologram =component.hologram
  20.  
  21. local sx, sz = 48, 48
  22.  
  23. local ox, oz = -24, -24
  24.  
  25. local starty, stopy = -5
  26.  
  27.  
  28.  
  29. local function validateY(value, min, max, default)
  30.  
  31.   value = tonumber(value) or default
  32.  
  33.   if value < min or value > max then
  34.  
  35.     io.stderr:write("invalid y coordinate, must be in [" .. min .. ", " .. max .. "]\n")
  36.  
  37.     os.exit(1)
  38.  
  39.   end
  40.  
  41.   return value
  42.  
  43. end
  44.  
  45.  
  46.  
  47. do
  48.  
  49.   local args = {...}
  50.  
  51.   starty = validateY(args[1], -32, 31, starty)
  52.  
  53.   stopy = validateY(args[2], starty, starty + 32, math.min(starty + 32, 31))
  54.  
  55. end
  56.  
  57.  
  58.  
  59. hologram.clear()
  60.  
  61. for x=ox,sx+ox do
  62.  
  63.   for z=oz,sz+oz do
  64.  
  65.     local hx, hz = 1 + x - ox, 1 + z - oz
  66.  
  67.     local column = geolyzer.scan(x, z, false)
  68.  
  69.     for y=1,1+stopy-starty do
  70.  
  71.       local color = 0
  72.  
  73.       if column then
  74.  
  75.         local hardness = column[y + starty + 32]
  76.  
  77.         if hardness == 0 or not hardness then
  78.  
  79.           color = 0
  80.  
  81.         elseif hardness < 3 then
  82.  
  83.           color = 2
  84.  
  85.         elseif hardness < 100 then
  86.  
  87.           color = 1
  88.  
  89.         else
  90.  
  91.           color = 3
  92.  
  93.         end
  94.  
  95.       end
  96.  
  97.       if hologram.maxDepth() > 1 then
  98.  
  99.         hologram.set(hx, y, hz, color)
  100.  
  101.       else
  102.  
  103.         hologram.set(hx, y, hz, math.min(color, 1))
  104.  
  105.       end
  106.  
  107.     end
  108.  
  109.     os.sleep(0)
  110.  
  111.   end
  112.  
  113. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement