View difference between Paste ID: hmHvWqVL and ficMQ9Tp
SHOW: | | - or go back to the newest paste.
1
-- pastebin get hmHvWqVL tpss.lua
2
3
os = require("os")
4
event = require("event")
5
term = require("term")
6
keyboard = require("keyboard")
7
com = require("component")
8
fs = require("filesystem")
9
 
10
w,h = com.gpu.getResolution()
11
 
12
prog = true
13
clearMon = false
14
crop = 0.4
15
tSlot = 1
16
timeConstant = 2
17
TPS = {}
18
avgTPS = 0
19
joke = 0
20
logTps = 1
21
logRow = 1
22
ww = w*crop
23
hh = h*crop
24
 
25
com.gpu.setResolution(ww, hh)
26
 
27
for tSlot=1,10 do
28
    TPS[tSlot]=0
29
end;
30
 
31
function minusTime(tc)
32
    if tc <= 1 then
33
        return tc
34
    else
35
        return tc - 1
36
    end;
37
end;
38
 
39
function plusTime(tc)
40
    if tc >= 20 then
41
        return tc
42
    else
43
        return tc + 1
44
    end;
45
end;
46
 
47
btn = {
48
    {
49
        x = ww-2,
50
        y = 1,
51
        action = function()
52
            event.ignore("touch", touch)
53
            prog = false
54
            clearMon = true
55
        end;
56
    },
57
    {
58
        x = 13,
59
        y = 3,
60
        action = function()
61
            timeConstant = minusTime(timeConstant)
62
        end;
63
    },
64
    {
65
        x = 21,
66
        y = 3,
67
        action = function()
68
            timeConstant = plusTime(timeConstant)
69
        end;
70
    }
71
}
72
 
73
function touch(_,_, x, y)
74
    for i = 1, #btn do
75
        if x == btn[i].x and y == btn[i].y or x >= btn[i].x + 1 and x < btn[i].x + 3 and y == btn[i].y then
76
            btn[i].action()
77
            break
78
        end;
79
    end;
80
end;
81
 
82
function twenty(flt)
83
    if flt > 20 then
84
        return 20
85
    else
86
        return flt
87
    end;
88
end;
89
 
90
function time()
91
    local f = io.open("/tmp/timeFile","w")
92
    f:write("test")
93
    f:close()
94
    return(fs.lastModified("/tmp/timeFile"))
95
end;
96
 
97
while prog == true do
98
 
99
    realTimeOld = time()
100
    os.sleep(timeConstant/10)
101
    realTimeNew = time()
102
    
103
    realTimeDiff = realTimeNew-realTimeOld
104
 
105
    TPS[tSlot] = twenty(20000*(timeConstant/10)/realTimeDiff)
106
    avgTPS = (TPS[1]+TPS[2]+TPS[3]+TPS[4]+TPS[5]+TPS[6]+TPS[7]+TPS[8]+TPS[9]+TPS[10])/10
107
    
108
    event.listen("touch", touch)
109-
    com.gpu.fill(1, 1, ww, hh-2, '█')
109+
110
    com.gpu.setForeground(0x222222)
111
--    com.gpu.fill(1, 1, ww, hh-2, '█')
112-
    com.gpu.fill(1, 1, ww, 1, '█')
112+
113
    com.gpu.setForeground(0x000080)
114
--    com.gpu.fill(1, 1, ww, 1, '█')
115
    
116
    term.setCursor(1,1)
117
    com.gpu.setBackground(0x000080)
118
    com.gpu.setForeground(0xFFFFFF)
119
    print("roga122 tps checker")
120
    
121
    com.gpu.setForeground(0xff0000)
122
    com.gpu.fill(ww-2, 1, 3, 1, '█')
123
    
124
    term.setCursor(ww-1,1)
125
    com.gpu.setBackground(0xff0000)
126
    com.gpu.setForeground(0xffffff)
127
    print("X")
128
    
129
    
130
    term.setCursor(1,3)
131
    com.gpu.setForeground(0xffffff)
132
    com.gpu.setBackground(0x222222)
133
    print("Частота:", timeConstant/10)
134
    
135
    term.setCursor(1,4)
136
    com.gpu.setForeground(0xffffff)
137
    com.gpu.setBackground(0x222222)
138
    print("TPS сейчас:", string.format("%.2f",TPS[tSlot]))
139
    
140
    term.setCursor(1,5)
141
    com.gpu.setBackground(0x222222)
142
    print("TPS средний:", string.format("%.2f",avgTPS))
143
    
144
    term.setCursor(1,7)
145
    print("Плавность работы визуально:")
146-
    print("История тпс:")
146+
147
    term.setCursor(1,17)
148
--    print("История тпс:")
149
    
150
    com.gpu.setForeground(0xcccccc)
151
    com.gpu.fill(13, 3, 3, 1, '█')
152
    
153
    com.gpu.setBackground(0xcccccc)
154
    com.gpu.setForeground(0xffffff)
155
    term.setCursor(14,3)
156
    print("-")
157
        
158
    com.gpu.setForeground(0xcccccc)
159
    com.gpu.fill(21, 3, 3, 1, '█')
160
    
161
    com.gpu.setBackground(0xcccccc)
162
    com.gpu.setForeground(0xffffff)
163
    term.setCursor(22,3)
164
    print("+")
165
    
166
    
167
    if joke < ww then
168
        if (avgTPS > 18) then
169
            com.gpu.setForeground(0x00FF00)
170
        elseif (avgTPS < 18 and avgTPS > 13) then
171
            com.gpu.setForeground(0xFFFF00)
172
        elseif (avgTPS < 13 and avgTPS > 8) then
173
            com.gpu.setForeground(0xFF9900)
174
        else
175-
        com.gpu.fill(1, 9, joke, 7, '█')
175+
176
        end;
177
--************************************************************
178
        com.gpu.fill(joke, 18-TPS[tSlot]/2, 1, TPS[tSlot]/2+1, '█')
179
--***********************************************************
180
        joke = joke + 1
181
    else 
182
--***********************************************************
183
--        if (avgTPS > 18) then
184
            com.gpu.setForeground(0x00FF00)
185
--        elseif (avgTPS < 18 and avgTPS > 13) then
186
--            com.gpu.setForeground(0xFFFF00)
187-
        com.gpu.fill(1, 9, ww, 7, '█')
187+
--        elseif (avgTPS < 13 and avgTPS > 8) then
188
--            com.gpu.setForeground(0xFF9900)
189
--        else
190
            com.gpu.setForeground(0x000000)
191
--        end;
192
        com.gpu.fill(1, 8, ww, 10, '█')
193
        joke = 0
194
    end;
195
    
196
    if logTps < 11 then
197
        term.setCursor(logRow+3, hh-1)
198
        com.gpu.setForeground(0xffffff)
199
        com.gpu.setBackground(0x222222)
200
        print(string.format("%.1f",TPS[logTps]))
201
        
202
        term.setCursor(1, hh-2)
203
        com.gpu.setForeground(0x222222)
204
        com.gpu.fill(1, hh-2, ww, 1, '█')
205
        
206
        term.setCursor(logRow+2, hh-2)
207
        
208
        com.gpu.setForeground(0x000000)
209
        if (TPS[tSlot] > 18) then
210
            com.gpu.setBackground(0x00FF00)
211
        elseif (TPS[tSlot] < 18 and TPS[tSlot] > 13) then
212
            com.gpu.setBackground(0xFFFF00)
213
        elseif (TPS[tSlot] < 13 and TPS[tSlot] > 8) then
214
            com.gpu.setBackground(0xFF9900)
215
        else
216
            com.gpu.setBackground(0xFF0000)
217
        end;
218
--******************************************************************
219
220
--        com.gpu.fill(logRow+2, 18-TPS[tSlot]/2, 6, TPS[tSlot]/2, '8')
221
222
223
        print("Сейчас")
224
        
225
        com.gpu.setForeground(0xffffff)
226
        com.gpu.setBackground(0x222222)
227
        
228
        logTps = logTps + 1
229
        logRow = logRow + 6
230
    end;
231
    
232
    if logTps == 11 then
233
        logTps = 1
234
        logRow = 1
235
    end;
236
    
237
    if tSlot == 10 then
238
        tSlot = 0
239
    end;
240
    
241
    tSlot = tSlot + 1
242
 
243
    if clearMon == true then
244
        term.setCursor(1, 1)
245
        term.clear()
246
        com.gpu.setBackground(0x000000)
247
        com.gpu.setForeground(0x000000)
248
        com.gpu.setResolution(w, h)
249
        com.gpu.fill(1, 1, w, h, '█')
250
        com.gpu.setForeground(0xFFFFFF)
251
        com.gpu.setBackground(0x000000)
252
        print("Выход...")
253
    end;
254
end;