Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("left")
- mon = peripheral.wrap("right")
- local total_counted = 0
- local counted_hour = 0
- local old_total_counted = 0
- local lst_of_counted = {}
- local lst_for_graph = {}
- local cycle = 0
- function sum(t)
- local sum = 0
- for k,v in pairs(t) do
- sum = sum + v
- end
- return sum
- end
- function what_length(t)
- local lengthNum = 0
- for k, v in pairs(t) do -- for every key in the table with a corresponding non-nil value
- lengthNum = lengthNum + 1
- end
- return lengthNum
- end
- function draw_square(i,j) --i,j are the cursor pos where the block is supposed to be placed.
- i = tonumber(i)
- j = tonumber(j)
- mon.setBackgroundColor(colors.green)
- mon.setCursorPos(i,j)
- mon.write(" ")
- mon.setBackgroundColor(colors.black) end --removed the return
- function draw_graph(k) --k should be lst_of_counted
- local counter = 0
- local i = 1
- counter = what_length(lst_for_graph) + 1
- for x=1,50,1 do
- counter = counter - 1
- i = i + 1
- if i > 49 then
- i = 49 end
- if k[counter] == nil then
- return
- elseif counter == 0 then
- return
- elseif k[counter] > 125 then
- for a=18,10,-1 do --draw a 8 block high green bar
- draw_square(i,a)
- sleep(0.1) end
- elseif k[counter] > 109 then
- for a=18,11,-1 do --draw a 7 block high green bar
- draw_square(i,a)
- sleep(0.1) end
- elseif k[counter] > 93 then
- for a=18,12,-1 do --draw a 6 block high green bar
- draw_square(i,a)
- sleep(0.1) end
- elseif k[counter] > 78 then
- for a=18,13,-1 do --draw a 5 block high green bar
- draw_square(i,a)
- sleep(0.1) end
- elseif k[counter] > 62 then
- for a=18,14,-1 do --draw a 4 block high green bar
- draw_square(i,a)
- sleep(0.1) end
- elseif k[counter] > 46 then
- for a=18,15,-1 do --draw a 3 block high green bar
- draw_square(i,a)
- sleep(0.1) end
- elseif k[counter] > 31 then
- for a=18,16,-1 do --draw a 2 block high green bar
- draw_square(i,a)
- sleep(0.1) end
- elseif k[counter] < 32 then
- for a=18,17,-1 do --draw a 1 block high green bar
- draw_square(i,a)
- sleep(0.1) end
- end
- end
- end
- while true do
- local currently_counted = 0
- x,y,z = rednet.receive()
- old_total_counted = total_counted
- cycle = cycle+1
- total_counted = y
- currently_counted = y - old_total_counted
- table.insert(lst_of_counted,currently_counted)
- table.insert(lst_for_graph,currently_counted)
- if cycle > 20 then
- table.remove(lst_of_counted, 1)
- --delete last item of table and then sum together all
- counted_hour = 0
- counted_hour = sum(lst_of_counted)
- end
- if cycle > 50 then
- table.remove(lst_for_graph, 1)
- end
- total_counted = tostring(tonumber(total_counted))
- counted_hour = tostring(tonumber(counted_hour))
- mon.clear()
- draw_graph(lst_for_graph)
- mon.setTextColor(colors.white)
- --Mark the graph
- mon.setCursorPos(1,9)
- mon.write("130")
- mon.setCursorPos(2,19)
- mon.write("3")
- mon.setCursorPos(10.5,19)
- mon.write("36")
- mon.setCursorPos(24,19)
- mon.write("72")
- mon.setCursorPos(37.5,19)
- mon.write("108")
- mon.setCursorPos(48,19)
- mon.write("144")
- sleep(0.1)
- mon.setCursorPos(1,1)
- mon.write("+------------------------------------------------+")
- mon.setCursorPos(1,3)
- mon.write("We have produced a total of ")
- mon.write(total_counted)
- mon.write(" pieces of coal!")
- mon.setCursorPos(1,5)
- mon.write(total_counted)
- mon.write(" makes ")
- mon.write(tostring(tonumber(math.floor(total_counted/64))))
- mon.write(" stacks of coal! ")
- if cycle > 10 then
- mon.setCursorPos(1,7)
- mon.write("Last hour ")
- mon.write(counted_hour)
- mon.write(" pieces of coal were produced!")
- mon.setCursorPos(1,20)
- mon.write("+------------------------------------------------+")
- else
- mon.setCursorPos(1,7)
- mon.write("Last hour [N/A] pieces of coal were produced!")
- mon.setCursorPos(1,20)
- mon.write("+------------------------------------------------+")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement