Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Totoro Model Holographics
- local event = require('event')
- local component = require('component')
- local args = { ... }
- if #args == 0 then
- print("Usage: holo <filename>")
- return
- end
- print("Loading...")
- local holo = component.hologram
- holo.setScale(4)
- holo.clear()
- color = {}
- color[1] = 0xFFFFFF -- white
- color[2] = 0xFFA500 -- orange
- color[3] = 0xFF00EE -- fuchsia
- color[4] = 0x1BA1E2 -- light blue
- color[5] = 0xFFFF00 -- yellow
- color[6] = 0x00FF00 -- light green
- color[7] = 0xF472D0 -- pink
- color[8] = 0x808080 -- gray
- color[9] = 0xC0C0C0 -- light gray
- color[10] = 0x00A0A0 -- teal
- color[11] = 0xAA00FF -- violet
- color[12] = 0x0000FF -- blue
- color[13] = 0x825A2C -- brown
- color[14] = 0x008A00 -- green
- color[15] = 0xFF0000 -- red
- color[16] = 0xFFFFFF -- black
- -- load image
- function load(filename)
- local model = {palette={}}
- local file = io.open(filename..".txt", "r")
- local palnum = 1
- print("Loading '"..filename.."' model...")
- for x=1, 32 do
- model[x] = {}
- for y=1, 48 do
- model[x][y] = {}
- for z=1, 48 do
- local i = string.byte(file:read(1))-48
- if i ~= 0 then
- 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
- model[x][y][z] = model.palette[i+10]
- else
- model[x][y][z] = 0
- end
- end
- end
- -- to avoid "too long without yielding" error
- os.sleep(0.01)
- end
- file:close()
- for i=1, 3 do
- if model.palette[i] == nil then model.palette[i] = 2 end
- end
- return model
- end
- function draw(model, angle)
- for x=1, 32 do
- for y=1, 48 do
- for z=1, 48 do
- if model[x][y][z] ~= 0 then
- 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])
- end
- end
- end
- end
- end
- model = load(args[1])
- for i=1, 3 do
- holo.setPaletteColor(i, color[model.palette[i]])
- end
- print("Done.")
- angle = 0
- while true do
- name, address = event.pull(0.01)
- if name == "key_down" then break end
- holo.clear()
- draw(model, angle)
- os.sleep(2)
- angle = math.random(0, math.pi*2) --(angle + math.pi/12)%(math.pi*2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement