Advertisement
billysback

visual

Jan 4th, 2013
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.70 KB | None | 0 0
  1. local function getCol(char)
  2.     local convert = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!£$%^&*()_+-=[];'#,/<>?:@~{}|\\`¬"..'"'.."%."
  3.     local index = 1
  4.     for i=1,string.len(convert) do if convert:sub(i, i) == char then index = i end end
  5.     local oind = index
  6.     while index > 16 do index = index - 16 end
  7.     if index <= 0 then index = 1 end
  8.     if index < 1 then index = 1 elseif index > 16 then index = 16 end
  9.     return 2 ^ (index-1), oind
  10. end
  11. local function visualData(data)
  12.     local tempdat = data
  13.     local cols = {}
  14.     local cur = 1
  15.     local dif = 1
  16.     while string.len(tempdat) > 0 do
  17.         local unused, index = getCol(tempdat:sub(cur, cur))
  18.         local col, ind = getCol(tempdat:sub(index, index))
  19.         cols[#cols + 1] = col
  20.         local bef = tempdat:sub(1, index-1)
  21.         local aft = tempdat:sub(index+1, -1)
  22.         if bef ~= nil then tempdat = bef else tempdat = "" end
  23.         if aft ~= nil then tempdat = tempdat..aft end
  24.         if cur >= string.len(tempdat) then
  25.             cur = string.len(tempdat)
  26.             dir = -1
  27.         elseif cur <= 0 then
  28.             cur = 1
  29.             dir = 1
  30.         end
  31.         cur = cur + dif
  32.     end
  33.     local w,h = term.getSize()
  34.     local curn = 1
  35.     local tick = 1
  36.     for x=1,w do
  37.         for y=1,h do
  38.             local n, unused = getCol(data:sub(curn, curn))
  39.             local xy = x + y + n
  40.             while xy > #cols do xy = xy - #cols end
  41.             if xy <= 0 then xy = 1 end
  42.             local col = cols[xy]
  43.             term.setCursorPos(x, y)
  44.             term.setBackgroundColor(col)
  45.             term.write(" ")
  46.             curn = curn + 1
  47.             if curn > string.len(data) then curn = 1 end
  48.             tick = tick + 1
  49.             if tick > 50 then
  50.                 tick = 0
  51.                 sleep(0)
  52.             end
  53.         end
  54.     end
  55. end
  56. local stuff = {...}
  57. local dat = ""
  58. for i=1,#stuff do if dat == "" then dat = stuff[i] else dat = dat.." "..stuff[i] end end
  59. visualData(dat)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement