Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local history = {}
- local function calculateHeight(maxHeight, value, maxValue)
- return math.floor(maxHeight * (value / maxValue) + 0.5)
- end
- local function drawGraph(history, xPos, yPos, length, height, maxValue)
- local len = #history
- for x = length, 1, -1 do
- local i = length - x + 1
- for y = 1, calculateHeight(height, history[i], maxValue) do
- -- draw a pixel at that position.
- term.setCursorPos(xPos + x, yPos + y)
- term.write(' ')
- end
- end
- end
- local function addHistory(value)
- table.insert(history, value)
- if #history > 50 then
- table.remove(history, 1)
- end
- end
- addHistory(83)
- addHistory(29)
- addHistory(37)
- addHistory(99)
- addHistory(75)
- addHistory(16)
- addHistory(1)
- addHistory(5)
- drawGraph(history, 3, 15, 9, 12, 100)
Add Comment
Please, Sign In to add comment