Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Paint program--
- function paint(hauteur)
- --Preparation de l'affichage de l'image--
- term.setBackgroundColor(1)
- term.clear()
- term.setCursorPos(1,1)
- term.setCursorBlink(false)
- local termHeight
- local termWidth
- termWidth, termHeight = term.getSize()
- --Gestion Event
- local event = ""
- local key = 0
- local x = 0
- local y = 0
- --Données du batiment
- local mat = 1
- local cLayer = 1
- local building = {} --Creation de matrice 3D
- for i=1,hauteur do
- building[i] = {} --Creation de la matrice 2D
- for j=1,termWidth do
- building[i][j] = {} --Création de la ligne
- for k=1,termHeight-1 do
- building[i][j][k] = 0
- end
- end
- end
- --Boucle principale
- while key ~= 28 do
- event, key, x, y = os.pullEvent()
- --Affichage
- term.setBackgroundColor(32768)
- term.setCursorPos(1,termHeight)
- write("^Turtle Couche " .. cLayer .. "/" .. hauteur)
- --Traitement de l'event
- if event == "mouse_drag" or event == "mouse_click" then --Souris
- if y < termHeight-1 then
- term.setCursorPos(x,y)
- if key == 1 then
- term.setBackgroundColor(32768)
- building[cLayer][x][y] = mat
- elseif key == 2 then
- term.setBackgroundColor(1)
- building[cLayer][x][y] = 0
- end
- term.write(" ")
- end
- elseif event == "key" then --Clavier
- if key == 42 then
- if mat == 1 then
- mat = 2
- else
- mat = 1
- end
- end
- end
- end
- --Preparation de l'affichage de la console--
- term.setBackgroundColor(32768)
- term.clear()
- term.setCursorBlink(true)
- term.setCursorPos(1,1)
- return building
- end
- --Main--
- local hauteur = nil
- local building
- local event = ""
- local key = 0
- local x = 0
- local y = 0
- term.clear()
- term.setCursorPos(1,1)
- while hauteur == nil or hauteur < 1 do
- print("Indiquez la hauteur de votre batiment")
- hauteur = tonumber(read())
- end
- building = paint(hauteur)
- print(building)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement