Advertisement
Laine_prikol

LainePaintOC

Mar 9th, 2017
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.27 KB | None | 0 0
  1. -- Paint by Laine_prikol
  2. local component = require("component")
  3. local event = require("event")
  4. local term = require("term")
  5. local gpu = component.gpu
  6. local gpic = require("gpic")
  7. local computer = require("computer")
  8. local filesystem = require("filesystem")
  9. local args = {...}
  10. fillscroll = 1
  11. color = 0
  12. fill = "█"
  13. timer = 5
  14. colorcustom = 0
  15. function redrawAll()
  16.     term.clear()
  17.     term.setCursor(1,1)
  18.     print("[S] [C] [+] FILL [-] [+] Color [-] [O] [N]")
  19. end
  20. redrawAll()
  21. -- Таймер
  22. function offtext()
  23. timer = timer - 1
  24.     if timer == 1 then
  25.     gpu.set(1,25, "                        ") -- Не понял как сделать очистку строки (term.clearLine() не работает)
  26.     end
  27.     if timer == 0 then
  28.     timer = 0
  29.     end
  30. end
  31.  
  32. function fillswitch(zalivka, scroll, filltypetext)
  33.     if fillscroll == scroll then
  34.     fill = zalivka
  35.     gpu.set(1, 25, filltypetext)
  36.     timer = 5
  37.     end
  38. end
  39. function colorswitch(colornum, colorscroll, colortext)
  40.     if color == colorscroll then -- White
  41.     gpu.setForeground(colornum)
  42.     gpu.set(63, 1, colortext)
  43.     end
  44. end
  45.  
  46. function checkFill()   
  47.     gpu.set(1, 1, "[S] [C] [+] FILL [-] [+] Color [-] [O] [N]")
  48.     gpu.set(1, 25, "Fill type: Standard   ")
  49.     timer = 5
  50.     fillswitch("█", 1, "Fill type: Standard   ")
  51.     fillswitch("#", 2, "Fill type: Hash   ")
  52.     fillswitch("@", 3, "Fill type: Circle1   ")
  53.     fillswitch(".", 4, "Fill type: Dot   ")
  54.     fillswitch(":", 5, "Fill type: Dots   ")
  55.     fillswitch(" ", 6, "Fill type: Eraser   ")
  56.     fillswitch("●", 7, "Fill type: Circle2   ")
  57.     fillswitch("░", 8, "Fill type: Semi-Transparent   ")
  58.     if fillscroll == 9 then
  59.     local file = io.open("customFills.cfg", "r")
  60.     fill = file:read("*a")
  61.     gpu.set(1, 25, "Fill type: Custom (create file customFills.cfg) ")
  62.     timer = 5
  63.     file:close()
  64.     end
  65.     if fillscroll == 10 then
  66.     local file1 = io.open("customFills1.cfg", "r")
  67.     fill = file1:read("*a")
  68.     gpu.set(1, 25, "Fill type: Custom1 (create file customFills1.cfg) ")
  69.     timer = 5
  70.     file1:close()
  71.     end
  72. end
  73. function checkColor()
  74.     gpu.setForeground(0xffffff)
  75.     gpu.set(1, 1, "[S] [C] [+] FILL [-] [+] Color [-] [O] [N]")
  76.     colorswitch(0xffffff, 0, "Color: whilte  ")
  77.     colorswitch(0xff0000, 1, "Color: Red  ")
  78.     colorswitch(0x2fff00, 2, "Color: Green  ")
  79.     colorswitch(0x0011ff, 3, "Color: Blue  ")
  80.     colorswitch(0xf0ff00, 4, "Color: Yellow  ")
  81.     colorswitch(0x898989, 5, "Color: Grey  ")
  82.     colorswitch(0xff9191, 6, "Color: Light red   ")
  83.     colorswitch(0xfd00ff, 7, "Color: Purple   ")
  84.     colorswitch(0xFF1493, 8, "Color: Pink   ")
  85.     colorswitch(0x0b6503, 9, "Color: Dark green  ")
  86.     colorswitch(0x0b6503, 10, "Color: Turquoise  ")
  87.     colorswitch(0x00dfff, 11, "Color: Light blue  ")
  88.     if color == 12 then -- Custom 1
  89.     local file2 = io.open("colors1.cfg", "r")
  90.     colorcustom = file2:read("*a")
  91.     gpu.setForeground(colorcustom)
  92.     gpu.set(63, 1, "Color: Custom(Create colors1.cfg)  ")
  93.     file2:close()
  94.     end
  95.     if color == 13 then -- Custom 2
  96.     local file3 = io.open("colors2.cfg", "r")
  97.     colorcustom = file3:read("*a")
  98.     gpu.setForeground(colorcustom)
  99.     gpu.set(63, 1, "Color: Custom(Create colors2.cfg)  ")
  100.     file3:close()
  101.     end
  102.     if color == 14 then -- Custom 3
  103.     local file4 = io.open("colors3.cfg", "r")
  104.     colorcustom = file4:read("*a")
  105.     gpu.setForeground(colorcustom)
  106.     gpu.set(63, 1, "Color: Custom(Create colors3.cfg)  ")
  107.     file4:close()
  108.     end
  109. end
  110. while true do
  111.   -- Чтение пикселей
  112.   local id, _, x, y = event.pullMultiple("touch", "drag")
  113.   if id == "touch" then
  114.   gpu.set(x, y, fill)
  115.   checkColor()
  116.   offtext()
  117.   end
  118.   if id == "drag" then
  119.   gpu.set(x, y, fill)
  120.   checkColor()
  121.   offtext()
  122.   end
  123.   if x == 6 and y == 1 then -- Выход
  124.   term.clear()
  125.   os.exit()
  126.   end
  127.   if x == 10 and y == 1 then -- Прогрутка типов заливки
  128.   fillscroll = fillscroll + 1
  129.   checkFill()
  130.     if fillscroll == 8 then
  131.     fillscroll = 8 -- Это чтобы переменная не ушла сильно в плюс (Не понял как сделать по-другому)
  132.     checkFill()
  133.     end
  134.   end
  135.   if x == 19 and y == 1 then -- Прогрутка типов заливки
  136.   fillscroll = fillscroll - 1
  137.    checkFill()
  138.     if fillscroll == 0 then
  139.     fillscroll = 1 -- Это чтобы переменная не ушла в минус (Не понял как сделать по-другому)
  140.     checkFill()
  141.     end
  142.   end
  143.   if x == 2 and y == 1 then -- Сохранение
  144.   local picture = gpic.new(1, 2, args[2], args[3])
  145.   gpic.write(picture,args[1])
  146.   computer.beep(880, 0.5)
  147.   end
  148.   if x == 37 and y == 1 then -- Загрузка
  149.   local image = gpic.read(args[1])
  150.   gpic.draw(1, 2, image)
  151.   computer.beep(500, 0.5)
  152.   end
  153.   if x == 23 and y == 1 then -- Прогрутка цветов
  154.   color = color + 1
  155.   checkColor()
  156.     if color == 14 then
  157.     color = 14 -- Это чтобы переменная не ушла сильно в плюс (Не понял как сделать по-другому)
  158.     checkFill()
  159.     end
  160.   end
  161.   if x == 33 and y == 1 then -- Прогрутка цветов
  162.   color = color - 1
  163.    checkFill()
  164.     if color == 0 then
  165.     color = 0 -- Это чтобы переменная не ушла в минус (Не понял как сделать по-другому)
  166.     checkColor()
  167.     end
  168.   end
  169.   if x == 41 and y == 1 then -- Новый файл
  170.   term.clear()
  171.   redrawAll()
  172.   end
  173. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement