Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- graphs = {}
- mon = term.current()
- function addGraph(name, x, y, width, height, color, value, maxValue)
- horizontal = false
- drawP = true
- drawOutline = true
- graphs[name] = {
- name = name,
- x = x,
- y = y,
- width = width,
- height = height,
- color = color,
- value = value,
- maxValue = maxValue,
- horizontal = horizontal,
- drawP = drawP,
- drawOutline = drawOutline
- }
- end
- function updateValue(name, value)
- maxValue = graphs[name].maxValue
- if value > maxValue then
- error("Value is greater than max value")
- end
- graphs[name].value = value
- end
- function updateMaxValue(name, maxValue)
- if value > maxValue then
- value = 0
- end
- graphs[name]["maxValue"] = maxValue
- end
- function updateDrawProgress(name, drawP)
- graphs[name].drawP = drawP
- end
- function setHorizontal(name, horizontal)
- graphs[name].horizontal = horizontal
- end
- function setShowText(name, showText)
- graphs[name].drawP = showText
- end
- function setShowOutline(name, showOutline)
- graphs[name].drawOutline = showOutline
- end
- function updateColor(name, color)
- graphs[name].color = color
- end
- function setMonitor(monitor)
- mon = monitor
- end
- function draw()
- term.redirect(mon)
- isColor = term.isColor()
- if not isColor then
- error("Color is not supported on this monitor. Cannot continue!")
- end
- term.setBackgroundColor(colors.black)
- term.clear()
- for name,graph in pairs(graphs) do
- x = graph["x"]
- y = graph["y"]
- width = graph["width"]
- height = graph["height"]
- endX = x + width
- endY = y + height
- color = graph["color"]
- value = graph["value"]
- maxValue = graph["maxValue"]
- horizontal = graph["horizontal"]
- drawP = graph["drawP"]
- drawOutline = graph["drawOutline"]
- offset = (height / maxValue) * (maxValue - value)
- if horizontal == true then
- offset = (width / maxValue) * (maxValue - value)
- paintutils.drawFilledBox(x, y, endX - offset, endY, color)
- else
- paintutils.drawFilledBox(x, y + offset, endX, endY, color)
- end
- if drawOutline == true then
- paintutils.drawBox(x, y, endX, endY, color)
- end
- text = ((value / maxValue) * 100) .. "%"
- if drawP == true then
- textX = x + ((width / 2) - (text:len() / 2))
- textY = y + (height / 2) + (offset / 2)
- if horizontal then
- textX = x + ((width / 2) - (text:len() / 2))
- textY = y + (height / 2)
- end
- term.setCursorPos(textX, textY)
- term.write(text)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement