Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --By Willa_/WillaRL_
- local event = require("event")
- local component = require("component")
- local gpu = component.gpu
- local statDispArr = {}
- statDispArr.__index = statDispArr
- setmetatable(statDispArr, {__call = function(cls,...) return cls.new(...) end,})
- local statisticGraph = {}
- statisticGraph.__index = statisticGraph
- setmetatable(statisticGraph, {__call = function(cls,...) return cls.new(...) end,})
- local statisticText = {}
- statisticText.__index = statisticText
- setmetatable(statisticText, {__call = function(cls,...) return cls.new(...) end,})
- -------------------------
- --START CLASS statDispArr
- -------------------------
- function statDispArr.new()
- local self = setmetatable({}, statDispArr)
- self.statsArr = {}
- return self
- end
- function statDispArr:addGraph(behaviour, x2, x1, y2, y1, colourBack, colourFront, dataFunc, min, max)
- local newStatDisp = statisticGraph(behaviour, x2, x1, y2, y1, colourBack, colourFront, dataFunc, min, max)
- table.insert(self.statsArr, newStatDisp)
- end
- function statDispArr:addText(x, y, colour, dataFunc)
- local newStatDisp = statisticText(x, y, colour, dataFunc)
- table.insert(self.statsArr, newStatDisp)
- end
- function statDispArr:start(resolution)
- while true do
- for i, display in ipairs(self.statsArr) do
- display:draw()
- end
- os.sleep(resolution)
- end
- end
- -----------------------
- --END CLASS statDispArr
- -----------------------
- ----------------------------
- --START CLASS statisticGraph
- ----------------------------
- function statisticGraph.new(behaviour, x2, x1, y2, y1, colourBack, colourFront, dataFunc, min, max)
- local self = setmetatable({}, statisticGraph)
- self.xMin = x1
- self.yMin = y1
- self.xMax = x2
- self.yMax = y2
- self.max = max
- self.min = min
- self.colourBack = colourBack
- self.colourFront = colourFront
- self.behaviour = behaviour
- self.dataFunc = dataFunc
- self.scaleFactor = self:__scaleFactor()
- return self
- end
- function statisticGraph:__scaleFactor()
- if(self.behaviour == 0) then
- return (self.xMax - self.xMin)/(self.max - self.min)
- else
- return (self.yMax - self.yMin)/(self.max - self.min)
- end
- end
- function statisticGraph:draw()
- if(self.behaviour == 0) then
- self:__drawHoriz()
- return true
- else
- self:__drawVert()
- return true
- end
- end
- function statisticGraph:__drawHoriz()
- local val = self.dataFunc()
- local adjustedVal = math.floor(val*self.scaleFactor)
- local oldColour = gpu.setBackground(self.colourBack, false)
- gpu.fill(self.xMin, self.yMin, self.xMax - self.xMin, self.yMax - self.yMin, " ")
- gpu.setBackground(self.colourFront, false)
- gpu.fill(self.xMin, self.yMin, adjustedVal, self.yMax - self.yMin, " ")
- gpu.setBackground(oldColour)
- end
- function statisticGraph:__drawVert()
- local val = self.dataFunc()
- local adjustedVal = math.floor(val*self.scaleFactor)
- local oldColour = gpu.setBackground(self.colourFront, false)
- gpu.fill(self.xMin, self.yMin, self.xMax - self.xMin, self.yMax - self.yMin, " ")
- gpu.setBackground(self.colourBack, false)
- gpu.fill(self.xMin, self.yMin, self.xMax - self.xMin, self.yMax - adjustedVal - self.yMin, " ")
- gpu.setBackground(oldColour)
- end
- --------------------------
- --END CLASS statisticGraph
- --------------------------
- --------------------------
- --START CLASS statisticText
- --------------------------
- function statisticText.new(x,y, colour, dataFunc)
- local self = setmetatable({}, statisticText)
- self.x = x
- self.y = y
- self.colour = colour
- self.dataFunc = dataFunc
- return self
- end
- function statisticText:draw()
- local oldColour = gpu.setForeground(self.colour)
- local val = self.dataFunc()
- gpu.set(self.x, self.y, val)
- gpu.setForeground(oldColour)
- end
- -------------------------
- --END CLASS statisticText
- -------------------------
- return statDispArr
Advertisement
Add Comment
Please, Sign In to add comment