Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Goto
- -- by SukkaiPoppuGo
- assert(pocket, "Require pocket computer")
- local target = vector.new(-100, 50, -25)
- local playerData = pocket.getEntity()
- local player = vector.new( playerData.x, playerData.y, playerData.z )
- --https://math.stackexchange.com/questions/42640/calculate-distance-in-3d-space
- function distance(A, B)
- return math.sqrt(math.pow(B.x - A.x, 2) + math.pow(B.y - A.y, 2) + math.pow(B.z - A.z, 2))
- end
- local function isColinear( A, B )
- return A.x * B.z == B.x * A.z
- end
- local function convertXZToScreen(x, z, yaw)
- local angle = math.rad(-yaw % 360)
- local px = math.cos(angle) * -x - math.sin(angle) * -z
- local py = math.sin(angle) * -x + math.cos(angle) * -z
- return px, py
- end
- local function abs2rel(A, B)
- return B - A
- end
- --local Rel = abs2rel(player, target)
- --local px, py = convertXZToScreen(Rel.x, Rel.z, player.yaw) --si player.yaw existe bien sous ce nom
- ------------------------
- -- 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
- local maxPX,maxPY,minPX,minPY = 0,0,math.huge,math.huge
- local w,h = term.getSize()
- local function screenConv(px,py, dist)
- local _x = math.min(w,math.max(1,math.floor(px+(dist/2)*w/dist)))
- local _y = math.min(h,math.max(1,math.floor(py+(dist/2)*h/dist)))
- term.setCursorPos(_x,_y)
- term.blit("\7","5","f")
- end
- target = vector.new(-4989,50,-2564)
- local function cursor(p)
- local px,py = convertXZToScreen(target.x-p.x, target.z-p.z, p.yaw)
- term.setCursorPos(1,1)
- term.write(string.format("x: %s, y: %s",px,py))
- maxPX = math.max(px,maxPX)
- maxPY = math.max(py,maxPY)
- minPX = math.min(px,minPX)
- minPY = math.min(py,minPY)
- term.setCursorPos(1,20)
- term.write(string.format(
- "X: %s~%s Y: %s~%s",
- math.floor(minPX*10)/10, math.floor(maxPX*10)/10,
- math.floor(minPY*10)/10, math.floor(maxPY*10)/10
- ))
- screenConv(px,py, distance(target,p))
- 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)
- term.setCursorPos(1,19)
- term.write("Distance: "..distance(target,p))
- cursor(p)
- sleep(.1)
- end
Advertisement
Add Comment
Please, Sign In to add comment