Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --TangentPaint V.0.5
- --Part one of the final product!
- --VARIABLE SETUP--
- width,height=term.getSize()
- print(height) print(width)
- colorNames=
- {
- "white",
- "orange",
- "magenta",
- "lightblue",
- "yellow",
- "lime",
- "pink",
- "gray",
- "lightgray",
- "cyan",
- "purple",
- "blue",
- "brown",
- "green",
- "red",
- "black"
- }
- decHexTable={"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"}
- canvas={}
- for i=1,height-1 do
- canvas[i]={}
- for j=1,width do
- canvas[i][j]=0
- end
- end
- overlay={}
- for i=1,height do
- overlay[i]={}
- for j=1,width do
- overlay[i][j]=0
- end
- end
- lastPosition={0,0}
- colorSelected=1
- alive=true
- --FUNCTIONS--
- function drawTools()
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(1,height)
- overlay={1,1,1,0,2,2,2,0,3,3,3,0,4,4,4}
- io.write("[L] [S] [M] [X]")
- term.setBackgroundColor(2^colorSelected-1)
- io.write(colorNames[colorSelected])
- end
- function drawCanvas()
- for i=1,height-1 do
- for j=1,width do
- term.setBackgroundColor(2^canvas[i][j])
- io.write(" ")
- term.setBackgroundColor(2^0)
- end
- io.write("\n")
- end
- end
- function paintLoad()
- loadData={}
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(1,height)
- for i=1,width do io.write(" ") end
- term.setCursorPos(1,height)
- loadName=io.read()
- if fs.exists(loadName) then
- file = io.open(loadName, "r")
- line = file:read()
- io.write(line)
- file:close()
- end
- for i=1,string.len(line) do
- loadData[i]=string.sub(line,i,i)
- end
- for i=1,#loadData do
- io.write(loadData[i])
- end
- k=1
- for i=1,height-1 do
- for j=1,width do
- for decode=1,16 do if loadData[k]==decHexTable[decode] then canvas[i][j]=decode-1 end end
- k=k+1
- end
- end
- for i=1,#loadData do
- print(loadData[i])
- end
- for i=1,height-1 do
- for j=1,width do
- io.write(canvas[i][j])
- end
- io.write("\n")
- end
- drawCanvas()
- end
- function paintSave()
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(1,height)
- for i=1,width do io.write(" ") end
- term.setCursorPos(1,height)
- saveName=io.read()
- local saveDir = saveName:sub(1, saveName:len() - fs.getName(saveName):len() )
- if not fs.exists(saveDir) then
- fs.makeDir( saveName )
- end
- file = fs.open(saveName, "w")
- --file.write(width..","..height.."|")
- for i=1,height-1 do
- for j=1,width do
- print(i..","..j..":"..canvas[i][j])
- index=canvas[i][j]+1
- file.write(decHexTable[index])
- end
- end
- file.close()
- end
- function paintMenu()
- end
- function paintExit()
- alive=false
- term.setBackgroundColor(colors.black)
- shell.run("clear")
- error()
- end
- function screenInteract()
- if mouseY==height then checkToolBar() return end
- if mouseButton==2 then
- canvas[mouseY][mouseX]=0
- end
- if mouseButton==1 then
- canvas[mouseY][mouseX]=colorSelected-1
- end
- if mouseButton==5 then
- colorSelected=colorSelected+1
- if colorSelected==17 then colorSelected=1 end
- end
- if mouseButton==4 then
- colorSelected=colorSelected-1
- if colorSelected==0 then colorSelected=16 end
- end
- end
- function checkToolBar()
- toolbarSelection=overlay[mouseX]
- if toolbarSelection==1 then paintLoad() end
- if toolbarSelection==2 then paintSave() end
- if toolbarSelection==3 then paintMenu() end
- if toolbarSelection==4 then paintExit() end
- end
- --MAIN PROGRAM--
- while alive do
- drawCanvas()
- drawTools()
- event,mouseX,mouseY,mouseButton=os.pullEvent("click")
- screenInteract()
- drawCanvas()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement