Guest User

Untitled

a guest
Oct 12th, 2013
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. --Graphical Speedtest Version 0.1
  2. --IMPORTANT FUNCTION
  3. function centerText(text) --SOURCE: http://www.computercraft.info/forums2/index.php?/topic/460-how-to-center-text/
  4. local x,y = term.getSize()
  5. local x2,y2 = term.getCursorPos()
  6. term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  7. write(text)
  8. end
  9. --@TXT!ID123
  10. centerText("Hello World")
  11. function string_speed(re)
  12. ss = os.clock()
  13. w = fs.open("SpeedFile","r")
  14.  
  15. rednet.send(tonumber(re),w.readAll(),true)
  16. sa = os.clock()
  17. event, id, text = os.pullEvent()
  18. if event == "rednet_message" then
  19. return "Speed: " .. math.abs(1024 / sa - ss) .." KiloByes/Sec."
  20.  
  21. end
  22. w.close()
  23. end
  24. function string_latency(rer)
  25. fb = os.clock()
  26.  
  27. rednet.send(tonumber(rer),"1111111111111111111111111111111",true)
  28. events, ids, texts = os.pullEvent()
  29.  
  30. if events == "rednet_message" then
  31. fn = os.clock()
  32. return "Latency: " .. fn - fb .. "s"
  33.  
  34. end
  35.  
  36. end
  37.  
  38. function crap()
  39.  
  40. rednet.open("back")
  41. term.clear()
  42. term.setCursorPos(1,1)
  43. term.setTextColor(colors.lime)
  44. term.setBackgroundColor(colors.blue)
  45. term.write("RedTest Graphical Version ")
  46. --term.setCursorPos(x>,y^)
  47. term.setCursorPos(1,4)
  48. term.write(" ")
  49. term.setCursorPos(1,5)
  50. term.write(" ")
  51. centerText("Latency")
  52. term.setCursorPos(1,6)
  53. term.write(" ")
  54. term.setTextColor(colors.purple)
  55. term.setBackgroundColor(colors.orange)
  56. term.setCursorPos(1,8)
  57. term.write(" ")
  58. term.setCursorPos(1,9)
  59. term.write(" ")
  60. centerText("Bit Rate")
  61.  
  62. term.setCursorPos(1,10)
  63. term.write(" ")
  64. term.setCursorPos(1,12)
  65. term.setTextColor(colors.lime)
  66. term.setBackgroundColor(colors.purple)
  67. term.write(" ")term.setCursorPos(1,13)
  68.  
  69. term.write(" ")
  70. centerText("Both")
  71. term.setCursorPos(1,14)
  72. term.write(" ")
  73. term.setBackgroundColor(colors.black)
  74. while true do
  75. sleep(0)
  76. event, button, x, y =os.pullEvent("mouse_click")
  77. if y == 5 or y==6 or y==4 then
  78. term.setCursorPos(1,4)
  79. centerText("COMPUTER ID: ")
  80. term.setCursorPos(1,5)
  81. js = read()
  82. term.setCursorPos(1,6)
  83. centerText(string_latency(js))
  84. sleep(4)
  85. crap()
  86. elseif y == 9 or y==8 or y==10 then
  87. term.setCursorPos(1,8)
  88. centerText("COMPUTER ID: ")
  89. term.setCursorPos(1,9)
  90. jss = read()
  91. term.setCursorPos(1,10)
  92. centerText(string_speed(jss))
  93. sleep(4)
  94. crap()
  95. elseif y == 13 or y==12 or y==14 then
  96. term.setCursorPos(1,12)
  97. centerText("COMPUTER ID: ")
  98. term.setCursorPos(1,13)
  99. jsss = read()
  100. term.setCursorPos(1,14)
  101. centerText(string_latency(jsss) .. " " .. string_speed(jss))
  102. sleep(4)
  103. crap()
  104. else
  105. end
  106. end
  107.  
  108. end
  109. crap()
Advertisement
Add Comment
Please, Sign In to add comment