Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tArgs = {...}
- if #tArgs ~= 1 then
- error("USAGE: tde-paint <filename>")
- end
- dofile("./tde-apis")
- len = string.len
- term = require("term")
- local event = require("event")
- setpos = term.setCursor
- setbg(0xFFFFFF)
- x,y = getres()
- i = 2
- xfill(1,1,x,y, " ")
- setbg(0x000000)
- xfill(1,1,x,1, " ")
- a = {true, true, true, true, true}
- a[1] = 0
- --Localisation:
- nblock = "[Новый блок]" --[New Block]
- save = "[Сохранить]" --[Save]
- quit = "[Выйти]" --[Quit]
- --End of localisation
- x1nblock = 1
- x2nblock = 12
- x1save = x2nblock+1
- x2save = x1save+10
- x1quit = x2save+1
- x2quit = x1quit+6
- state = 1
- alw = 0
- while true do
- setbg(0xFFFFFF)
- if alw == 0 then
- xfill(1,1,x,y, " ")
- end
- if (a[1] > 0) and (state == 1) then
- drawImage(a)
- if alw == 0 then
- alw = 1
- end
- end
- setbg(0x000000)
- xfill(1,1,x,1, " ")
- if state == 1 then
- setpos(1,1)
- write(nblock)
- write(" ")
- write(save)
- write(" ")
- write(quit)
- elseif state == 2 then
- setbg(0x000000)
- xfill(1,1,x,1," ")
- setpos(1,1)
- write("Выберите 1 позицию блока")
- elseif state == 3 then
- setbg(0x000000)
- xfill(1,1,x,1," ")
- setpos(1,1)
- write("Выберите 2 позицию блока")
- elseif state == 4 then
- setbg(0x000000)
- xfill(1,1,x,1," ")
- setpos(1,1)
- write("Цвет: ")
- a[i] = tonumber(io.read())
- i = i + 1
- state = 1
- elseif state == 5 then
- setbg(0x000000)
- xfill(1,1,x,1," ")
- setpos(1,1)
- write("Сохранение изображения...")
- f = io.open(tArgs[1], "w")
- for k = 1 , a[1]*5+1 do
- f:write(tostring(a[k]).."\n")
- end
- f:close()
- state = 1
- setbg(0x000000)
- xfill(1,1,x,1," ")
- setpos(1,1)
- write(nblock)
- write(" ")
- write(save)
- write(" ")
- write(quit)
- end
- local event, adress, arg1,arg2,arg3 = event.pull()
- if event == "touch" then
- X = arg1
- Y = arg2
- if state == 1 then
- if (X >= x1nblock) and (X <= x2nblock) and (state == 1) then
- a[1] = a[1] + 1
- state = 2
- elseif (X >= x1save) and (X <= x2save) then
- state = 5
- elseif (X >= x1quit) and (X <= x2quit) then
- setbg(0x000000)
- gl.setForeground(0xFFFFFF)
- break
- end
- elseif state == 2 then
- a[i] = X
- a[i+1] = Y
- i = i + 2
- state = 3
- elseif state == 3 then
- a[i] = X
- a[i+1] = Y
- i = i + 2
- state = 4
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement