local ver = "0.0.1" local resX, resY = term.getSize() local fps = 60 local tools = {{1, "orange"},{0, "blue"},{0,"green"},{0, "red"}} local toolIcon = { "", "•-•", "CLR", } local monitor = peripheral.find("monitor") if monitor ~= nil then monitor.clear() end local mResX, mResY = 45, 13--monitor.getSize() local die = false if monitor ~= nil then mResX, mResY = monitor.getSize() if mResX > 45 or mResY > 13 then term.setTextColor(colors.red) print("WTF? Your monitor has resolution ".. mResX .. "x" .. mResY .. " which goes over this software's resolution limit of 45x13") die = true end end if not die then local offXS, offXE, offYS, offYE local cols = {} local function setupHud() if monitor ~= nil then monitor.setBackgroundColor(colors.white) monitor.clear() end term.setBackgroundColor(colors.lightGray) term.clear() offXS = math.floor(resX/2-mResX/2) offXE = math.floor(resX/2+mResX/2) offYS = math.floor(resY/2-mResY/2)-1 offYE = math.floor(resY/2+mResY/2)-1 term.setBackgroundColor(colors.red) term.setTextColor(colors.white) term.setCursorPos(resX,1) term.write("×") term.setCursorPos(resX-1,1) term.setTextColor(colors.lightGray) term.write("▌") term.setBackgroundColor(colors.lightGray) term.setTextColor(colors.yellow) term.setCursorPos(resX-12, resY-2) term.write("Save: Ctrl+S") term.setCursorPos(resX-12, resY-1) term.write("Load: Ctrl+L") term.setTextColor(colors.gray) term.setCursorPos(resX-string.len("Paint+ Version "..ver), resY) term.write("Paint+ Version "..ver) term.setCursorPos(offXS,offYS) term.setBackgroundColor(colors.lightGray) -- term.setTextColor(colors.gray) term.write("+") term.setCursorPos(offXE+1,offYS) term.write("+") term.setCursorPos(offXS, offYE+1) term.write("+") term.setCursorPos(offXE+1,offYE+1) term.write("+") for x = offXS+1, offXE do term.setCursorPos(x,offYS) term.setBackgroundColor(colors.lightGray) term.write("-") term.setCursorPos(x,offYE+1) term.write("-") for y = offYS+1, offYE do term.setCursorPos(x,y) term.setBackgroundColor(colors.white) term.write(" ") term.setBackgroundColor(colors.lightGray) term.setCursorPos(offXS, y) term.write("|") term.setCursorPos(offXE+1,y) term.write("|") end end local ci = 1 -- MAKING COLOR PALETTE for i = 1, 16 do local x = (i-1)%2+1 local y = math.floor((i-1)/2)+5 term.setCursorPos(x,y) cols[(x-1)+(y-1)*resX] = ci term.setBackgroundColor(ci) term.write(" ") ci = ci + ci end end local ltX = nil local ltY = nil function updateTools() ltX = nil ltY = nil for i, t in pairs(tools) do term.setBackgroundColor(colors.gray) term.setTextColor(colors.lightGray) term.setCursorPos((i-1)*6+1, resY-1) term.write("|") term.setCursorPos((i-1)*6+5, resY-1) term.write("|") term.setCursorPos((i-1)*6+1, resY) term.write("+---+") term.setCursorPos((i-1)*6+1, resY-2) term.write("+---+") term.setCursorPos((i-1)*6+2, resY-1) if t[1] == 1 then term.setBackgroundColor(colors.black) term.setTextColor(colors[t[2]]) else term.setTextColor(colors.black) end term.write(toolIcon[i]) end end local selColor = 32768 -- black setupHud() updateTools() canvas = {} for x = 1, mResX do canvas[x] = {} for y = 1, mResY do canvas[x][y] = colors.white end end local function updateCanvas() for x = 1, mResX do for y = 1,mResY do local color = canvas[x][y] term.setCursorPos(x+offXS, y+offYS) term.setBackgroundColor(color) term.write(" ") if monitor ~= nil then monitor.setCursorPos(x, y) monitor.setBackgroundColor(color) monitor.write(" ") end end end end local function setPixel(x, y, color) canvas[x][y] = color term.setCursorPos(x+offXS, y+offYS) term.setBackgroundColor(color) term.write(" ") if monitor ~= nil then monitor.setCursorPos(x, y) monitor.setBackgroundColor(color) monitor.write(" ") end end local function setSudoPixel(x, y) if x > mResX or y > mResY or x < 1 or y < 1 then return end term.setCursorPos(x+offXS, y+offYS) term.setBackgroundColor(selColor) term.write(" ") if monitor ~= nil then monitor.setCursorPos(x, y) monitor.setBackgroundColor(selColor) monitor.write(" ") end end local function selectColor(color) selColor = color for x = 1, 2 do for y = 8+5, 8+5+1 do term.setCursorPos(x, y) term.setBackgroundColor(selColor) term.write(" ") end end end selectColor(selColor) local selectedTool = 1 local gameFrames = 0 local ctrlBoy = false local checkLocations = {} local function drawLine(x0, y0, x1, y1, sudo) local dx = math.abs(x1-x0) local sx = 1 if x0 > x1 then sx = -1 end local dy = -math.abs(y1-y0) local sy = 1 if y0 > y1 then sy = -1 end local error = dx + dy if sudo then updateCanvas() end while true do if sudo ~= true then if canvas[x0] ~= nil and canvas[x0][y0] ~= nil then canvas[x0][y0] = selColor end else setSudoPixel(x0,y0) end local e2 = 2*error if e2 >= dy then if x0 == x1 then break end error = error + dy x0 = x0 + sx end if e2 <= dx then if y0 == y1 then break end error = error + dx y0 = y0 + sy end end if sudo ~= true then updateCanvas() end end local prevPointX = nil local prevPointY = nil local fileMenu = false local function saveMenu() while true do term.setCursorPos(1,resY-4) term.setBackgroundColor(colors.black) term.setTextColor(colors.yellow) term.clear() print("Give me a save name ok? or type \"no\" to cancel:") term.setCursorPos(3, resY-3) local name = read() if name == "no" then fileMenu = false setupHud() updateTools() updateCanvas() break end local fucked = false local succ, msg = pcall(function() if string.find(name, "%.") or string.find(name, "/") then fucked = true error("fuck") end if name == "" then fucked = true error("fuck") end local le_file = fs.open(fs.getDir(shell.getRunningProgram()).."/Paintings/"..name..".pp", "w") local data = mResX .. ":" .. mResY for x = 1, mResX do for y = 1, mResY do data = data .. ":" .. canvas[x][y] end end le_file.write(data) le_file.close() if not fs.exists(fs.getDir(shell.getRunningProgram()).."/Paintings/"..name..".pp") then fucked = true error("fuck") end end) if fucked then term.setTextColor(colors.red) print("Stop attempting fucked up names") sleep(2) elseif not succ then print("What the fuck? try again") sleep(2) else print("Successfully saved as \"" .. name .. ".pp\" Located at the Paintings folder") sleep(3) fileMenu = false setupHud() updateTools() updateCanvas() break end end end local function loadMenu() while true do term.setCursorPos(1,resY-4) term.setBackgroundColor(colors.black) term.setTextColor(colors.green) term.clear() print("Which one you want? (say the number)") term.setTextColor(colors.lime) local index = 1 local list = fs.list(fs.getDir(shell.getRunningProgram()).."/Paintings") local picks = {} for i, d in pairs(list) do if d:sub(-3,-1) == ".pp" then print(" "..index..". "..d) index = index + 1 table.insert(picks,fs.getDir(shell.getRunningProgram()).."/Paintings/".. d) end end if #picks == 0 then term.clear() print("WTF? There are no saves") sleep(2) fileMenu = false setupHud() updateTools() updateCanvas() break end print(" "..index..". ".."NO I DONT WANT TO LOAD") local pick = tonumber(read()) if pick == #picks+1 then fileMenu = false setupHud() updateTools() updateCanvas() break elseif picks[pick] == nil then print("What the fuck? dont do that, try again") sleep(2) else local data = fs.open(picks[pick], "r").readAll() local info = {} for v in string.gmatch(data, "[^:]+") do info[#info+1] = v end local lx = tonumber(info[1]) local ly = tonumber(info[2]) if lx ~= mResX or ly ~= mResY then local dontDo = false if monitor ~= nil and (mResX ~= lx or mResY ~= ly) then print("WTF! The monitor resolution is "..mResX.."x"..mResY.." but the save resolution is "..lx.."x"..ly) sleep(3) print("I'll still load it") sleep(1) end if not dontDo then for x = 1, mResX do for y = 1, mResY do canvas[x][y] = nil end canvas[x] = nil end mResX = lx mResY = ly for x = 1, mResX do canvas[x] = {} for y = 1, mResY do canvas[x][y] = colors.white end end end end local pi = 1 for x = 1, lx do for y = 1, ly do if canvas[x] ~= nil and canvas[x][y] ~= nil then canvas[x][y] = tonumber(info[pi+2]) pi = pi + 1 end end end fileMenu = false setupHud() updateTools() updateCanvas() break end end end while true do local event, butt, mx, my = os.pullEvent() if event == "peripheral_detach" or event == "peripheral" then monitor = peripheral.find("monitor") updateCanvas() end if event == "monitor_resize" then updateCanvas() end if event == "mouse_click" and mx >= resX - 1 and my == 1 then term.setBackgroundColor(colors.black) --term.setTextColor(colors.lightGray) term.clear() term.setCursorPos(1,1) -- print("Paint+ Terminated") break end if fileMenu then else if event == "key" and butt == keys.l and ctrlBoy then fileMenu = true loadMenu() end if event == "key" and butt == keys.s and ctrlBoy then fileMenu = true saveMenu() end if event == "key" and butt == keys.leftCtrl then ctrlBoy = true end if event == "key_up" then ctrlBoy = false end if event == "mouse_up" then prevPointX = nil prevPointY = nil end if event == "mouse_click" and my > resY-3 and mx <= #tools*6 and mx%6 ~= 0 and tools[math.floor(mx/6)+1] ~= nil then tools[selectedTool][1] = 0 selectedTool = math.floor(mx/6)+1 tools[selectedTool][1] = 1 updateTools() elseif event == "mouse_click" and cols[mx-1+(my-1)*resX] ~= nil then selectColor(cols[mx-1+(my-1)*resX]) elseif tools[1][1] == 1 and (event == "mouse_click" or event == "mouse_drag") and mx > offXS and mx <= offXE and my > offYS and my <= offYE then local x = mx-offXS local y = my-offYS setPixel(x,y, selColor) if prevPointX ~= nil and (math.abs(prevPointX-x) > 1 or math.abs(prevPointY-y) > 1) then drawLine(prevPointX,prevPointY,x,y) end prevPointX = x prevPointY = y elseif tools[3][1] == 1 and (event == "mouse_click" or event == "mouse_drag") then local x = mx - offXS local y = my - offYS if ltX == nil then setPixel(x,y,selColor) ltX = x ltY = y else drawLine(ltX,ltY,x,y,true) end elseif tools[3][1] == 1 and event == "mouse_up" then local x = mx - offXS local y = my - offYS if ltX ~= nil then drawLine(ltX,ltY,x,y) end ltX = nil ltY = nil elseif event == "mouse_click" and mx > offXS and mx <= offXE and my > offYS and my <= offYE then if tools[2][1] == 1 then local x = mx-offXS local y = my-offYS local checkCol = canvas[x][y] for i, _ in pairs(checkLocations) do checkLocations[i][1] = nil checkLocations[i][2] = nil checkLocations[i] = nil end table.insert(checkLocations, {x,y}) local dirs = {{1,0},{0,1},{-1,0},{0,-1}} canvas[x][y] = selColor --local iterations = 0 while #checkLocations > 0 do local cl = checkLocations[1] for di, d in pairs(dirs) do if canvas[cl[1]+d[1]] and canvas[cl[1]+d[1]][cl[2]+d[2]] and canvas[cl[1]+d[1]][cl[2]+d[2]] == checkCol then canvas[cl[1]+d[1]][cl[2]+d[2]] = selColor table.insert(checkLocations, {cl[1]+d[1],cl[2]+d[2]}) --if ctrlBoy == true --end end end updateCanvas() table.remove(checkLocations, 1) --if iterations%64 == 0 then -- sleep(1/fps) --end --iterations = iterations + 1 end -- updateCanvas() elseif tools[#tools][1] == 1 then for x = 1, mResX do for y = 1, mResY do setPixel(x,y,colors.white) end end end else prevPointX = nil prevPointY = nil end end gameFrames = gameFrames + 1 end end