Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- ASCII art editer
- by Big SHiny Toys
- ]]
- ------- varibals ---------
- local curX,curY = 1,1
- local winX,winY = term.getSize()
- local picX,picY
- local offsX,offsY = 0,0
- local picT = {}
- local MMSelset = 1
- local ver = 0.35 -- lazy mans edition lol XD
- local mode = 1 -- mode 1 is static mode 2 is moving
- --------- end ------------
- ------- functions --------
- local function dialogBox(mes,yes,no,ok,cancle,mes2)
- local indexer ={}
- local sel2 = 1
- local sel3 = 1
- local with,higth = 26,6
- local x13,y13 = term.getSize()
- local off1 = (x13/2)-(with/2)
- local off2 = (y13/2)-(higth/2)
- local barier = string.rep("-",with-2)
- local blank = string.rep(" ",with-2)
- term.setCursorPos(off1,off2)
- write("+"..barier.."+")
- term.setCursorPos(off1,off2+1)
- write("|"..blank.."|")
- term.setCursorPos(off1,off2+2)
- write("+"..barier.."+")
- term.setCursorPos(off1,off2+3)
- write("|"..blank.."|")
- term.setCursorPos(off1,off2+4)
- write("|"..blank.."|")
- term.setCursorPos(off1,off2+5)
- write("+"..barier.."+")
- if mes ~= nil then
- term.setCursorPos(off1+1,off2+1)
- write(mes)
- end
- if mes2 ~= nil then
- term.setCursorPos(off1+1,off2+3)
- write(mes2)
- end
- if yes == 1 then table.insert(indexer,1) end
- if no == 1 then table.insert(indexer,2) end
- if ok == 1 then table.insert(indexer,3) end
- if cancle == 1 then table.insert(indexer,4) end
- sel2 = sel3
- if sel3 > table.maxn(indexer) then
- sel3 = table.maxn(indexer)
- sel2 = indexer[sel3]
- end
- if sel3 < 1 then
- sel3 = 1
- sel2 = indexer[1]
- end
- sel2 = indexer[1]
- while true do
- if yes == 1 then
- term.setCursorPos(off1+1,off2+4)
- if sel2 == 1 then
- write("[YES]")
- else
- write(" YES ")
- end
- end
- if no == 1 then
- term.setCursorPos(off1+7,off2+4)
- if sel2 == 2 then
- write("[NO]")
- else
- write(" NO ")
- end
- end
- if ok == 1 then
- term.setCursorPos(off1+12,off2+4)
- if sel2 == 3 then
- write("[OK]")
- else
- write(" OK ")
- end
- end
- if cancle == 1 then
- term.setCursorPos(off1+17,off2+4)
- if sel2 == 4 then
- write("[CANCLE]")
- else
- write(" CANCLE ")
- end
- end
- e,e1,e2,e3,e4,e5 = os.pullEvent()
- if e == "key" then
- if e1 == 203 then -- left
- sel3 = sel3-1
- end
- if e1 == 205 then -- right
- sel3 = sel3+1
- end
- if e1 == 28 then -- enter
- if indexer[sel3] == 1 then return true end
- if indexer[sel3] == 2 then return false end
- return indexer[sel3]
- end
- end
- sel2 = sel3
- if sel3 > table.maxn(indexer) then
- sel3 = table.maxn(indexer)
- sel2 = indexer[sel3]
- end
- if sel3 < 1 then
- sel3 = 1
- sel2 = indexer[1]
- end
- end
- end
- local function help()
- term.clear()
- term.setCursorPos(1,1)
- write([[Use the direction keys to navigate menues and select size of new picture.
- To load a new picture use the up down keys to select the right file. Folders are represented by [] pressing Enter will open that folder. Using the \\ option will return you one directry back. Ounce selected you will be promped to confirm use keys to and enter to make elsection. To exit file selection without selecting a file press Ctrl key.
- when the new file is made or loaded the screen will clear and the direction keys will move the cursor around the screen. pressing and ASCII charicter like "k" or "^" will make it apear on screen. the picture can be saved by pressing Ctrl and selecting save. you will need to select a file to over write or select the blank space bellow the list and use Tab to enyer a file name.
- That is about it have fun with ASCII art.
- Press Enter to return.]])
- local event,var
- while true do
- event,var = os.pullEvent()
- if event == "key" and var == 28 then
- return
- end
- end
- end
- local function redrawfull()
- term.setCursorBlink(false)
- term.clear()
- winX,winY = term.getSize()
- for i = 1 , winX - 2 do
- for v = 1 , winY - 1 do
- term.setCursorPos(i,v)
- if picT[i+offsX] == nil then
- elseif picT[i+offsX][v+offsY] ~= nil then
- write(picT[i+offsX][v+offsY])
- end
- end
- end
- local scBar = math.floor(((offsY+1)/(picY-winY+1))*(winY-1))
- for i = 1,winY-1 do
- term.setCursorPos(winX-1,i)
- if scBar == i then
- write("#")
- else
- write("|")
- end
- end
- scBar = math.floor(((offsX+1)/(picX-winX+2))*(winX-2))
- for i = 1,winX-2 do
- term.setCursorPos(i,winY)
- if scBar == i then
- write("#")
- else
- write("-")
- end
- end
- term.setCursorBlink(true)
- end
- local function CustomExit()
- term.clear()
- winX,winY = term.getSize()
- term.setCursorPos((winX/2)-(string.len("Thank you for trying ASCII art")/2),(winY/2)-1)
- write("Thank you for trying ASCII art")
- term.setCursorPos((winX/2)-(string.len("Idear from Troll")/2),(winY/2))
- write("Idear from Troll")
- term.setCursorPos((winX/2)-(string.len("By Big SHiny Toys")/2),(winY/2)+1)
- write("By Big SHiny Toys")
- sleep(2)
- term.clear()
- term.setCursorPos(1,1)
- error()
- end
- local function fileList(mode)
- local parth = {}
- local sParth
- local list = {}
- local x12,y12 = term.getSize()
- local sel = 3
- local curent
- local offset = 0
- local flot = 0
- local fileName
- local function pointer() -- yes it points lol XD
- if sel > y12-2 then
- sel = y12-2
- offset = offset+1
- end
- if sel < 3 then
- sel = 3
- offset = offset-1
- end
- if offset < 0 then offset = 0 end
- term.setCursorPos(1,sel)
- write(">")
- end
- local function top()
- sParth = [[\]]
- for i = 1,table.maxn(parth) do
- sParth = sParth..parth[i]..[[\]]
- end
- list = fs.list(sParth)
- term.setCursorPos(1,1)
- write("Dir: "..sParth)
- local barier = string.rep("-",x12-2)
- term.setCursorPos(1,2)
- write(barier)
- end
- local function middle()
- local counter
- local specal
- local folder = {}
- local file = {}
- local this = nil
- for i = 1, table.maxn(list) do
- if fs.isDir(sParth..list[i]) then
- table.insert(folder,list[i])
- else
- table.insert(file,list[i])
- end
- end
- table.sort(folder)
- table.sort(file)
- table.insert(folder,1,[[\\]])
- if offset > table.maxn(folder)+table.maxn(file)- (y12-5) then
- offset = table.maxn(folder)+table.maxn(file)- (y12-5)
- end
- if offset < 0 then
- offset = 0
- end
- for i = 1 , y12-4 do
- if i+offset < table.maxn(folder)+1 then
- term.setCursorPos(3,i+2)
- this = folder[i+offset]
- write("[] "..folder[i+offset])
- counter = i
- else
- if counter == nil then
- counter = 0
- flot = offset - table.maxn(folder)
- end
- if i-counter+flot < table.maxn(file)+1 then
- term.setCursorPos(3,i+2)
- this = file[i-counter+flot]
- write(" "..file[i-counter+flot])
- end
- end
- if i+2 == sel then curent = this
- end
- this = nil
- end
- end
- local function bottom()
- local barier = string.rep("-",x12-2)
- term.setCursorPos(1,y12-1)
- write(barier)
- term.setCursorPos(1,y12)
- write("File Name: "..tostring(fileName))
- term.setCursorPos(x12-string.len(tostring(curent))-1,y12)
- write(tostring(curent))
- end
- while true do
- term.clear()
- top()
- pointer()
- middle()
- bottom()
- e,e1,e2,e3,e4,e5 = os.pullEvent()
- if e == "key" then
- if e1 == 200 then -- up key
- sel = sel-1
- end
- if e1 == 208 then -- down key
- sel = sel+1
- end
- if e1 == 15 then -- tab
- term.setCursorPos(1,y12)
- term.clearLine()
- write("File Name: ")
- term.setCursorPos(12,y12)
- fileName = io.read()
- specal = true
- end
- if e1 == 29 then -- Ctrl
- if dialogBox("Message",1,1,0,0,"Exit file select") then
- return
- end
- end
- if e1 == 28 or specal then -- enter key
- if curent == [[\\]] then
- table.remove(parth)
- else
- if curent ~= nil then
- if fs.isDir(sParth..curent) then
- table.insert(parth,curent)
- end
- end
- if mode == "save" then
- if fs.isDir(sParth..tostring(curent)) or curent == [[\\]] then
- else
- if fileName == nil and curent == nil then
- dialogBox("Enter a Name",0,0,1,0,"press Tab to add name")
- else
- if fs.exists(sParth..tostring(curent)) then
- if fs.isReadOnly(sParth..tostring(curent)) then
- dialogBox("Error",0,0,1,0,"File is read only")
- else
- if dialogBox("Confirm OVER WRITE",1,1,0,0,"Save as:"..sParth..curent) then
- return sParth..curent
- end
- end
- else
- if dialogBox("Confirm",1,1,0,0,"Save as:"..sParth..fileName) then
- return sParth..fileName
- end
- end
- end
- end
- end
- if mode == "load" then
- if curent ~= nil then
- if fs.isDir(sParth..curent) then
- else
- if dialogBox("confirm",1,1,0,0,"load :"..sParth..curent) then
- return sParth..curent
- else
- end
- end
- else
- dialogBox("Error",0,0,1,0,"No file selected")
- end
- end
- end
- specal = false
- end
- end
- end
- end
- local function clear()
- local size = table.maxn(picT)
- if size == 0 then
- return
- end
- local size2 = table.maxn(picT[1])
- for i = 1, size do
- for b = 1, size2 do
- picT[i][b] = nil
- end
- table.remove(picT[i])
- end
- end
- local function specialSave() -- exports image
- local A = string.char(91)
- local B = string.char(93)
- local D = ","
- local C = "}"
- local fileLocation = fileList("save")
- local contence = ""
- if fileLocation ~= nil then
- local x = picX
- local y = picY
- local builder = [[local tImage = {]]
- for v = 1 , y do
- for i = 1 , x do
- contence = contence..picT[i][v]
- end
- if v == y then
- builder = builder..A..A..contence..B..B..C.."\n"
- else
- builder = builder..A..A..contence..B..B..D.."\n"
- end
- contence = ""
- end
- local file = fs.open(fileLocation,"w")
- file.write(builder)
- file.close()
- contence = ""
- dialogBox("Mesage",0,0,1,0,"Save Completed")
- return true
- end
- dialogBox("Error",0,0,1,0,"Failed to save")
- return false
- end
- local function save() -- come up with format add that
- local fileLocation = fileList("save")
- local contence = ""
- if fileLocation ~= nil then
- local x = picX
- local y = picY
- for v = 1 , y do
- for i = 1 , x do
- contence = contence..picT[i][v]
- end
- if v == y then
- else
- contence = contence.."\n"
- end
- end
- local file = fs.open(fileLocation,"w")
- file.write(contence)
- file.close()
- contence = ""
- dialogBox("Mesage",0,0,1,0,"Save Completed")
- return true
- end
- dialogBox("Error",0,0,1,0,"Failed to save")
- return false
- end
- local function load() -- come up with format add that
- local fileLocation = fileList("load")
- local contence = {}
- local sLine
- local allGood = true
- if fileLocation ~= nil then
- if fs.exists(fileLocation) then
- local file = io.open( fileLocation, "r" )
- sLine = file:read()
- table.insert( contence, sLine )
- sLine = file:read()
- while sLine do
- if string.len(tostring(contence[1])) == string.len(tostring(sLine)) then
- table.insert( contence, sLine )
- else
- allGood = false
- break
- end
- sLine = file:read()
- if sLine == nil then break end
- end
- file:close()
- end
- if allGood then
- clear()
- local x = string.len(contence[1])
- local y = table.maxn(contence)
- picX,picY = x,y
- for i = 1 , x do
- picT[i] = {}
- for v = 1 , y do
- picT[i][v] = string.sub(contence[v],i,i)
- end
- end
- dialogBox("Mesage",0,0,1,0,"File loaded")
- return true
- else
- dialogBox("Error",0,0,1,0,"Not ACSCII art file")
- return false
- end
- end
- end
- local function Newgrid(x,y)
- for i = 1 , x do
- picT[i] = {}
- for v = 1 , y do
- picT[i][v] = " "
- end
- end
- end
- local function newSelect()
- local xTemp,yTemp = 1,1
- local pos = 1
- local sizex,sizey = term.getSize()
- while true do
- if pos > 4 then pos = 1 end
- if pos < 1 then pos = 4 end
- --if xTemp > sizex-2 then xTemp = sizex-2 end
- --if xTemp < 1 then xTemp = 1 end
- --if yTemp > sizey-2 then yTemp = sizey-2 end
- --if yTemp < 1 then yTemp = 1 end
- term.clear()
- term.setCursorPos(1,1)
- write("Please select size")
- term.setCursorPos(1,3)
- write("Size X : ")
- if pos == 1 then write("< "..xTemp.." > ".."Recomended: "..tostring(sizex-2))
- else
- write(" "..xTemp.." ".."Recomended: "..tostring(sizex-2))
- end
- term.setCursorPos(1,4)
- write("Size Y : ")
- if pos == 2 then write("< "..yTemp.." > ".."Recomended: "..tostring(sizey-2))
- else
- write(" "..yTemp.." ".."Recomended: "..tostring(sizey-2))
- end
- term.setCursorPos(1,5)
- if pos == 3 then write(" [Create] ")
- else
- write(" Create ")
- end
- term.setCursorPos(1,6)
- if pos == 4 then write(" [Return] ")
- else
- write(" Return ")
- end
- while true do
- e,e1 = os.pullEvent()
- if e == "key" then
- if e1 == 200 then -- up
- pos = pos-1
- break
- end
- if e1 == 208 then -- down
- pos = pos+1
- break
- end
- if e1 == 203 then -- left
- if pos == 1 then
- xTemp = xTemp - 1
- end
- if pos == 2 then
- yTemp = yTemp - 1
- end
- break
- end
- if e1 == 205 then -- right
- if pos == 1 then
- xTemp = xTemp + 1
- end
- if pos == 2 then
- yTemp = yTemp + 1
- end
- break
- end
- if e1 == 28 then -- enter
- if pos == 3 then
- Newgrid(xTemp,yTemp)
- picX,picY = xTemp,yTemp
- return true
- end
- if pos == 4 then
- return false
- end
- end
- end
- end
- end
- end
- local function clearGrid()
- local x = table.maxn(picT)
- local y = table.maxn(picT[1])
- for i = 1 , x do
- for v = 1 , y do
- picT[i][v] = " "
- end
- end
- end
- local function menue2() -- save - load - new - exit 6 lines
- local crnX,crnY = term.getSize()
- local selected = 6
- while true do
- if selected > 7 then selected = 1
- end
- if selected < 1 then selected = 7
- end
- term.setCursorPos(crnX-9,crnY-8)
- write("+-------+")
- term.setCursorPos(crnX-9,crnY-7)
- if selected == 6 then write("|> Mod "..mode.."|") else write("| Mod "..mode.."|") end --new
- term.setCursorPos(crnX-9,crnY-6)
- if selected == 7 then write("|> EXPO |") else write("| EXPO |") end
- term.setCursorPos(crnX-9,crnY-5)
- if selected == 1 then write("|> Save |") else write("| Save |") end
- term.setCursorPos(crnX-9,crnY-4)
- if selected == 2 then write("|> Load |") else write("| Load |") end
- term.setCursorPos(crnX-9,crnY-3)
- if selected == 3 then write("|> New |") else write("| New |") end
- term.setCursorPos(crnX-9,crnY-2)
- if selected == 4 then write("|> Clear|") else write("| Clear|") end
- term.setCursorPos(crnX-9,crnY-1)
- if selected == 5 then write("|> Exit |") else write("| Exit |") end
- term.setCursorPos(crnX-9,crnY)
- write("+-------+")
- while true do
- e,e1,e2,e3,e4,e5 = os.pullEvent()
- if e == "key" then
- if e1 == 200 then -- up key
- selected = selected-1
- break
- end
- if e1 == 208 then -- down key
- selected = selected+1
- break
- end
- if e1 == 203 then -- left key
- if selected == 6 then
- mode = 1
- end
- break
- end
- if e1 == 205 then -- right key
- if selected == 6 then
- mode = 2
- end
- break
- end
- if e1 == 29 then -- Ctrl
- return
- end
- if e1 == 28 then -- enter key
- if selected == 3 then -- new
- if newSelect() then
- return
- else
- break
- end
- end
- if selected == 6 then -- new
- return
- end
- if selected == 5 then
- CustomExit()
- return
- end
- if selected == 4 then
- clearGrid()
- return
- end
- if selected == 1 then -- neds work
- save()
- return
- end
- if selected == 2 then -- neds work
- load()
- return
- end
- if selected == 7 then
- specialSave()
- return
- end
- end
- end
- end
- end
- end
- ---------- end -----------
- ------- Main Menue -------
- -- load - new - help - exit
- local function Mmenue()
- MMSelset = 1
- local s1 = "ASCII Art ver "..ver
- local s2 = "--- Main Menue ---"
- while true do
- if MMSelset > 4 then MMSelset = 1
- end
- if MMSelset < 1 then MMSelset = 4
- end
- winX,winY = term.getSize()
- term.clear()
- term.setCursorPos((winX/2)-(string.len(s1)/2),1)
- write(s1)
- term.setCursorPos((winX/2)-(string.len(s2)/2),3)
- write(s2)
- term.setCursorPos((winX/2)-(string.len(" Load ")/2),5)
- if MMSelset == 1 then
- write("> Load <")
- else
- write(" Load ")
- end
- term.setCursorPos((winX/2)-(string.len(" new ")/2),6)
- if MMSelset == 2 then
- write("> New <")
- else
- write(" New ")
- end
- term.setCursorPos((winX/2)-(string.len(" Help ")/2),7)
- if MMSelset == 3 then
- write("> Help <")
- else
- write(" Help ")
- end
- term.setCursorPos((winX/2)-(string.len(" Exit ")/2),8)
- if MMSelset == 4 then
- write("> Exit <")
- else
- write(" Exit ")
- end
- while true do
- e,e1,e2,e3,e4,e5 = os.pullEvent()
- if e == "key" then
- if e1 == 200 then -- up key
- MMSelset = MMSelset-1
- break
- end
- if e1 == 208 then -- down key
- MMSelset = MMSelset+1
- break
- end
- if e1 == 28 then -- enter key
- if MMSelset == 1 then
- if load() then
- return
- else
- break
- end
- end
- if MMSelset == 2 then -- new
- if newSelect() then
- return
- else
- break
- end
- end
- if MMSelset == 3 then -- will be help section
- help()
- break
- end
- if MMSelset == 4 then
- CustomExit()
- end
- end
- end
- end
- end
- end
- ---------- end -----------
- ------- Main loop --------
- Mmenue()
- redrawfull()
- curX,curY = 1,1
- term.setCursorBlink(true)
- term.setCursorPos(curX,curY)
- while true do
- e,e1,e2,e3,e4,e5 = os.pullEvent()
- if e == "key" then
- if e1 == 200 then -- up key
- curY = curY -1
- end
- if e1 == 29 then -- Ctrl key
- term.setCursorBlink(false)
- menue2()
- redrawfull()
- term.setCursorPos(curX,curY)
- term.setCursorBlink(true)
- end
- if e1 == 208 then -- down key
- curY = curY +1
- end
- if e1 == 203 then -- left key
- curX = curX-1
- end
- if e1 == 205 then -- right key
- curX = curX+1
- end
- if e1 == 14 then -- backspace
- if mode == 2 then
- if curX-1 >= 1 then
- curX = curX-1
- else
- if curY-1 <= 1 then
- curX,curY = picX,curY-1
- end
- end
- picT[curX][curY] = " "
- term.setCursorPos(curX,curY)
- write(picT[curX][curY])
- end
- end
- if curX > winX-2 then
- curX = winX-2
- offsX = offsX+1
- redrawfull()
- elseif curX < offsX then
- curX = 1
- offsX = offsX-1
- redrawfull()
- end
- term.setCursorPos(curX,curY)
- if curX > picX-offsX-1 then
- curX = picX-offsX
- elseif curX < 1 then
- curX = 1
- end
- term.setCursorPos(curX,curY)
- if curY > winY-1 then
- curY = winY -1
- offsY = offsY+1
- redrawfull()
- elseif curY < offsY then
- curY = 1
- offsY = offsY-1
- redrawfull()
- end
- term.setCursorPos(curX,curY)
- if curY > picY-offsY-1 then
- curY = picY-offsY
- elseif curY < 1 then
- curY = 1
- end
- term.setCursorPos(curX,curY)
- end
- if e == "char" then
- picT[curX+offsX][curY+offsY] = e1
- write(picT[curX+offsX][curY+offsY])
- if mode == 1 then
- end
- if mode == 2 then
- if curX+1 > picX then
- if curY+1 <= picY then
- curX,curY = 1,curY+1
- end
- else
- curX,curY = curX+1,curY
- end
- end
- term.setCursorPos(curX,curY)
- end
- end
- ---------- end -----------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement