-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmeasurer.lua
145 lines (117 loc) · 3.39 KB
/
measurer.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
local cursorX = 1
local cursorY = 1
local function setCursor(x,y)
cursorX = x
cursorY = y
term.setCursorPos(cursorX, cursorY)
end
local function goDown()
local posX, posY= term.getCursorPos()
term.setCursorPos(cursorX, posY+1)
end
local function move(x,y)
local posX, posY= term.getCursorPos()
term.setCursorPos(posX+x, posY+y)
end
local function clearLine(y)
local posX, posY= term.getCursorPos()
local sizeX, _ = term.getSize()
if type(y) == "table" then
for k,v in pairs(y) do
term.setCursorPos(1,v)
term.write(string.rep(" ",sizeX))
end
else
term.setCursorPos(1,y)
term.write(string.rep(" ",sizeX))
end
term.setCursorPos(posX,posY)
end
term.clear()
setCursor(1,1)
print("Select a Mode:")
print(" 1. Single Measurement,\n 2. Constant")
local res = tonumber(io.read())
term.clear()
setCursor(1,1)
local x1,y1,z1 = gps.locate()
term.setTextColor(colors.white)
print("1st Coords:")
term.setTextColor(colors.red)
print("X: "..x1)
term.setTextColor(colors.lime)
print("Y: "..y1)
term.setTextColor(colors.blue)
print("Z: "..z1)
if res == 1 then
term.setTextColor(colors.white)
print("\nPress Enter to select 2nd point")
io.read()
local x2,y2,z2 = gps.locate()
setCursor(14,1)
term.setTextColor(colors.white)
term.write("2nd Coords:")
goDown()
term.setTextColor(colors.red)
term.write("X2: "..x2)
goDown()
term.setTextColor(colors.lime)
term.write("Y2: "..y2)
goDown()
term.setTextColor(colors.blue)
term.write("Z2: "..z2)
goDown()
clearLine({6,7})
setCursor(1,8)
term.setTextColor(colors.white)
print("Distance:")
term.setTextColor(colors.red)
print("X: "..string.format("%.2f", x2-x1))
term.setTextColor(colors.lime)
print("Y: "..string.format("%.2f", y2-y1))
term.setTextColor(colors.blue)
print("Z: "..string.format("%.2f", z2-z1))
term.setTextColor(colors.white)
print("All: "..string.format("%.2f", math.abs(x2-x1)+math.abs(y2-y1)+math.abs(z2-z1)))
elseif res == 2 then
local exit_loop = false
repeat
local x2,y2,z2 = gps.locate()
setCursor(14,1)
term.setTextColor(colors.white)
term.write("2nd Coords:")
goDown()
term.setTextColor(colors.red)
term.write("X2: "..x2)
goDown()
term.setTextColor(colors.lime)
term.write("Y2: "..y2)
goDown()
term.setTextColor(colors.blue)
term.write("Z2: "..z2)
goDown()
clearLine({6,7})
setCursor(1,8)
term.setTextColor(colors.white)
print("Distance:")
term.setTextColor(colors.red)
print("X: "..string.format("%.2f", x2-x1))
term.setTextColor(colors.lime)
print("Y: "..string.format("%.2f", y2-y1))
term.setTextColor(colors.blue)
print("Z: "..string.format("%.2f", z2-z1))
term.setTextColor(colors.white)
print("All: "..string.format("%.2f", math.abs(x2-x1)+math.abs(y2-y1)+math.abs(z2-z1)))
print("\n\nPress \"Backspace\" to stop.")
os.startTimer(0.1)
while true do
local event, key = os.pullEvent()
if event == "timer" then
break
elseif event == "key" and key == keys.backspace then
exit_loop = true
break
end
end
until exit_loop
end