Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Global
- local tArgs = {...}
- local drawing = true
- local showingMenu = false
- local colorA = colors.white
- local colorB = colors.black
- local bgColor = colors.black
- local quitting = false
- local playing = false
- local playing_frame = 1
- local name = ""
- ------ Frame
- local splash_currentFrame = {}
- local splash_blankFrame = {}
- local splash_Frames = {splash_currentFrame}
- local splash_FrameCount = 1
- local splash_currentFrameNumber = 1
- --Passing
- if tArgs[1] == "edit" then
- --tArgs[2] = the file name
- local file = fs.open(tArgs[2], 'r')
- local contents = file.readAll()
- splash_Frames = textutils.unserialize(contents)
- file.close()
- local count = 0
- for _ in pairs(splash_Frames) do count = count + 1 end
- splash_FrameCount = count
- end
- if tArgs[1] == "new" then
- name = tArgs[2]
- end
- if tArgs[1] == nil then
- while true do
- write("Splash (Edit | New) name")
- os.sleep(5)
- end
- end
- --Functions
- local function tablelength(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- end
- local function paintPixel(posx, posy, button)
- --If button 1, paint color A, if button 2, paint color B
- ---print("Painting Pixel")
- if button == 1 then
- --print("Color A")
- table.insert(splash_currentFrame, {posx, posy, colorA })
- elseif button == 2 then
- --print("Color B")
- table.insert(splash_currentFrame, {posx, posy, colorB })
- end
- end
- function deepcopy(orig)
- local orig_type = type(orig)
- local copy
- if orig_type == 'table' then
- copy = {}
- for orig_key, orig_value in next, orig, nil do
- copy[deepcopy(orig_key)] = deepcopy(orig_value)
- end
- setmetatable(copy, deepcopy(getmetatable(orig)))
- else -- number, string, boolean, etc
- copy = orig
- end
- return copy
- end
- local function checkEvents()
- event, param1, param2, param3 = os.pullEvent()
- if event == "mouse_click" then
- if drawing then
- paintPixel(param2, param3, param1)
- elseif showingMenu == true then
- --Get the coords, press the settings
- local posx = param2
- local posy = param3
- --Selecting A Color
- local newColor = nil
- if (posx == 2) or (posx == 3) then
- if(posy == 2) then newColor = colors.red end
- if(posy == 3) then newColor = colors.orange end
- if(posy == 4) then newColor = colors.yellow end
- if(posy == 5) then newColor = colors.lime end
- if(posy == 6) then newColor = colors.green end
- if(posy == 7) then newColor = colors.cyan end
- if(posy == 8) then newColor = colors.blue end
- if(posy == 9) then newColor = colors.lightBlue end
- if(posy == 10) then newColor = colors.purple end
- if(posy == 11) then newColor = colors.magenta end
- if(posy == 12) then newColor = colors.pink end
- if(posy == 13) then newColor = colors.brown end
- if(posy == 14) then newColor = colors.gray end
- if(posy == 15) then newColor = colors.lightGray end
- if(posy == 16) then newColor = colors.black end
- if(posy == 17) then newColor = colors.white end
- if newColor ~= nil then
- if param1 == 1 then colorA = newColor end
- if param1 == 2 then colorB = newColor end
- end
- end
- -- New Frame
- if (posx >= 8) and (posx <= 18) and (posy >= 6) and (posy <= 6) then
- splash_FrameCount = splash_FrameCount + 1
- splash_Frames[splash_FrameCount] = {}
- splash_currentFrameNumber = splash_FrameCount;
- end
- -- New Frame Copy
- if (posx >= 8) and (posx <= 18) and (posy >= 8) and (posy <= 8) then
- splash_FrameCount = splash_FrameCount + 1
- splash_Frames[splash_FrameCount] = deepcopy(splash_Frames[splash_currentFrameNumber])
- --splash_Frames[splash_FrameCount] = splash_Frames[splash_currentFrameNumber]
- splash_currentFrameNumber = splash_FrameCount;
- end
- --Prev Frame
- if (posx >= 5) and (posx <= 13) and (posy >= 4) and (posy <= 4) then
- if splash_currentFrameNumber ~= 1 then
- splash_currentFrameNumber = splash_currentFrameNumber - 1
- end
- end
- --Next Frame
- if (posx >= 14) and (posx <= 20) and (posy >= 4) and (posy <= 4) then
- if splash_currentFrameNumber ~= splash_FrameCount then
- splash_currentFrameNumber = splash_currentFrameNumber + 1
- end
- end
- --Quitting
- if (posx >= 42) and (posx <= 48) and (posy >= 9) and (posy <= 17) then
- quitting = true
- end
- --Saving
- if (posx >= 42) and (posx <= 48) and (posy >= 1) and (posy <= 7) then
- --quitting = true
- local file = fs.open(name, 'w')
- file.write(textutils.serialize(splash_Frames))
- file.close()
- end
- end
- elseif event == "key" then
- --31 -- 16/18 -- 38
- if param1 == 31 then
- if showingMenu == true then
- showingMenu = false
- drawing = true
- else
- drawing = false
- showingMenu = true
- end
- end
- if param1 == 16 then
- if splash_currentFrameNumber ~= 1 then
- splash_currentFrameNumber = splash_currentFrameNumber - 1
- end
- end
- if param1 == 18 then
- if splash_currentFrameNumber ~= splash_FrameCount then
- splash_currentFrameNumber = splash_currentFrameNumber + 1
- end
- end
- if param1 == 38 then
- end
- --print (param1)
- end
- end
- --Render
- ------ Render That
- local function renderCurrentFrame(currentFrame)
- for p = 1,#currentFrame do
- paintutils.drawPixel(currentFrame[p][1], currentFrame[p][2], currentFrame[p][3])
- end
- end
- local function renderMenu()
- -- Quit Button
- for i=44,48 do
- paintutils.drawPixel(i,9, colors.red)
- end
- for i=10,17 do
- paintutils.drawPixel(48,i, colors.red)
- end
- for i=44,48 do
- paintutils.drawPixel(i,17, colors.red)
- end
- paintutils.drawPixel(44,11, colors.red)
- paintutils.drawPixel(45,12, colors.red)
- paintutils.drawPixel(46,13, colors.red)
- paintutils.drawPixel(45,14, colors.red)
- paintutils.drawPixel(44,15, colors.red)
- for i=42,45 do
- paintutils.drawPixel(i,13, colors.red)
- end
- -- Save Button
- paintutils.drawPixel(42,2, colors.cyan)
- paintutils.drawPixel(42,3, colors.cyan)
- paintutils.drawPixel(42,4, colors.cyan)
- paintutils.drawPixel(42,5, colors.cyan)
- paintutils.drawPixel(42,6, colors.cyan)
- paintutils.drawPixel(42,7, colors.cyan)
- paintutils.drawPixel(43,7, colors.cyan)
- paintutils.drawPixel(44,7, colors.cyan)
- paintutils.drawPixel(45,7, colors.cyan)
- paintutils.drawPixel(46,7, colors.cyan)
- paintutils.drawPixel(47,7, colors.cyan)
- paintutils.drawPixel(48,7, colors.cyan)
- paintutils.drawPixel(48,2, colors.cyan)
- paintutils.drawPixel(48,3, colors.cyan)
- paintutils.drawPixel(48,4, colors.cyan)
- paintutils.drawPixel(48,5, colors.cyan)
- paintutils.drawPixel(48,6, colors.cyan)
- paintutils.drawPixel(45,5, colors.cyan)
- paintutils.drawPixel(45,4, colors.cyan)
- paintutils.drawPixel(45,3, colors.cyan)
- paintutils.drawPixel(45,2, colors.cyan)
- paintutils.drawPixel(45,1, colors.cyan)
- paintutils.drawPixel(44,4, colors.cyan)
- paintutils.drawPixel(46,4, colors.cyan)
- paintutils.drawPixel(43,3, colors.cyan)
- paintutils.drawPixel(47,3, colors.cyan)
- -- Color Choices (16)
- for i=2,3 do
- paintutils.drawPixel(i,2, colors.red)
- paintutils.drawPixel(i,3, colors.orange)
- paintutils.drawPixel(i,4, colors.yellow)
- paintutils.drawPixel(i,5, colors.lime)
- paintutils.drawPixel(i,6, colors.green)
- paintutils.drawPixel(i,7, colors.cyan)
- paintutils.drawPixel(i,8, colors.blue)
- paintutils.drawPixel(i,9, colors.lightBlue)
- paintutils.drawPixel(i,10, colors.purple)
- paintutils.drawPixel(i,11, colors.magenta)
- paintutils.drawPixel(i,12, colors.pink)
- paintutils.drawPixel(i,13, colors.brown)
- paintutils.drawPixel(i,14, colors.gray)
- paintutils.drawPixel(i,15, colors.lightGray)
- paintutils.drawPixel(i,16, colors.black)
- paintutils.drawPixel(i,17, colors.white)
- end
- -- Frame Count
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(6, 2)
- term.write("Total Frames: ")
- term.write(splash_FrameCount)
- term.setCursorPos(6, 3)
- term.write("Current Frame: ")
- term.write(splash_currentFrameNumber)
- term.setCursorPos(5, 4)
- term.write("<< Prev | Next >>")
- term.setCursorPos(8, 6)
- term.write("+ New Frame")
- term.setCursorPos(7, 8)
- term.write("+ Copy Frame")
- term.setCursorPos(6, 10)
- term.write("- Current Frame")
- end
- --App
- while true do
- term.setBackgroundColor(bgColor)
- term.clear()
- splash_currentFrame = splash_Frames[splash_currentFrameNumber]
- if playing == true then
- if splash_FrameCount >= playing_frame then
- --go back to 0
- playing_frame = 1
- else
- --go up a frame
- playing_frame = playing_frame + 1
- end
- renderCurrentFrame(splash_Frames[playing_frame])
- else
- if showingMenu then
- renderMenu()
- else
- renderCurrentFrame(splash_currentFrame)
- end
- end
- checkEvents()
- if quitting then
- term.clear()
- term.setTextColor(colors.black)
- print("Successfully closed Splash, come paint again!")
- break
- end
- os.sleep(0)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement