LUAdev

Getting your values

Mar 10th, 2013
1,204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.14 KB | None | 0 0
  1. -- All credits go to the author, Engineer
  2. term.clear()
  3. term.setCursorPos(1,1)
  4.  
  5. local buttons = { "left top", "right top", "left bottom", "right bottom" }
  6. local cButton = { }
  7.  
  8. function display( input, button )
  9.     term.setBackgroundColor( colors.black )
  10.     term.setCursorPos(1,19)
  11.     term.clearLine()
  12.     if button then
  13.         write( input )
  14.     else
  15.         write( "Current button: ".. input )
  16.     end
  17. end
  18.  
  19. print( "Click everywhere on the screen to place a marker." )
  20. for i = 1, 3 do
  21.     display( buttons[i] )
  22.     while true do
  23.         local evt, button, x, y = os.pullEvent( "mouse_click" )
  24.         if buttons[i] == "left top" then
  25.             paintutils.drawPixel( x, y, colors.orange )
  26.             table.insert( cButton, x )
  27.             table.insert( cButton, y )
  28.             break
  29.         elseif buttons[i] == "right top" and x > cButton[1] and y == cButton[2] then
  30.             paintutils.drawPixel( x, y, colors.magenta )
  31.             table.insert( cButton, x )
  32.             break
  33.         elseif buttons[i] == "left bottom" and y > cButton[2] and x == cButton[1] then
  34.             paintutils.drawPixel( x, y, colors.lightBlue )
  35.             table.insert( cButton, y )
  36.             paintutils.drawPixel( cButton[3], cButton[4], colors.yellow )
  37.             display( buttons[4] )
  38.             break
  39.         end
  40.     end
  41. end
  42.  
  43. sleep(1)
  44. term.setBackgroundColor( 32768 )
  45. term.clear()
  46. term.setCursorPos( 1,1 )
  47. print( "Your button will be printed shortly" )
  48. sleep(1.5)
  49. term.clear()
  50. paintutils.drawLine( tonumber( cButton[1] ), tonumber( cButton[2] ), tonumber( cButton[3] ), tonumber( cButton[2] ), 512 )
  51. paintutils.drawLine( tonumber( cButton[1] ), tonumber( cButton[4] ), tonumber( cButton[3] ), tonumber( cButton[4] ), 512 )
  52. paintutils.drawLine( tonumber( cButton[1] ), tonumber( cButton[2] ), tonumber( cButton[1] ), tonumber( cButton[4] ), 512 )
  53. paintutils.drawLine( tonumber( cButton[3] ), tonumber( cButton[2] ), tonumber( cButton[3] ), tonumber( cButton[4] ), 512 )
  54. display( "Hit enter to continue ", true )
  55.  
  56. while true do
  57.     local evt, key = os.pullEvent( "key" )
  58.     if key == 28 then
  59.         break
  60.     end
  61. end
  62.  
  63. term.clear()
  64. term.setCursorPos( 1,1 )
  65.  
  66. print( "Your values\n" )
  67.  
  68. print( "xMin = " .. cButton[1] )
  69. print( "xMax = " .. cButton[3] )
  70. print( "yMin = " .. cButton[2] )
  71. print( "yMax = " .. cButton[4] )
Advertisement
Add Comment
Please, Sign In to add comment