skypop

CC Number display

Aug 10th, 2018
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.54 KB | None | 0 0
  1. -- Numbers
  2. -- by SukaiPoppuGo
  3.  
  4. -- Pixel API Wizard
  5. os.loadAPI("/api/pixel.lua")
  6. if not pixel then
  7.     local confirm
  8.     repeat
  9.         print("Pixel API required")
  10.         print("pastebin get Fa9KJqS4 /api/pixel.lua")
  11.         print("Download ? Y/N")
  12.         confirm = string.lower(read())
  13.         if confirm ~= "y" and confirm ~= "n" then
  14.             printError(confirm, "Invalid\n")
  15.         end
  16.     until confirm == "y" or confirm == "n"
  17.     if confirm == "y" then
  18.         shell.run("pastebin get Fa9KJqS4 /api/pixel.lua")
  19.         sleep(1)
  20.         os.loadAPI("/api/pixel.lua")
  21.         if not pixel then
  22.             printError("Setup failed..")
  23.         end
  24.     else
  25.         print("Abort")
  26.         return
  27.     end
  28. end
  29. -- End Wizard
  30.  
  31. --Pocket screen
  32. --local screenW, screenH = term.getSize()
  33. local screenW, screenH = 26, 20
  34. -- Native char pixel: 26 x 20 borderless ------------------->  88 outline borderless
  35. -- With pixel API   : 26 x 30 borderless -> 24 x 28 framed -> 108 outline borderless -> 100 outline framed
  36. -- With blittle API : 52 x 60 borderless -> 48 x 54 framed -> 220 outline borderless -> 200 outline framed
  37.  
  38. local _n = {
  39. {"000","ff0","000","000","0f0","000","000","000","000","000",},
  40. {"0f0","ff0","ff0","ff0","0f0","0ff","0ff","ff0","0f0","0f0",},
  41. {"0f0","ff0","000","000","000","000","000","ff0","000","000",},
  42. {"0f0","ff0","0ff","ff0","ff0","ff0","0f0","ff0","0f0","ff0",},
  43. {"000","ff0","000","000","ff0","000","000","ff0","000","000",},
  44. }
  45. local tNum = {}
  46. for i=0,9 do
  47.     tNum[i] = pixel.compute({_n[1][i],_n[2][i],_n[3][i],_n[4][i],_n[5][i]})
  48. end
  49.  
  50. function test()
  51.     term.clear()
  52.     local x,y = 4,6
  53.     for i=0,9 do
  54.         term.setCursorPos(x + ((i%5)*4), i > 4 and y+6 or y)
  55.         pixel.draw(tNum[i])
  56.     end
  57.     term.setCursorPos(3,18)
  58.     read()
  59. end
  60.  
  61. local maxLen = 6
  62. function display(num, x, y)
  63.     assert(tonumber(num), string.format([[! "%s" NaN]], num))
  64.     assert(string.len(tostring(num)) <= 6, string.format([[! "%s" too long (5 digits)]], num))
  65.    
  66.     --debug
  67.     term.setCursorPos(1,y < 10 and 2 or 17)
  68.     term.clearLine()
  69.     print("num:", num, "s:", tostring(num), "n:", tonumber(num))
  70.     term.setCursorPos(1,y < 10 and 3 or 18)
  71.     term.clearLine()
  72.     term.write("split: ")
  73.     num = string.sub(tostring(num)..string.rep(" ",maxLen),1,maxLen)
  74.     local line = {"","","","",""}
  75.     for i=1,string.len(num) do
  76.         if string.sub(num,i,i) == " " then
  77.             local pad = i == string.len(num) and "" or " "
  78.             line[1] = line[1].." "..pad
  79.             line[2] = line[2].." "..pad
  80.             line[3] = line[3].." "..pad
  81.             line[4] = line[4].." "..pad
  82.             line[5] = line[5].." "..pad
  83.         elseif i == 1 and tonumber(num) < 0 then --nombre négatif
  84.             line = string.len(num) == maxLen and {" ff "," ff "," 00 "," ff "," ff "} or {"fff ","fff ","000 ","fff ","fff "}
  85.             term.write("-")
  86.         else
  87.             term.write(tonumber(string.sub(num,i,i)).." ")
  88.             local n = tonumber(string.sub(num,i,i))
  89.             local pad = i == string.len(num) and "" or " "
  90.             line[1] = line[1].._n[1][n+1]..pad
  91.             line[2] = line[2].._n[2][n+1]..pad
  92.             line[3] = line[3].._n[3][n+1]..pad
  93.             line[4] = line[4].._n[4][n+1]..pad
  94.             line[5] = line[5].._n[5][n+1]..pad
  95.         end
  96.     end
  97.     term.setCursorPos(x, y)
  98.     pixel.draw(pixel.compute(line))
  99. end
  100.  
  101. function alignLeft()
  102.     return margin
  103. end
  104. function alignCenter(v)
  105.     local w = string.len(tostring(v))*4
  106.     return math.floor((screenW - w) / 2)
  107. end
  108. function alignRight(v, margin)
  109.     local w = string.len(tostring(v))*4
  110.     return screenW - w - margin
  111. end
  112.  
  113.  
  114. term.clear()
  115. while true do
  116.     local p = pocket.getEntity()
  117.     term.clear()
  118.     term.setTextColor(colors.gray)
  119.     display(math.floor(p.x), alignCenter(math.floor(p.x), 4), 6)
  120.     display(math.floor(p.z), alignCenter(math.floor(p.z), 4), 12)
  121.     sleep(.1)
  122. end
Advertisement
Add Comment
Please, Sign In to add comment