Guest User

ccpaint

a guest
Nov 6th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.80 KB | None | 0 0
  1. local t = {...}
  2. local bC = {}
  3. if t[1] == nil then
  4.   print("Usage: ccpaint <gpu side>")
  5.   error()
  6. end
  7. bC[1] = 224
  8. bC[2] = 224
  9. bC[3] = 224
  10. local gpu = peripheral.wrap(t[1])
  11. local removeM = false
  12. local screen = {}
  13. local mColor = 224
  14. local cColor = {}
  15. local oSet = {}
  16. local mouseDown = false
  17. oSet["x"] = 0
  18. oSet["y"] = 0
  19. cColor["r"] = 224
  20. cColor["g"] = 224
  21. cColor["b"] = 224
  22. function clearAll()
  23.   screen = {}
  24. end
  25. function remove(x, y)
  26.   if screen[x] == nil then
  27.     return
  28.   end
  29.   screen[x][y] = nil
  30.   gpu.setColorRGB(bC[1], bC[2], bC[3], x, y)
  31. end
  32. function clearScreen()
  33.   local a, b = gpu.getSize()
  34.   for c=0,a do
  35.     for d=0,b do
  36.       gpu.setColorRGB(bC[1], bC[2], bC[3], c, d)
  37.     end
  38.   end
  39. end
  40. function mem()
  41.   local a = gpu.getTotalMemory()
  42.   local b = gpu.getUsedMemory()
  43.   local c = gpu.getFreeMemory()
  44.   term.write("Used:")
  45.   term.write(b)
  46.   term.write(" Free:")
  47.   term.write(c)
  48.   term.write(" Total:")
  49.   term.write(a)
  50.   print()
  51. end
  52. function exit()
  53.   clearScreen()
  54.   error()
  55. end
  56. function getInput(t)
  57.   term.write(t)
  58.   local a = read()
  59.   a = tonumber(a)
  60.   if a > mColor then
  61.     a = mColor
  62.   end
  63.   return tonumber(a)
  64. end
  65. function setBColor()
  66.   bC[1] = getInput("R:")
  67.   bC[2] = getInput("G:")
  68.   bC[3] = getInput("B:")
  69.   clearScreen()
  70.   for a,b in pairs(screen) do
  71.     for b,c in pairs(screen[a]) do
  72.       gpu.setColorRGB(screen[a][b]["r"], screen[a][b]["g"], screen[a][b]["b"], a, b)
  73.     end
  74.   end
  75. end
  76. function setColor()
  77.   cColor["r"] = getInput("R:")
  78.   cColor["g"] = getInput("G:")
  79.   cColor["b"] = getInput("B:")
  80. end
  81. function setXYColor(x, y)
  82.   if screen[x] == nil then
  83.     screen[x] = {}
  84.   end
  85.   screen[x][y] = {}
  86.   screen[x][y]["r"] = cColor["r"]
  87.   screen[x][y]["g"] = cColor["g"]
  88.   screen[x][y]["b"] = cColor["b"]
  89.   gpu.setColorRGB(screen[x][y]["r"], screen[x][y]["g"], screen[x][y]["b"], x, y)
  90. end
  91. function setBeginPoint()
  92.   term.write("Click a Point on the Monitor")
  93.   print()
  94.   local a, b, c, d = os.pullEventRaw("monitor_down")
  95.   oSet["x"] = c
  96.   oSet["y"] = d
  97.   term.write("Point Set To: ")
  98.   term.write(oSet["x"])
  99.   term.write(" ")
  100.   term.write(oSet["y"])
  101.   print()
  102. end
  103. function save()
  104.   term.write("Save To:")
  105.   local a = read()
  106.   print()
  107.   term.write("Image Name:")
  108.   local t = {}
  109.   local n = read()
  110.   local file = fs.open(a, "w")
  111.   for a,b in pairs(screen) do
  112.     t[a] = {}
  113.     for b,c in pairs(screen[a]) do
  114.       t[a][b] = {}
  115.       t[a][b]["r"] = screen[a][b]["r"]
  116.       t[a][b]["g"] = screen[a][b]["g"]
  117.       t[a][b]["b"] = screen[a][b]["b"]
  118.     end
  119.   end
  120.   file.write(n)
  121.   file.write("=")
  122.   file.write(textutils.serialize(t))
  123.   file.write("\n")
  124.   file.close()
  125. end
  126. function input()
  127.   local a
  128.   local b
  129.   local c
  130.   local d
  131.   while true do
  132.     a, b, c, d = os.pullEventRaw()
  133.     if a == "char" then
  134.       if b == "q" then
  135.         exit()
  136.       elseif b == "s" then
  137.         save()
  138.       elseif b == "c" then
  139.         setColor()
  140.       elseif b == "o" then
  141.         setBeginPoint()
  142.       elseif b == "m" then
  143.         mem()
  144.       elseif b == "r" then
  145.         term.write("Remove Mode ")
  146.         if removeM then
  147.           term.write("Off")
  148.           removeM = false
  149.         else
  150.           term.write("On")
  151.           removeM = true
  152.         end
  153.         print()
  154.       elseif b == "b" then
  155.         setBColor()
  156.       elseif b == "n" then
  157.         clearAll()
  158.         clearScreen()
  159.       end
  160.     elseif a == "monitor_down" then
  161.       mouseDown = true
  162.       if removeM then
  163.         remove(c, d)
  164.       else
  165.         setXYColor(c, d)
  166.       end
  167.     elseif a == "monitor_up" then
  168.       mouseDown = false
  169.     elseif a == "monitor_move" and mouseDown then
  170.       if removeM then
  171.         remove(c, d)
  172.       else
  173.         setXYColor(c, d)
  174.       end
  175.     end
  176.   end
  177. end
  178. function main()
  179.   clearScreen()
  180.   input()
  181. end
  182. main()
Advertisement
Add Comment
Please, Sign In to add comment