Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local t = {...}
- local bC = {}
- if t[1] == nil then
- print("Usage: ccpaint <gpu side>")
- error()
- end
- bC[1] = 224
- bC[2] = 224
- bC[3] = 224
- local gpu = peripheral.wrap(t[1])
- local removeM = false
- local screen = {}
- local mColor = 224
- local cColor = {}
- local oSet = {}
- local mouseDown = false
- oSet["x"] = 0
- oSet["y"] = 0
- cColor["r"] = 224
- cColor["g"] = 224
- cColor["b"] = 224
- function clearAll()
- screen = {}
- end
- function remove(x, y)
- if screen[x] == nil then
- return
- end
- screen[x][y] = nil
- gpu.setColorRGB(bC[1], bC[2], bC[3], x, y)
- end
- function clearScreen()
- local a, b = gpu.getSize()
- for c=0,a do
- for d=0,b do
- gpu.setColorRGB(bC[1], bC[2], bC[3], c, d)
- end
- end
- end
- function mem()
- local a = gpu.getTotalMemory()
- local b = gpu.getUsedMemory()
- local c = gpu.getFreeMemory()
- term.write("Used:")
- term.write(b)
- term.write(" Free:")
- term.write(c)
- term.write(" Total:")
- term.write(a)
- print()
- end
- function exit()
- clearScreen()
- error()
- end
- function getInput(t)
- term.write(t)
- local a = read()
- a = tonumber(a)
- if a > mColor then
- a = mColor
- end
- return tonumber(a)
- end
- function setBColor()
- bC[1] = getInput("R:")
- bC[2] = getInput("G:")
- bC[3] = getInput("B:")
- clearScreen()
- for a,b in pairs(screen) do
- for b,c in pairs(screen[a]) do
- gpu.setColorRGB(screen[a][b]["r"], screen[a][b]["g"], screen[a][b]["b"], a, b)
- end
- end
- end
- function setColor()
- cColor["r"] = getInput("R:")
- cColor["g"] = getInput("G:")
- cColor["b"] = getInput("B:")
- end
- function setXYColor(x, y)
- if screen[x] == nil then
- screen[x] = {}
- end
- screen[x][y] = {}
- screen[x][y]["r"] = cColor["r"]
- screen[x][y]["g"] = cColor["g"]
- screen[x][y]["b"] = cColor["b"]
- gpu.setColorRGB(screen[x][y]["r"], screen[x][y]["g"], screen[x][y]["b"], x, y)
- end
- function setBeginPoint()
- term.write("Click a Point on the Monitor")
- print()
- local a, b, c, d = os.pullEventRaw("monitor_down")
- oSet["x"] = c
- oSet["y"] = d
- term.write("Point Set To: ")
- term.write(oSet["x"])
- term.write(" ")
- term.write(oSet["y"])
- print()
- end
- function save()
- term.write("Save To:")
- local a = read()
- print()
- term.write("Image Name:")
- local t = {}
- local n = read()
- local file = fs.open(a, "w")
- for a,b in pairs(screen) do
- t[a] = {}
- for b,c in pairs(screen[a]) do
- t[a][b] = {}
- t[a][b]["r"] = screen[a][b]["r"]
- t[a][b]["g"] = screen[a][b]["g"]
- t[a][b]["b"] = screen[a][b]["b"]
- end
- end
- file.write(n)
- file.write("=")
- file.write(textutils.serialize(t))
- file.write("\n")
- file.close()
- end
- function input()
- local a
- local b
- local c
- local d
- while true do
- a, b, c, d = os.pullEventRaw()
- if a == "char" then
- if b == "q" then
- exit()
- elseif b == "s" then
- save()
- elseif b == "c" then
- setColor()
- elseif b == "o" then
- setBeginPoint()
- elseif b == "m" then
- mem()
- elseif b == "r" then
- term.write("Remove Mode ")
- if removeM then
- term.write("Off")
- removeM = false
- else
- term.write("On")
- removeM = true
- end
- print()
- elseif b == "b" then
- setBColor()
- elseif b == "n" then
- clearAll()
- clearScreen()
- end
- elseif a == "monitor_down" then
- mouseDown = true
- if removeM then
- remove(c, d)
- else
- setXYColor(c, d)
- end
- elseif a == "monitor_up" then
- mouseDown = false
- elseif a == "monitor_move" and mouseDown then
- if removeM then
- remove(c, d)
- else
- setXYColor(c, d)
- end
- end
- end
- end
- function main()
- clearScreen()
- input()
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment