Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Numbers
- -- by SukaiPoppuGo
- -- Pixel API Wizard
- os.loadAPI("/api/pixel.lua")
- if not pixel then
- local confirm
- repeat
- print("Pixel API required")
- print("pastebin get Fa9KJqS4 /api/pixel.lua")
- print("Download ? Y/N")
- confirm = string.lower(read())
- if confirm ~= "y" and confirm ~= "n" then
- printError(confirm, "Invalid\n")
- end
- until confirm == "y" or confirm == "n"
- if confirm == "y" then
- shell.run("pastebin get Fa9KJqS4 /api/pixel.lua")
- sleep(1)
- os.loadAPI("/api/pixel.lua")
- if not pixel then
- printError("Setup failed..")
- end
- else
- print("Abort")
- return
- end
- end
- -- End Wizard
- --Pocket screen
- --local screenW, screenH = term.getSize()
- local screenW, screenH = 26, 20
- -- Native char pixel: 26 x 20 borderless -------------------> 88 outline borderless
- -- With pixel API : 26 x 30 borderless -> 24 x 28 framed -> 108 outline borderless -> 100 outline framed
- -- With blittle API : 52 x 60 borderless -> 48 x 54 framed -> 220 outline borderless -> 200 outline framed
- local _n = {
- {"000","ff0","000","000","0f0","000","000","000","000","000",},
- {"0f0","ff0","ff0","ff0","0f0","0ff","0ff","ff0","0f0","0f0",},
- {"0f0","ff0","000","000","000","000","000","ff0","000","000",},
- {"0f0","ff0","0ff","ff0","ff0","ff0","0f0","ff0","0f0","ff0",},
- {"000","ff0","000","000","ff0","000","000","ff0","000","000",},
- }
- local tNum = {}
- for i=0,9 do
- tNum[i] = pixel.compute({_n[1][i],_n[2][i],_n[3][i],_n[4][i],_n[5][i]})
- end
- function test()
- term.clear()
- local x,y = 4,6
- for i=0,9 do
- term.setCursorPos(x + ((i%5)*4), i > 4 and y+6 or y)
- pixel.draw(tNum[i])
- end
- term.setCursorPos(3,18)
- read()
- end
- local maxLen = 6
- function display(num, x, y)
- assert(tonumber(num), string.format([[! "%s" NaN]], num))
- assert(string.len(tostring(num)) <= 6, string.format([[! "%s" too long (5 digits)]], num))
- --debug
- term.setCursorPos(1,y < 10 and 2 or 17)
- term.clearLine()
- print("num:", num, "s:", tostring(num), "n:", tonumber(num))
- term.setCursorPos(1,y < 10 and 3 or 18)
- term.clearLine()
- term.write("split: ")
- num = string.sub(tostring(num)..string.rep(" ",maxLen),1,maxLen)
- local line = {"","","","",""}
- for i=1,string.len(num) do
- if string.sub(num,i,i) == " " then
- local pad = i == string.len(num) and "" or " "
- line[1] = line[1].." "..pad
- line[2] = line[2].." "..pad
- line[3] = line[3].." "..pad
- line[4] = line[4].." "..pad
- line[5] = line[5].." "..pad
- elseif i == 1 and tonumber(num) < 0 then --nombre négatif
- line = string.len(num) == maxLen and {" ff "," ff "," 00 "," ff "," ff "} or {"fff ","fff ","000 ","fff ","fff "}
- term.write("-")
- else
- term.write(tonumber(string.sub(num,i,i)).." ")
- local n = tonumber(string.sub(num,i,i))
- local pad = i == string.len(num) and "" or " "
- line[1] = line[1].._n[1][n+1]..pad
- line[2] = line[2].._n[2][n+1]..pad
- line[3] = line[3].._n[3][n+1]..pad
- line[4] = line[4].._n[4][n+1]..pad
- line[5] = line[5].._n[5][n+1]..pad
- end
- end
- term.setCursorPos(x, y)
- pixel.draw(pixel.compute(line))
- end
- function alignLeft()
- return margin
- end
- function alignCenter(v)
- local w = string.len(tostring(v))*4
- return math.floor((screenW - w) / 2)
- end
- function alignRight(v, margin)
- local w = string.len(tostring(v))*4
- return screenW - w - margin
- end
- term.clear()
- while true do
- local p = pocket.getEntity()
- term.clear()
- term.setTextColor(colors.gray)
- display(math.floor(p.x), alignCenter(math.floor(p.x), 4), 6)
- display(math.floor(p.z), alignCenter(math.floor(p.z), 4), 12)
- sleep(.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment