Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local EU = require("ExtraUtilits")
- local gpu = require("component").gpu
- local unicode = require("unicode")
- local computer = require("computer")
- local term = require("term")
- local serialization = require("serialization")
- local close = false
- local field = {}
- local debugMode = false
- local w, h = gpu.getResolution()
- local width = 32
- local height = 16
- local x, y = math.floor(w / 2 - width / 2), math.floor(h / 2 - height / 2)
- local defaultBackground = 7767453
- local defaultForeground = 0xffffff
- local backgroundSymbol1 = unicode.char(10267)
- local backgroundSymbol2 = unicode.char(10468)
- local background = 0x000000
- local foreground = 0xffffff
- local symbol = " "
- local hotKeys = {
- [9] = function() close = true end
- }
- local r, g, b = 100, 100, 100
- local ss = {
- unicode.char(9582),
- unicode.char(9687)
- }
- ------------------------------------------------
- local function setScale()
- repeat
- width = tonumber(EU.ReadyUtilits.WFUIV2(70, 23, 15, "Enter width(1 - " .. w .. "):", "number"))
- until width and width > 0 and width <= w
- repeat
- height = tonumber(EU.ReadyUtilits.WFUIV2(70, 23, 15, "Enter height(1 - " .. h .. "):", "number"))
- until height and height > 0 and height <= h
- x, y = math.floor(160 / 2 - width / 2), math.floor(h / 2 - height / 2)
- end
- local function clear()
- for i = 1, width do
- field[i] = {}
- for j = 1, height do
- field[i][j] = {}
- end
- end
- end
- local function draw()
- for i = 1, width do
- for j = 1, height do
- if field[i][j].symbol then
- if field[i][j].background ~= gpu.getBackground() then gpu.setBackground(field[i][j].background) end
- if field[i][j].foreground ~= gpu.getForeground() then gpu.setForeground(field[i][j].foreground) end
- gpu.set(x + i, y + j, field[i][j].symbol)
- else
- if gpu.getBackground() ~= defaultBackground then gpu.setBackground(defaultBackground) end
- if gpu.getForeground() ~= defaultForeground then gpu.setForeground(defaultForeground) end
- if math.floor(i / 2) * 2 == i then
- gpu.set(x + i, y + j, backgroundSymbol1)
- else
- gpu.set(x + i, y + j, backgroundSymbol2)
- end
- end
- end
- end
- end
- local function pull()
- while not close do
- local signal = {computer.pullSignal()}
- if signal[1] == "touch" or signal[1] == "drag" then
- local sx, sy = signal[3], signal[4]
- if sx <= x + width and sx > x and sy <= y + height and sy > y then
- field[math.floor(sx - x)][math.floor(sy - y)].background = background
- field[math.floor(sx - x)][math.floor(sy - y)].foreground = foreground
- field[math.floor(sx - x)][math.floor(sy - y)].symbol = symbol
- if gpu.getBackground ~= background then gpu.setBackground(background) end
- if gpu.getForeground ~= foreground then gpu.setForeground(foreground) end
- gpu.set(sx, sy, symbol)
- if debugMode then
- gpu.setBackground(0x161616)
- gpu.fill(1, 1, 10, 6, " ")
- gpu.setForeground(0x00ffff)
- gpu.set(1, 1, "sx: " .. sx)
- gpu.set(1, 2, "sy: " .. sy)
- gpu.set(1, 3, "x: " .. x)
- gpu.set(1, 4, "y: " .. y)
- gpu.set(1, 5, "width: " .. width)
- gpu.set(1, 6, "height: " .. height)
- end
- end
- elseif signal[1] == "key_down" then
- local key, key2 = signal[3], signal[4]
- local char = unicode.char(key)
- for hotKey, func in pairs(hotKeys) do
- if hotKey == key or hotKey == char or type(hotKeys[hotKey]) == "table" and hotKeys[hotKey].key2 == key2 then
- if type(hotKeys[hotKey]) == "table" then
- hotKeys[hotKey].func()
- else
- func()
- end
- end
- end
- end
- end
- end
- local function menu()
- local buttons = {}
- local function changeBackground()
- background = EU.ReadyUtilits.RGBPalette(65, 23, "", background)
- buttons.close = true
- gpu.setBackground(0x323232)
- gpu.setForeground(background)
- gpu.set(7, 1, ss[2])
- end
- local function changeForeground()
- foreground = EU.ReadyUtilits.RGBPalette(65, 23, "", foreground)
- buttons.close = true
- gpu.setBackground(0x323232)
- gpu.setForeground(foreground)
- gpu.set(2, 7, ss[2])
- end
- local function save()
- local path = EU.ReadyUtilits.WFUIV2(70, 23, 15, "Enter path to saving:")
- local func, reason = loadfile("/paint_modules/save.lua")
- if func then
- func(field, width, height, path)
- else
- error("Error with running save module: " .. reason)
- end
- buttons.close = true
- end
- local function load()
- local path = EU.ReadyUtilits.WFUIV2(70, 23, 15, "Enter image path:")
- local c
- local file = io.open(path, "r")
- if file:read() == "--CAMERA_PICTURE--" then c = true end
- file:close()
- if c then
- local func, reason = loadfile("/camera_render.lua")
- if not func then error("Failed with opening camera picture render file: " .. reason) end
- local data = func(path)
- field = data.field
- width = data.width
- height = data.height
- else
- local func, reason = loadfile("/paint_modules/load.lua")
- if func then
- local data = func(path)
- field = data.field
- width = data.width
- height = data.height
- print(width .. " " .. height .. " " .. #field .. " " .. #field[1])
- else
- error("Error with runnint load file: " .. reason)
- end
- end
- x, y = w / 2 - width / 2, h / 2 - height / 2
- buttons.close = true
- end
- local function fill()
- for i = 1, width do
- for j = 1, height do
- field[i][j] = {}
- field[i][j].background = background
- field[i][j].foreground = foreground
- field[i][j].symbol = symbol
- end
- end
- end
- local function filter()
- local buttons = {}
- local function invert()
- for i = 1, width do
- for j = 1, height do
- if field[i][j].symbol then
- field[i][j].background = EU.Color.Invert(field[i][j].background)
- field[i][j].foreground = EU.Color.Invert(field[i][j].background)
- end
- end
- end
- buttons.close = true
- end
- local function rgb()
- local lbuttons = {}
- lbuttons = {
- {w / 2 - 3, h / 2 - 2, 6, 1, 0xffffff, 0xff0000, "R:" .. r .. "%", function() r = EU.ReadyUtilits.WFUIV2(w / 2 - 15/2, h / 2 -1, 15, "Enter r value:", "number") lbuttons[1][7] = "R:" .. r .. "%" EU.draw(buttons) end},
- {w / 2 - 3, h / 2 - 1, 6, 1, 0xffffff, 0x00ff00, "G:" .. g .. "%", function() g = EU.ReadyUtilits.WFUIV2(w / 2 - 15/2, h / 2 -1, 15, "Enter g value:", "number") lbuttons[2][7] = "G:" .. g .. "%" EU.draw(buttons) end},
- {w / 2 - 3, h / 2 - 0, 6, 1, 0xffffff, 0x0000ff, "B:" .. b .. "%", function() b = EU.ReadyUtilits.WFUIV2(w / 2 - 15/2, h / 2 -1, 15, "Enter b value:", "number") lbuttons[3][7] = "B:" .. b .. "%" EU.draw(buttons) end}
- }
- lbuttons.eventFunc = function(ev) if ev[1] == "key_down" and ev[3] == 13 then
- for i = 1, width do
- for j = 1, height do
- field[i][j].background = EU.Color.Restrict(field[i][j].background, r, g, b)
- field[i][j].foreground = EU.Color.Restrict(field[i][j].foreground, r, g, b)
- end
- end
- lbuttons.close = true end
- end
- EU.screenBackup(function()
- EU.draw(lbuttons)
- EU.buttonPress(lbuttons)
- end)
- end
- buttons = {
- {7, 7, 6, 1, 0xffffff, 0x646464, "Invert", invert},
- {7, 8, 6, 1, 0xffffff, 0x646464, "RGB", rgb}
- }
- buttons.eventFunc = function(ev)
- if ev[1] == "key_down" and ev[3] == 9 then
- buttons.close = true
- end
- end
- EU.screenBackup(function()
- gpu.setForeground(0xffffff)
- gpu.setBackground(0x323232)
- gpu.set(7, 6, ss[1])
- os.sleep(0.1)
- EU.draw(buttons)
- EU.buttonPress(buttons)
- end)
- end
- local buttons = {
- {1, 1, 6, 1, 0xffffff, 0x646464, "back", changeBackground},
- {1, 2, 6, 1, 0xffffff, 0x646464, "fore", changeForeground},
- {1, 3, 6, 1, 0xffffff, 0x646464, "Save", save},
- {1, 4, 6, 1, 0xffffff, 0x646464, "Load", load},
- {1, 5, 6, 1, 0xffffff, 0x646464, "Fill", fill},
- {1, 6, 6, 1, 0xffffff, 0x646464, "Filter", filter}
- }
- buttons.eventFunc = function(ev)
- if ev[1] == "key_down" and ev[3] == 9 then buttons.close = true end
- end
- gpu.setBackground(0x323232)
- gpu.setForeground(background)
- gpu.set(7, 1, ss[2])
- gpu.setForeground(foreground)
- gpu.set(7, 2, ss[2])
- EU.draw(buttons)
- EU.buttonPress(buttons)
- gpu.setBackground(0x323232)
- term.clear()
- draw()
- end
- hotKeys["c"] = function() clear() draw() end
- hotKeys["d"] = function() draw() end
- hotKeys["e"] = function() if debugMode then loadfile("/bin/edit.lua")("/paint.lua") loadfile("/paint.lua")() end end
- hotKeys["m"] = menu
- hotKeys["D"] = function() local text = "[Debug mode]" if debugMode then debugMode = false gpu.setBackground(0x000000) gpu.fill(1, h, w, h, " ") gpu.fill(1, 1, 10, 6, " ") else debugMode = true gpu.setBackground(0x000000) gpu.setForeground(0x00ffff) gpu.set(w/2-string.len(text)/2, h, text)end draw() end
- hotKeys["s"] = function() setScale() clear() draw() end
- hotKeys["ss"] = {key2 = 56}
- hotKeys["ss"].func = function()
- local signal = {computer.pullSignal()}
- repeat
- if signal[1] == "key_up" and signal[4] == 56 then
- return
- elseif signal[1] == "touch" then
- local _, fore, back = gpu.get(signal[3], signal[4])
- background = back
- foreground = fore
- return
- end
- until false
- end
- hotKeys["t"] = function()
- repeat
- local signal = {computer.pullSignal()}
- if signal[1] == "key_up" and unicode.char(signal[3]) == "t" then return end
- if signal[1] == "touch" then
- local tx, ty = signal[3], signal[4]
- local text = EU.ReadyUtilits.WFUIV2(70, 23, 10)
- for i = 1, string.len(text) do
- gpu.setBackground(background)
- gpu.setForeground(foreground)
- field[tx-x+i][ty-y].symbol = string.sub(text, i, i)
- field[tx-x+i][ty-y].background = background
- field[tx-x+i][ty-y].foreground = foreground
- gpu.set(x + tx + i, ty, string.sub(text, i, i))
- end
- return
- end
- until false
- end
- gpu.setBackground(0x323232)
- term.clear()
- clear()
- draw()
- pull()
- gpu.setBackground(0x000000)
- gpu.setForeground(0xffffff)
- term.clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement