Advertisement
Guest User

tde-paint [OpenComputers blocks painter program (RUS)]

a guest
Aug 15th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 KB | None | 0 0
  1. tArgs = {...}
  2. if #tArgs ~= 1 then
  3.   error("USAGE: tde-paint <filename>")
  4. end
  5. dofile("./tde-apis")
  6. len = string.len
  7. term = require("term")
  8. local event = require("event")
  9. setpos = term.setCursor
  10. setbg(0xFFFFFF)
  11. x,y = getres()
  12. i = 2
  13. xfill(1,1,x,y, " ")
  14. setbg(0x000000)
  15. xfill(1,1,x,1, " ")
  16. a = {true, true, true, true, true}
  17. a[1] = 0
  18. --Localisation:
  19.  
  20. nblock = "[Новый блок]" --[New Block]
  21. save = "[Сохранить]"  --[Save]
  22. quit = "[Выйти]"  --[Quit]
  23.  
  24. --End of localisation
  25. x1nblock = 1
  26. x2nblock = 12
  27. x1save = x2nblock+1
  28. x2save = x1save+10
  29. x1quit = x2save+1
  30. x2quit = x1quit+6
  31. state = 1
  32. alw = 0
  33. while true do
  34.   setbg(0xFFFFFF)
  35.   if alw == 0 then
  36.     xfill(1,1,x,y, " ")
  37.   end
  38.   if (a[1] > 0) and (state == 1) then
  39.     drawImage(a)
  40.     if alw == 0 then
  41.       alw = 1
  42.     end
  43.   end
  44.   setbg(0x000000)
  45.   xfill(1,1,x,1, " ")
  46.   if state == 1 then
  47.     setpos(1,1)
  48.     write(nblock)
  49.     write(" ")
  50.     write(save)
  51.     write(" ")
  52.     write(quit)
  53.   elseif state == 2 then
  54.     setbg(0x000000)
  55.     xfill(1,1,x,1," ")
  56.     setpos(1,1)
  57.     write("Выберите 1 позицию блока")
  58.   elseif state == 3 then
  59.     setbg(0x000000)
  60.     xfill(1,1,x,1," ")
  61.     setpos(1,1)
  62.     write("Выберите 2 позицию блока")
  63.   elseif state == 4 then
  64.     setbg(0x000000)
  65.     xfill(1,1,x,1," ")
  66.     setpos(1,1)
  67.     write("Цвет: ")
  68.     a[i] = tonumber(io.read())
  69.     i = i + 1
  70.     state = 1
  71.   elseif state == 5 then
  72.     setbg(0x000000)
  73.     xfill(1,1,x,1," ")
  74.     setpos(1,1)
  75.     write("Сохранение изображения...")
  76.     f = io.open(tArgs[1], "w")
  77.     for k = 1 , a[1]*5+1 do
  78.       f:write(tostring(a[k]).."\n")
  79.     end
  80.     f:close()
  81.     state = 1
  82.     setbg(0x000000)
  83.     xfill(1,1,x,1," ")
  84.     setpos(1,1)
  85.     write(nblock)
  86.     write(" ")
  87.     write(save)
  88.     write(" ")
  89.     write(quit)
  90.   end
  91.   local event, adress, arg1,arg2,arg3 = event.pull()
  92.   if event == "touch" then
  93.     X = arg1
  94.     Y = arg2
  95.     if state == 1 then
  96.       if (X >= x1nblock) and (X <= x2nblock) and (state == 1) then
  97.         a[1] = a[1] + 1
  98.         state = 2
  99.       elseif (X >= x1save) and (X <= x2save) then
  100.         state = 5
  101.       elseif (X >= x1quit) and (X <= x2quit) then
  102.         setbg(0x000000)
  103.         gl.setForeground(0xFFFFFF)
  104.         break
  105.       end
  106.     elseif state == 2 then
  107.       a[i] = X
  108.       a[i+1] = Y
  109.       i = i + 2
  110.       state = 3
  111.     elseif state == 3 then
  112.       a[i] = X
  113.       a[i+1] = Y
  114.       i = i + 2
  115.       state = 4
  116.     end
  117.   end
  118. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement