Advertisement
PandaDoddo72Rus

Рекурсивная заливка

Dec 22nd, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.53 KB | None | 0 0
  1. local cmp = require("component")
  2. local gpu = cmp.gpu
  3. local event = require("event")
  4. local serialization = require("serialization")
  5. local unicode=require("unicode")
  6. local filesystem = require("filesystem")
  7. local shell = require("shell")
  8. local term = require("term")
  9. local uc=require('unicode')
  10. local computer = require("computer")
  11. local keyboard = require("keyboard")
  12. a,b=gpu.getResolution()
  13. local oldB=gpu.getBackground()
  14. local oldF=gpu.getForeground()
  15. local args={...}
  16. local len = uc.len
  17. local sub = uc.sub
  18.  
  19. function drawMem()
  20. gpu.fill(1,1,10,1,' ')
  21. gpu.set(1,1,tostring(computer.freeMemory()))
  22. end
  23. log = {}
  24.  
  25. function old()
  26.  gpu.setBackground(oldB)
  27.  gpu.setForeground(oldF)
  28. end
  29.  
  30. function sq(x,y,w,h,col)
  31.   gpu.setBackground(col)
  32.   gpu.fill(x,y,w,h," ")
  33. end
  34.  
  35. function req(x,y,back)
  36.   find = false
  37.   p = {gpu.get(x,y)}
  38.   if p[3] == back then
  39.     gpu.set(x,y,' ')
  40.     find = true
  41.   end
  42.   drawMem()
  43.   return find
  44. end
  45.  
  46. function addLog(l)
  47.   log[#log+1]=l
  48. end
  49.  
  50. function check(back)
  51.   ret = true
  52.   if loc.x ~= a and req(loc.x+1,loc.y,back) == true then
  53.     addLog('x+1')
  54.     loc.x=loc.x+1
  55.   elseif loc.x ~= 1 and req(loc.x-1,loc.y,back) == true then
  56.     addLog('x-1')
  57.     loc.x=loc.x-1
  58.   elseif loc.y ~= b and req(loc.x,loc.y+1,back) == true then
  59.     addLog('y+1')
  60.     loc.y=loc.y+1
  61.   elseif loc.y ~= 1 and req(loc.x,loc.y-1,back) == true then
  62.     addLog('y-1')
  63.     loc.y=loc.y-1
  64.   else
  65.     h = log[#log]
  66.     if #log < 1 then
  67.       ret = false
  68.     elseif h == 'x-1' then
  69.       loc.x=loc.x+1
  70.       table.remove(log)
  71.     elseif h == 'x+1' then
  72.       loc.x=loc.x-1
  73.       table.remove(log)
  74.     elseif h == 'y-1' then
  75.       loc.y=loc.y+1
  76.       table.remove(log)
  77.     elseif h == 'y+1' then
  78.       loc.y=loc.y-1
  79.       table.remove(log)
  80.     end
  81.   end
  82.   return ret
  83. end
  84.  
  85.  
  86. function kost()
  87.   u =  gpu.getBackground()
  88.   u1 =  gpu.getForeground()
  89.   o ={ gpu.get(1,1)}
  90.   gpu.set(1,1,' ')
  91.   k = {gpu.get(1,1)}
  92.   true_color = k[3]
  93.   gpu.setBackground(o[3])
  94.   gpu.setForeground(o[2])
  95.   gpu.set(1,1,o[1])
  96.   gpu.setBackground(u)
  97.   gpu.setForeground(u1)
  98. end
  99.  
  100. shell.execute('draw pic.pic')
  101.  
  102. gpu.setBackground(0x00FF00)
  103. kost()
  104.  
  105. while true do
  106.  -- gpu.setBackground(math.random(0x222222,0xFFFFFF))
  107.   --e = {event.pull("touch")}
  108.   e= {0,0,math.random(1,a),math.random(1,b)}
  109.   t = {gpu.get(e[3],e[4])}
  110.   loc={x=e[3],y=e[4]}
  111.   log = {}
  112.   g = gpu.getBackground()
  113.   if t[3] ~= true_color then
  114.     while true do
  115.       if check(t[3]) and g ~= t[3] then
  116.  
  117.       else
  118.         break
  119.       end
  120.     end
  121.   end
  122. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement