SHARE
TWEET

Totoro Model Holographics

MoonlightOwl Jul 18th, 2014 1,095 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Totoro Model Holographics
  2. local event = require('event')
  3. local component = require('component')
  4.  
  5. local args = { ... }
  6.  
  7. if #args == 0  then
  8.   print("Usage: holo <filename>")
  9.   return
  10. end
  11.  
  12. print("Loading...")
  13.  
  14. local holo = component.hologram
  15. holo.setScale(4)
  16. holo.clear()
  17.  
  18. color = {}
  19. color[1] = 0xFFFFFF  -- white
  20. color[2] = 0xFFA500  -- orange
  21. color[3] = 0xFF00EE  -- fuchsia
  22. color[4] = 0x1BA1E2  -- light blue
  23. color[5] = 0xFFFF00  -- yellow
  24. color[6] = 0x00FF00  -- light green
  25. color[7] = 0xF472D0  -- pink
  26. color[8] = 0x808080  -- gray
  27. color[9] = 0xC0C0C0  -- light gray
  28. color[10] = 0x00A0A0 -- teal
  29. color[11] = 0xAA00FF -- violet
  30. color[12] = 0x0000FF -- blue
  31. color[13] = 0x825A2C -- brown
  32. color[14] = 0x008A00 -- green
  33. color[15] = 0xFF0000 -- red
  34. color[16] = 0xFFFFFF -- black
  35.  
  36. -- load image
  37. function load(filename)
  38.   local model = {palette={}}
  39.   local file = io.open(filename..".txt", "r")
  40.   local palnum = 1
  41.   print("Loading '"..filename.."' model...")
  42.   for x=1, 32 do
  43.     model[x] = {}
  44.     for y=1, 48 do
  45.         model[x][y] = {}
  46.       for z=1, 48 do
  47.         local i = string.byte(file:read(1))-48
  48.         if i ~= 0 then
  49.           if model.palette[i+10] == nil then model.palette[i+10] = palnum; model.palette[palnum] = i; print("New color: "..i.."("..palnum..")"); palnum = palnum%3+1; end
  50.           model[x][y][z] = model.palette[i+10]
  51.         else
  52.           model[x][y][z] = 0
  53.         end
  54.       end
  55.     end
  56.     -- to avoid "too long without yielding" error
  57.     os.sleep(0.01)
  58.   end
  59.   file:close()
  60.   for i=1, 3 do
  61.     if model.palette[i] == nil then model.palette[i] = 2 end
  62.   end
  63.   return model
  64. end
  65.  
  66. function draw(model, angle)
  67.   for x=1, 32 do
  68.     for y=1, 48 do
  69.       for z=1, 48 do
  70.         if model[x][y][z] ~= 0 then
  71.                 holo.set(24 + (y - 24) * math.cos(angle) - (z - 24) * math.sin(angle), x, 24 + (z - 24) * math.cos(angle) + (y - 24) * math.sin(angle), model[x][y][z])
  72.         end
  73.       end
  74.     end
  75.   end
  76. end
  77.  
  78. model = load(args[1])
  79. for i=1, 3 do
  80.   holo.setPaletteColor(i, color[model.palette[i]])
  81. end
  82. print("Done.")
  83. angle = 0
  84.  
  85. while true do
  86.   name, address = event.pull(0.01)
  87.   if name == "key_down" then break end
  88.  
  89.   holo.clear()
  90.   draw(model, angle)
  91.   os.sleep(2)
  92.   angle = math.random(0, math.pi*2) --(angle + math.pi/12)%(math.pi*2)
  93. 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