Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. --Paint program--
  2. function paint(hauteur)
  3. --Preparation de l'affichage de l'image--
  4. term.setBackgroundColor(1)
  5. term.clear()
  6. term.setCursorPos(1,1)
  7. term.setCursorBlink(false)
  8. local termHeight
  9. local termWidth
  10. termWidth, termHeight = term.getSize()
  11.  
  12. --Gestion Event
  13. local event = ""
  14. local key = 0
  15. local x = 0
  16. local y = 0
  17. --Données du batiment
  18. local mat = 1
  19. local cLayer
  20. local building = {} --Creation de matrice
  21. for i=1,termWidth do
  22. building[i] = {} --Creation de ligne
  23. for j=1,termHeight-1 do
  24. mt[i][j] = 0
  25. end
  26. end
  27. --Boucle principale
  28. while key ~= 28 do
  29.  
  30. event, key, x, y = os.pullEvent()
  31.  
  32. --Affichage
  33. term.setBackgroundColor(32768)
  34. term.setCursorPos(1,termHeight)
  35. write("^Turtle Couche " .. cLayer .. "/" .. hauteur)
  36. --Traitement de l'event
  37. if event == "mouse_drag" or event == "mouse_click" then --Souris
  38. if y < termHeight-1 then
  39. term.setCursorPos(x,y)
  40. if key == 1 then
  41. term.setBackgroundColor(32768)
  42. building[cLayer][x][y] = mat
  43. elseif key == 2 then
  44. term.setBackgroundColor(1)
  45. building[cLayer][x][y] = 0
  46. end
  47. term.write(" ")
  48. end
  49. elseif event == "key" then --Clavier
  50. if key == 42 then
  51. if mat == 1 then
  52. mat = 2
  53. else
  54. mat = 1
  55. end
  56. end
  57. end
  58. end
  59.  
  60. --Preparation de l'affichage de la console--
  61. term.setBackgroundColor(32768)
  62. term.clear()
  63. term.setCursorBlink(true)
  64. term.setCursorPos(1,1)
  65. return building
  66. end
  67.  
  68. --Main--
  69. local hauteur = nil
  70. local building
  71. local event = ""
  72. local key = 0
  73. local x = 0
  74. local y = 0
  75.  
  76. term.clear()
  77. term.setCursorPos(1,1)
  78. while hauteur == nil or hauteur < 1 do
  79. print("Indiquez la hauteur de votre batiment")
  80. hauteur = tonumber(read())
  81. end
  82. building = paint(hauteur)
  83. print(building)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement