Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local gui = require("/apis/gui")
- function main()
- -- initialize display using above information
- -- receive buffer object which elements can be added to
- local monitor = peripheral.wrap("monitor_0")
- monitor.setTextScale(0.5)
- monitor.clear()
- monitor.setCursorPos(1, 1)
- local main_display = gui.initializeDisplay(monitor)
- setupDisplays(main_display)
- while true do
- main_display:render()
- gui.doEvents()
- end
- end
- function setupDisplays(display)
- local text_container = gui.Element:new {
- x = 1,
- y = 1,
- width = 16,
- height = display.window.height - 2,
- bg_color = colors.gray,
- }
- display.window:addElement(text_container)
- local filler_text = gui.Text:new {
- x = 1,
- y = 1,
- width = text_container.width - 3,
- height = text_container.height - 2,
- bg_color = colors.white,
- text = "lorem ipsum dolor sit amet",
- text_color = colors.black,
- }
- text_container:addElement(filler_text)
- local scroll_bar_container = gui.Element:new {
- x = filler_text.width + 1,
- y = 1,
- width = 1,
- height = text_container.height - 2,
- bg_color = colors.lightGray,
- }
- text_container:addElement(scroll_bar_container)
- local scroll_up_button = gui.Element:new {
- x = 0,
- y = 0,
- width = 1,
- height = 1,
- bg_color = colors.red,
- monitor_touch = function(self, e)
- filler_text.scroll_offset = filler_text.scroll_offset - 1
- end,
- }
- scroll_bar_container:addElement(scroll_up_button)
- local scroll_down_button = gui.Element:new {
- x = 0,
- y = scroll_bar_container.height - 1,
- width = 1,
- height = 1,
- bg_color = colors.green,
- monitor_touch = function(self, e)
- filler_text.scroll_offset = filler_text.scroll_offset + 1
- end,
- }
- scroll_bar_container:addElement(scroll_down_button)
- local right_x = text_container.x + text_container.width + 1
- local bar = gui.Bar:new {
- x = right_x,
- y = 1,
- width = display.window.width - right_x - 1,
- height = 2,
- bg_color = colors.white,
- fill_color = colors.green,
- percent_filled = 0.0,
- }
- display.window:addElement(bar)
- local function updateBar()
- if bar.percent_filled >= 1 then
- bar.percent_filled = 0.0
- end
- local timer_id = os.startTimer(0.1)
- function bar:timer(e)
- if e.id == timer_id then
- self.percent_filled = self.percent_filled + 0.01
- updateBar()
- end
- end
- end
- updateBar()
- local bar_text = gui.Text:new {
- x = 1,
- y = 1,
- width = 8,
- height = 1,
- bg_transparent = true,
- text_color = colors.black,
- text = "bar_text"
- }
- bar:addElement(bar_text)
- local data = {
- {
- u = 0,
- v = 1,
- },
- {
- u = 1,
- v = 4,
- },
- {
- u = 2,
- v = 2,
- },
- {
- u = 3,
- v = 1,
- },
- {
- u = 4,
- v = 6,
- },
- {
- u = 5,
- v = 4,
- },
- {
- u = 6,
- v = 0.5,
- },
- }
- local data_file = fs.open("data.txt", "w")
- local serial_data = textutils.serialise(data)
- data_file.write(serial_data)
- filler_text:setText(serial_data)
- data_file.close()
- local graph = gui.Graph:new {
- x = right_x,
- y = 4,
- width = display.window.width - right_x - 1,
- height = display.window.height - 5,
- bg_color = colors.white,
- data_source = "data.txt",
- u_min = -0.4,
- u_max = 7,
- v_min = -1,
- v_max = 6,
- draw_axes = true,
- }
- graph:pullData()
- display.window:addElement(graph)
- local u_min = graph.u_min
- local v_min = graph.v_min
- local function updateGraph()
- local timer_id = os.startTimer(0.05)
- function graph:timer(e)
- if e.id == timer_id then
- self.u_min = u_min + 2 * math.sin(os.clock())
- self.v_min = v_min + 1.3 * math.sin(0.8 * os.clock() + 0.2)
- updateGraph()
- end
- end
- end
- updateGraph()
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement