Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("")
- term.write("Enter hours: ")
- local nHours = tonumber(read())
- nHours = nHours or 0
- print("")
- term.write("Enter minutes: ")
- local nMinutes = tonumber(read())
- nMinutes = nMinutes or 0
- print("")
- term.write("Enter seconds: ")
- local nSeconds = tonumber(read())
- nSeconds = nSeconds or 0
- term.clear()
- local totalTime = (nHours * 36000) + (nMinutes * 600) + (nSeconds * 10)
- if totalTime == 0 then print("") error("No time to count down\n", 0) end
- local hours, minutes, seconds, sHours, sMinutes, sSeconds, sTenths, countdownTimer, timer, _
- local mon = { peripheral.find("monitor") }
- if mon then
- local x
- for i = 1, #mon do
- mon[i].setTextColor(colors.white)
- mon[i].setBackgroundColor(colors.black)
- mon[i].clear()
- mon[i].setTextScale(1)
- x = mon[i].getSize()
- if x == 7 then --# width = 1
- mon[i].setTextScale(0.5)
- elseif x == 18 then --# width = 2
- mon[i].setTextScale(nHours < 10 and 2 or 1)
- elseif x == 29 then --# width = 3
- mon[i].setTextScale(3)
- elseif x == 39 then --# width = 4
- mon[i].setTextScale(4)
- elseif x >= 50 then --# width = 5+
- mon[i].setTextScale(5)
- end
- end
- end
- for i = totalTime, 0, -1 do
- hours = totalTime > 35999 and math.floor(totalTime / 36000) or 0
- sHours = tostring(hours)
- minutes = totalTime > 599 and math.floor((totalTime - (hours * 36000)) / 600) or 0
- sMinutes = minutes > 9 and tostring(minutes) or "0" .. tostring(minutes)
- seconds = totalTime > 9 and math.floor((totalTime - ((hours * 36000) + (minutes * 600))) / 10) or 0
- sSeconds = seconds > 9 and tostring(seconds) or "0" .. tostring(seconds)
- sTenths = tostring(math.floor(totalTime - ((hours * 36000) + (minutes * 600) + (seconds * 10))))
- term.setCursorPos(1, 1)
- if totalTime == 0 and term.isColor() then term.setTextColor(colors.red) end
- term.write(sHours .. ":" .. sMinutes .. ":" .. sSeconds .. ":" .. sTenths .. " ")
- if mon then
- for i = 1, #mon do
- mon[i].setCursorPos(1, 1)
- if totalTime == 0 and mon[i].isColor() then mon[i].setTextColor(colors.red) end
- mon[i].write(sHours .. ":" .. sMinutes .. ":" .. sSeconds .. ":" .. sTenths .. " ")
- end
- end
- if totalTime > 0 then
- countdownTimer = os.startTimer(0.1)
- repeat
- _, timer = os.pullEvent("timer")
- if timer == countdownTimer then
- totalTime = totalTime - 1
- end
- until timer == countdownTimer
- end
- end
- print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement