Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- monSide = "right"
- --lime/red will toggle
- --blue/gray/magenta will NOT change colour.
- --add buttons here
- tButtons = {
- --name, xmin, xmax, ymin, ymax, Colour
- {"Button1",1,10,1,3,"lime"},
- {"Button2",12,21,1,3,"lime"},
- {"Button3",1,10,5,7,"lime"},
- {"Button4",12,21,5,7,"magenta"},
- {"Button5",1,10,9,11,"gray"},
- {"Button6",12,21,9,11,"blue"},
- }
- --add function here
- function userInput(Touch)
- if Touch == 1 then
- print("1")
- elseif Touch == 2 then
- print("2")
- elseif Touch == 3 then
- print("3")
- elseif Touch == 4 then
- print("4")
- elseif Touch == 5 then
- print("soooooo boring")
- elseif Touch == 6 then
- print("i'm blue baby!")
- end
- end
- ------------------------------------------------
- function drawButtons()
- mon.setBackgroundColour(colours.black)
- mon.clear()
- for i = 1,#tButtons do
- if tButtons[i][6] == "red" then
- mon.setBackgroundColor(colorRed)
- elseif tButtons[i][6] == "lime" then
- mon.setBackgroundColor(colorLime)
- elseif tButtons[i][6] == "blue" then
- mon.setBackgroundColor(colorBlue)
- elseif tButtons[i][6] == "gray" then
- mon.setBackgroundColor(colorGray)
- elseif tButtons[i][6] == "magenta" then
- mon.setBackgroundColor(colorMagenta)
- end
- for i2 = tButtons[i][4],tButtons[i][5] do
- for i3 = tButtons[i][2],tButtons[i][3] do
- mon.setCursorPos(i3,i2)
- mon.write(" ")
- end
- end
- mon.setCursorPos((tButtons[i][2] + tButtons[i][3]) /2 -(#tButtons[i][1]/2 -1 ), (tButtons[i][4] + tButtons[i][5])/2 )
- mon.write(tButtons[i][1])
- end
- end
- mon = peripheral.wrap(monSide)
- mon.setBackgroundColour(colours.black)
- mon.clear()
- colorRed = 16384
- colorLime = 32
- colorBlue = 2048
- colorGray = 256
- colorMagenta = 4
- function miceClick()
- event, button, miceX, miceY = os.pullEvent("monitor_touch")
- for i4 = 1,#tButtons do
- if miceX >= tButtons[i4][2] and miceX <= tButtons[i4][3] and miceY >= tButtons[i4][4] and miceY <= tButtons[i4][5] then
- if tButtons[i4][6] == "lime" then
- tButtons[i4][6] = "red"
- elseif tButtons[i4][6] == "red" then
- tButtons[i4][6] = "lime"
- end
- Touch = i4
- userInput(Touch)
- end
- end
- end
- while true do
- drawButtons()
- miceClick()
- end
Advertisement
Add Comment
Please, Sign In to add comment