Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monSide = "back"
- local Bcol = colors.lightGray
- local Bside = "front"
- mon = peripheral.wrap(monSide)
- mon.setTextScale(.5)
- local xMax,yMax = mon.getSize()
- Button = {}
- Button[1] = { 2, 2, xMax/2-1, yMax-1,"Hoch" ,colors.lime,false,colors.red}
- Button[2] = { xMax/2+1, 2, xMax-1 , yMax-1,"Runter",colors.red ,false,colors.yellow}
- function Background(col)
- mon.setBackgroundColor(col)
- for yPos = 1,yMax do
- for xPos = 1,xMax do
- mon.setCursorPos(xPos,yPos)
- mon.write(" ")
- end
- end
- end
- function printButton()
- for i = 1,#Button do
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(Button[i][6])
- for yPos = Button[i][2],Button[i][4] do
- for xPos = Button[i][1],Button[i][3] do
- mon.setCursorPos(xPos,yPos)
- mon.write(" ")
- end
- end
- mon.setCursorPos((Button[i][1]+Button[i][3])/2-#Button[i][5]/2,(Button[i][2]+Button[i][4])/2)
- mon.write(Button[i][5])
- end
- end
- function checkButton(xP,yP)
- for i = 1,#Button do
- if xP >= Button[i][1] and xP <= Button[i][3]
- and yP >= Button[i][2] and yP <= Button[i][4]
- then
- Button[i][7] = true
- end
- end
- end
- function move()
- for i = 1,#Button do
- if Button[i][7] then
- rs.setBundledOutput(Bside,Button[i][8])
- sleep(.5)
- rs.setBundledOutput(Bside,0)
- Button[i][7] = false
- end
- end
- end
- while true do
- Background(Bcol)
- printButton()
- event,_,xPos,yPos = os.pullEvent("monitor_touch")
- checkButton(xPos,yPos)
- move()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement