Advertisement
opencomputerstest2

speed.lua

Apr 5th, 2024 (edited)
776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. shell.run("wget https://github.com/9551-Dev/apis/raw/main/graphir.lua")
  2.  
  3. shell.run("wget https://github.com/9551-Dev/apis/raw/main/pixelbox_lite.lua")
  4.  
  5. local graphir  = require("graphir")
  6.  
  7. local pixelbox = require("pixelbox_lite")
  8.  
  9. local box = pixelbox.new(term.current())
  10.  
  11. local graph = graphir.new(box,colors.lightGray,colors.black,true,"normal")
  12.  
  13.  
  14.  
  15. while true do
  16.     local a_x, a_y, a_z = gps.locate(5)
  17.  
  18.     os.sleep(0.5)
  19.  
  20.     local b_x, b_y, b_z = gps.locate(5)
  21.  
  22.  
  23.     local delta_x = a_x - b_x
  24.     local delta_z = a_z - b_z
  25.  
  26.     local distance = math.sqrt(delta_x^2 + delta_z^2)
  27.  
  28.     local a_x = nil
  29.     local b_x = nil
  30.     local b_y = nil
  31.     local a_y = nil
  32.     local a_z = nil
  33.     local b_z = nil
  34.  
  35.     local speed = distance*2
  36.  
  37.     term.setBackgroundColor(colors.black)
  38.     term.setTextColor(colors.white)
  39.     graph:add(speed)
  40.     graph:push()
  41.     box:render()
  42.     term.setCursorPos(1, 1)
  43.     term.setBackgroundColor(colors.white)
  44.     term.setTextColor(colors.black)
  45.     print(("Current speed: %s meters/second"):format(speed))
  46.  
  47. end
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement