SHOW:
|
|
- or go back to the newest paste.
1 | - | --TODO: |
1 | + | |
2 | - | --Finde heraus wie breit der monitor ist. |
2 | + | |
3 | - | --integriere neue liste mit der gewuenschten breite |
3 | + | |
4 | - | --mach balken hoeher |
4 | + | |
5 | local counted_hour = 0 | |
6 | local old_total_counted = 0 | |
7 | local lst_of_counted = {} | |
8 | local lst_for_graph = {} | |
9 | local cycle = 0 | |
10 | ||
11 | ||
12 | function sum(t) | |
13 | local sum = 0 | |
14 | for k,v in pairs(t) do | |
15 | sum = sum + v | |
16 | end | |
17 | return sum | |
18 | end | |
19 | ||
20 | function what_length(t) | |
21 | local lengthNum = 0 | |
22 | ||
23 | for k, v in pairs(t) do -- for every key in the table with a corresponding non-nil value | |
24 | lengthNum = lengthNum + 1 | |
25 | end | |
26 | return lengthNum | |
27 | - | --mon.setBackgroundColor(colors.green) |
27 | + | |
28 | ||
29 | - | mon.write("#") |
29 | + | |
30 | i = tonumber(i) | |
31 | j = tonumber(j) | |
32 | mon.setBackgroundColor(colors.green) | |
33 | - | mon.setCursorPos(1,10) |
33 | + | |
34 | - | mon.write("DRAWING GRAPH....") |
34 | + | mon.write(" ") |
35 | - | local i = 18 --DEBUGGING |
35 | + | |
36 | - | for x=2,18,1 do |
36 | + | |
37 | function draw_graph(k) --k should be lst_of_counted | |
38 | - | if i > 40 then |
38 | + | local counter = 0 |
39 | - | i = 40 end |
39 | + | local i = 1 |
40 | - | if k[i] == nil then |
40 | + | counter = what_length(lst_for_graph) + 1 |
41 | for x=1,50,1 do | |
42 | - | elseif k[i] > 119 then |
42 | + | counter = counter - 1 |
43 | - | for a=19,14,-1 do --draw a 5 block high green bar |
43 | + | |
44 | if i > 49 then | |
45 | i = 49 end | |
46 | - | elseif k[i] > 89 then |
46 | + | if k[counter] == nil then |
47 | - | for a=19,15,-1 do --draw a 4 block high green bar |
47 | + | |
48 | - | draw_square(x,a) |
48 | + | elseif counter == 0 then |
49 | return | |
50 | - | elseif k[i] > 59 then |
50 | + | elseif k[counter] > 125 then |
51 | - | for a=19,16,-1 do --draw a 3 block high green bar |
51 | + | for a=18,10,-1 do --draw a 8 block high green bar |
52 | - | draw_square(x,a) |
52 | + | |
53 | sleep(0.1) end | |
54 | - | elseif k[i] > 29 then |
54 | + | elseif k[counter] > 109 then |
55 | - | for a=19,17,-1 do --draw a 2 block high green bar |
55 | + | for a=18,11,-1 do --draw a 7 block high green bar |
56 | - | draw_square(x,a) |
56 | + | |
57 | sleep(0.1) end | |
58 | - | elseif k[i] > 1 then |
58 | + | elseif k[counter] > 93 then |
59 | - | for a=19,18,-1 do --draw a 1 block high green bar |
59 | + | for a=18,12,-1 do --draw a 6 block high green bar |
60 | - | draw_square(x,a) |
60 | + | |
61 | sleep(0.1) end | |
62 | elseif k[counter] > 78 then | |
63 | for a=18,13,-1 do --draw a 5 block high green bar | |
64 | draw_square(i,a) | |
65 | sleep(0.1) end | |
66 | elseif k[counter] > 62 then | |
67 | for a=18,14,-1 do --draw a 4 block high green bar | |
68 | draw_square(i,a) | |
69 | sleep(0.1) end | |
70 | elseif k[counter] > 46 then | |
71 | for a=18,15,-1 do --draw a 3 block high green bar | |
72 | draw_square(i,a) | |
73 | sleep(0.1) end | |
74 | elseif k[counter] > 31 then | |
75 | for a=18,16,-1 do --draw a 2 block high green bar | |
76 | draw_square(i,a) | |
77 | sleep(0.1) end | |
78 | elseif k[counter] < 32 then | |
79 | for a=18,17,-1 do --draw a 1 block high green bar | |
80 | draw_square(i,a) | |
81 | sleep(0.1) end | |
82 | end | |
83 | end | |
84 | end | |
85 | ||
86 | - | if cycle > 40 then |
86 | + | |
87 | ||
88 | local currently_counted = 0 | |
89 | ||
90 | x,y,z = rednet.receive() | |
91 | ||
92 | old_total_counted = total_counted | |
93 | cycle = cycle+1 | |
94 | - | draw_graph(lst_of_counted) |
94 | + | |
95 | currently_counted = y - old_total_counted | |
96 | table.insert(lst_of_counted,currently_counted) | |
97 | table.insert(lst_for_graph,currently_counted) | |
98 | ||
99 | if cycle > 20 then | |
100 | table.remove(lst_of_counted, 1) | |
101 | --delete last item of table and then sum together all | |
102 | counted_hour = 0 | |
103 | counted_hour = sum(lst_of_counted) | |
104 | end | |
105 | ||
106 | if cycle > 50 then | |
107 | - | mon.setCursorPos(1,7) |
107 | + | |
108 | - | mon.write("Last batch there was ") |
108 | + | |
109 | - | mon.write(tostring(tonumber(currently_counted))) |
109 | + | |
110 | total_counted = tostring(tonumber(total_counted)) | |
111 | - | mon.setCursorPos(1,12) |
111 | + | |
112 | - | mon.write(lst_of_counted[1]) |
112 | + | |
113 | mon.clear() | |
114 | - | mon.setCursorPos(1,9) |
114 | + | draw_graph(lst_for_graph) |
115 | mon.setTextColor(colors.white) | |
116 | --Mark the graph | |
117 | mon.setCursorPos(1,9) | |
118 | mon.write("130") | |
119 | mon.setCursorPos(2,19) | |
120 | mon.write("3") | |
121 | - | mon.setCursorPos(1,9) |
121 | + | mon.setCursorPos(10.5,19) |
122 | mon.write("36") | |
123 | mon.setCursorPos(24,19) | |
124 | mon.write("72") | |
125 | mon.setCursorPos(37.5,19) | |
126 | mon.write("108") | |
127 | mon.setCursorPos(48,19) | |
128 | mon.write("144") | |
129 | sleep(0.1) | |
130 | mon.setCursorPos(1,1) | |
131 | mon.write("+------------------------------------------------+") | |
132 | mon.setCursorPos(1,3) | |
133 | mon.write("We have produced a total of ") | |
134 | mon.write(total_counted) | |
135 | mon.write(" pieces of coal!") | |
136 | mon.setCursorPos(1,5) | |
137 | mon.write(total_counted) | |
138 | mon.write(" makes ") | |
139 | mon.write(tostring(tonumber(math.floor(total_counted/64)))) | |
140 | mon.write(" stacks of coal! ") | |
141 | if cycle > 10 then | |
142 | mon.setCursorPos(1,7) | |
143 | mon.write("Last hour ") | |
144 | mon.write(counted_hour) | |
145 | mon.write(" pieces of coal were produced!") | |
146 | mon.setCursorPos(1,20) | |
147 | mon.write("+------------------------------------------------+") | |
148 | else | |
149 | mon.setCursorPos(1,7) | |
150 | mon.write("Last hour [N/A] pieces of coal were produced!") | |
151 | mon.setCursorPos(1,20) | |
152 | mon.write("+------------------------------------------------+") | |
153 | end | |
154 | end | |
155 |