Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Set up variables
- local attachedMonitor = peripheral.wrap("top")
- local defaultBackgroundColor =colors.black
- local defaultTextColor=colors.white
- local backgroundColorNormal = colors.blue
- local backgroundColorPressed = colors.red
- local textColorNormal = colors.white
- local textColorPressed = colors.yellow
- local width=10
- local height = 3
- local label="Button"
- local startColumn=3
- local startRow=3
- -- Set up Monitor
- attachedMonitor.setBackgroundColor(defaultBackgroundColor)
- attachedMonitor.setTextColor(defaultTextColor)
- --attachedMonitor.setTextScale(.5)
- attachedMonitor.clear()
- -- Display the button Background
- attachedMonitor.setBackgroundColor(backgroundColorNormal)
- for row = startRow,startRow+height-1 do
- attachedMonitor.setCursorPos(startColumn,row)
- attachedMonitor.write(string.rep(" ",width))
- end
- --Display the label (auto centered)
- attachedMonitor.setTextColor (textColorNormal)
- attachedMonitor.setCursorPos(startColumn + math.floor((width - #label)/2),startRow)
- attachedMonitor.write(label)
- -- reset to original text/background colors
- attachedMonitor.setBackgroundColor(defaultBackgroundColor)
- attachedMonitor.setTextColor(defaultTextColor)
- -- sleep and then let's do it again with our "pressed" colors.
- sleep(3)
- attachedMonitor.setBackgroundColor(backgroundColorPressed)
- for row = startRow,startRow+height-1 do
- attachedMonitor.setCursorPos(startColumn,row)
- attachedMonitor.write(string.rep(" ",width))
- end
- attachedMonitor.setTextColor(textColorPressed)
- attachedMonitor.setCursorPos(startColumn + math.floor((width - #label)/2),startRow)
- attachedMonitor.write(label)
- attachedMonitor.setBackgroundColor(defaultBackgroundColor)
- attachedMonitor.setTextColor(defaultTextColor)
- attachedMonitor.setCursorPos(1,8)
- attachedMonitor.write("Done.")
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement