Advertisement
Guest User

Untitled

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