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 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)
- backgroundSymbol = unicode.char(9618)
- local background = 0x00ffff
- local foreground = 0xffffff
- local symbol = " "
- local hotKeys = {
- [9] = function() close = true end
- }
- ------------------------------------------------
- local function setScale()
- repeat
- width = tonumber(EU.ReadyUtilits.WriteFieldUI(60, 23, "Enter massive width(1 - " .. w .. "):"))
- until width and width > 0 and width <= w
- repeat
- height = tonumber(EU.ReadyUtilits.WriteFieldUI(60, 23, "Enter massive height(1 - " .. h .. ":"))
- 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] = {}
- field[i][j].symbol = backgroundSymbol
- field[i][j].background = 0x000000
- if j / 2 * 2 ~= j then field[i][j].foreground = 0xffffff else field[i][j].foreground = 0x323232 end
- end
- end
- end
- local function draw()
- for i = 1, width do
- for j = 1, height do
- 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)
- 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 = signal[3]
- local char = unicode.char(key)
- for hotKey, func in pairs(hotKeys) do
- if hotKey == key or hotKey == char then
- func()
- end
- end
- end
- end
- end
- local function menu()
- local buttons = {}
- local function changeBackground()
- background = EU.ReadyUtilits.RGBPalette(65, 23, "", background)
- buttons.close = true
- end
- local function changeForeground()
- foreground = EU.ReadyUtilits.RGBPalette(65, 23, "", foreground)
- buttons.close = true
- end
- local function save()
- EU.save({field = field, width = width, height = height}, EU.ReadyUtilits.WriteFieldUI(60, 23, "Enter path to saving:"))
- buttons.close = true
- end
- local function load()
- local data = EU.load(EU.ReadyUtilits.WriteFieldUI(60, 23, "Enter image path:"))
- field = data.field
- width = data.width
- height = data.height
- buttons.close = true
- end
- local function fill()
- for i = 1, width do
- for j = 1, height do
- field[i][j].background = background
- field[i][j].foreground = foreground
- field[i][j].symbol = symbol
- end
- end
- end
- buttons = {
- {1, 1, 6, 1, background, EU.Color.Invert(background), "back", changeBackground},
- {1, 2, 6, 1, foreground, EU.Color.Invert(foreground), "fore", changeForeground},
- {1, 3, 6, 1, 0x161616, 0x00ffff, "Save", save},
- {1, 4, 6, 1, 0x161616, 0x00ffff, "Load", load},
- {1, 5, 6, 1, 0x161616, 0x00ffff, "Fill", function() fill() draw() buttons.close = true end}
- }
- buttons.eventFunc = function(ev)
- if ev[1] == "key_down" and ev[3] == 9 then buttons.close = true end
- end
- 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
- EU.screenBackup(function()
- gpu.setBackground(0x323232)
- term.clear()
- clear()
- draw()
- pull()
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement