Advertisement
Guest User

Untitled

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