Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------Paint program-----------------------------
- --Affichage--
- function displayLayer(building, height, width)
- local layer = 1
- local mat = 0
- for i=1,width do
- for j=1,height do
- mat = building[layer][i][j]
- term.setCursorPos(i,j)
- if mat == 0 then
- term.setBackgroundColor(1)
- elseif mat == 1 then
- term.setBackgroundColor(16384)
- else
- term.setBackgroundColor(8192)
- end
- term.write(" ")
- end
- end
- end
- --Prgramme principal
- 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
- --Affichage
- displayLayer(building, termHeight-1, termWidth)
- term.setBackgroundColor(32768)
- term.setCursorPos(1,termHeight)
- write("^Turtle Couche " .. cLayer .. "/" .. hauteur .. " Mat : " .. mat)
- event, key, x, y = os.pullEvent()
- --Traitement de l'event
- if event == "mouse_drag" or event == "mouse_click" then --Souris
- if y < termHeight then
- if key == 1 then
- building[cLayer][x][y] = mat
- elseif key == 2 then
- building[cLayer][x][y] = 0
- end
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement