Advertisement
NorthmcCormick

Untitled

Sep 21st, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.39 KB | None | 0 0
  1. --Global
  2.  
  3. local tArgs = {...}
  4.  
  5. local drawing = true
  6. local showingMenu = false
  7. local colorA = colors.white
  8. local colorB = colors.black
  9. local bgColor = colors.black
  10. local quitting = false
  11. local playing = false
  12. local playing_frame = 1
  13. local name = ""
  14.  
  15. ------ Frame
  16. local splash_currentFrame = {}
  17. local splash_blankFrame = {}
  18.  
  19. local splash_Frames = {splash_currentFrame}
  20.  
  21. local splash_FrameCount = 1
  22. local splash_currentFrameNumber = 1
  23.  
  24. --Passing
  25.  
  26. if tArgs[1] == "edit" then
  27. --tArgs[2] = the file name
  28. local file = fs.open(tArgs[2], 'r')
  29. local contents = file.readAll()
  30. splash_Frames = textutils.unserialize(contents)
  31. file.close()
  32.  
  33. local count = 0
  34. for _ in pairs(splash_Frames) do count = count + 1 end
  35.  
  36. splash_FrameCount = count
  37. end
  38.  
  39. if tArgs[1] == "new" then
  40. name = tArgs[2]
  41. end
  42.  
  43. if tArgs[1] == nil then
  44.  
  45. while true do
  46. write("Splash (Edit | New) name")
  47. os.sleep(5)
  48. end
  49.  
  50. end
  51.  
  52.  
  53.  
  54. --Functions
  55.  
  56. local function tablelength(T)
  57. local count = 0
  58. for _ in pairs(T) do count = count + 1 end
  59. return count
  60. end
  61.  
  62. local function paintPixel(posx, posy, button)
  63. --If button 1, paint color A, if button 2, paint color B
  64. ---print("Painting Pixel")
  65. if button == 1 then
  66. --print("Color A")
  67. table.insert(splash_currentFrame, {posx, posy, colorA })
  68. elseif button == 2 then
  69. --print("Color B")
  70. table.insert(splash_currentFrame, {posx, posy, colorB })
  71. end
  72.  
  73. end
  74.  
  75. function deepcopy(orig)
  76. local orig_type = type(orig)
  77. local copy
  78. if orig_type == 'table' then
  79. copy = {}
  80. for orig_key, orig_value in next, orig, nil do
  81. copy[deepcopy(orig_key)] = deepcopy(orig_value)
  82. end
  83. setmetatable(copy, deepcopy(getmetatable(orig)))
  84. else -- number, string, boolean, etc
  85. copy = orig
  86. end
  87. return copy
  88. end
  89.  
  90. local function checkEvents()
  91. event, param1, param2, param3 = os.pullEvent()
  92.  
  93. if event == "mouse_click" then
  94. if drawing then
  95. paintPixel(param2, param3, param1)
  96. elseif showingMenu == true then
  97. --Get the coords, press the settings
  98. local posx = param2
  99. local posy = param3
  100.  
  101. --Selecting A Color
  102. local newColor = nil
  103.  
  104. if (posx == 2) or (posx == 3) then
  105. if(posy == 2) then newColor = colors.red end
  106. if(posy == 3) then newColor = colors.orange end
  107. if(posy == 4) then newColor = colors.yellow end
  108. if(posy == 5) then newColor = colors.lime end
  109. if(posy == 6) then newColor = colors.green end
  110. if(posy == 7) then newColor = colors.cyan end
  111. if(posy == 8) then newColor = colors.blue end
  112. if(posy == 9) then newColor = colors.lightBlue end
  113. if(posy == 10) then newColor = colors.purple end
  114. if(posy == 11) then newColor = colors.magenta end
  115. if(posy == 12) then newColor = colors.pink end
  116. if(posy == 13) then newColor = colors.brown end
  117. if(posy == 14) then newColor = colors.gray end
  118. if(posy == 15) then newColor = colors.lightGray end
  119. if(posy == 16) then newColor = colors.black end
  120. if(posy == 17) then newColor = colors.white end
  121.  
  122. if newColor ~= nil then
  123. if param1 == 1 then colorA = newColor end
  124. if param1 == 2 then colorB = newColor end
  125. end
  126. end
  127.  
  128. -- New Frame
  129. if (posx >= 8) and (posx <= 18) and (posy >= 6) and (posy <= 6) then
  130. splash_FrameCount = splash_FrameCount + 1
  131. splash_Frames[splash_FrameCount] = {}
  132. splash_currentFrameNumber = splash_FrameCount;
  133. end
  134.  
  135. -- New Frame Copy
  136. if (posx >= 8) and (posx <= 18) and (posy >= 8) and (posy <= 8) then
  137.  
  138. splash_FrameCount = splash_FrameCount + 1
  139.  
  140. splash_Frames[splash_FrameCount] = deepcopy(splash_Frames[splash_currentFrameNumber])
  141.  
  142. --splash_Frames[splash_FrameCount] = splash_Frames[splash_currentFrameNumber]
  143. splash_currentFrameNumber = splash_FrameCount;
  144. end
  145.  
  146. --Prev Frame
  147. if (posx >= 5) and (posx <= 13) and (posy >= 4) and (posy <= 4) then
  148. if splash_currentFrameNumber ~= 1 then
  149. splash_currentFrameNumber = splash_currentFrameNumber - 1
  150. end
  151. end
  152.  
  153. --Next Frame
  154. if (posx >= 14) and (posx <= 20) and (posy >= 4) and (posy <= 4) then
  155. if splash_currentFrameNumber ~= splash_FrameCount then
  156. splash_currentFrameNumber = splash_currentFrameNumber + 1
  157. end
  158. end
  159.  
  160. --Quitting
  161. if (posx >= 42) and (posx <= 48) and (posy >= 9) and (posy <= 17) then
  162. quitting = true
  163. end
  164.  
  165. --Saving
  166. if (posx >= 42) and (posx <= 48) and (posy >= 1) and (posy <= 7) then
  167. --quitting = true
  168. local file = fs.open(name, 'w')
  169. file.write(textutils.serialize(splash_Frames))
  170. file.close()
  171. end
  172. end
  173. elseif event == "key" then
  174. --31 -- 16/18 -- 38
  175. if param1 == 31 then
  176. if showingMenu == true then
  177. showingMenu = false
  178. drawing = true
  179. else
  180. drawing = false
  181. showingMenu = true
  182. end
  183. end
  184.  
  185. if param1 == 16 then
  186. if splash_currentFrameNumber ~= 1 then
  187. splash_currentFrameNumber = splash_currentFrameNumber - 1
  188. end
  189. end
  190.  
  191. if param1 == 18 then
  192. if splash_currentFrameNumber ~= splash_FrameCount then
  193. splash_currentFrameNumber = splash_currentFrameNumber + 1
  194. end
  195. end
  196.  
  197. if param1 == 38 then
  198.  
  199. end
  200.  
  201. --print (param1)
  202. end
  203. end
  204.  
  205. --Render
  206.  
  207. ------ Render That
  208. local function renderCurrentFrame(currentFrame)
  209. for p = 1,#currentFrame do
  210. paintutils.drawPixel(currentFrame[p][1], currentFrame[p][2], currentFrame[p][3])
  211. end
  212. end
  213.  
  214. local function renderMenu()
  215. -- Quit Button
  216. for i=44,48 do
  217. paintutils.drawPixel(i,9, colors.red)
  218. end
  219.  
  220. for i=10,17 do
  221. paintutils.drawPixel(48,i, colors.red)
  222. end
  223.  
  224. for i=44,48 do
  225. paintutils.drawPixel(i,17, colors.red)
  226. end
  227.  
  228. paintutils.drawPixel(44,11, colors.red)
  229. paintutils.drawPixel(45,12, colors.red)
  230. paintutils.drawPixel(46,13, colors.red)
  231. paintutils.drawPixel(45,14, colors.red)
  232. paintutils.drawPixel(44,15, colors.red)
  233.  
  234. for i=42,45 do
  235. paintutils.drawPixel(i,13, colors.red)
  236. end
  237.  
  238. -- Save Button
  239.  
  240. paintutils.drawPixel(42,2, colors.cyan)
  241. paintutils.drawPixel(42,3, colors.cyan)
  242. paintutils.drawPixel(42,4, colors.cyan)
  243. paintutils.drawPixel(42,5, colors.cyan)
  244. paintutils.drawPixel(42,6, colors.cyan)
  245. paintutils.drawPixel(42,7, colors.cyan)
  246.  
  247. paintutils.drawPixel(43,7, colors.cyan)
  248. paintutils.drawPixel(44,7, colors.cyan)
  249. paintutils.drawPixel(45,7, colors.cyan)
  250. paintutils.drawPixel(46,7, colors.cyan)
  251. paintutils.drawPixel(47,7, colors.cyan)
  252. paintutils.drawPixel(48,7, colors.cyan)
  253.  
  254. paintutils.drawPixel(48,2, colors.cyan)
  255. paintutils.drawPixel(48,3, colors.cyan)
  256. paintutils.drawPixel(48,4, colors.cyan)
  257. paintutils.drawPixel(48,5, colors.cyan)
  258. paintutils.drawPixel(48,6, colors.cyan)
  259.  
  260. paintutils.drawPixel(45,5, colors.cyan)
  261. paintutils.drawPixel(45,4, colors.cyan)
  262. paintutils.drawPixel(45,3, colors.cyan)
  263. paintutils.drawPixel(45,2, colors.cyan)
  264. paintutils.drawPixel(45,1, colors.cyan)
  265.  
  266. paintutils.drawPixel(44,4, colors.cyan)
  267. paintutils.drawPixel(46,4, colors.cyan)
  268. paintutils.drawPixel(43,3, colors.cyan)
  269. paintutils.drawPixel(47,3, colors.cyan)
  270.  
  271. -- Color Choices (16)
  272. for i=2,3 do
  273. paintutils.drawPixel(i,2, colors.red)
  274. paintutils.drawPixel(i,3, colors.orange)
  275. paintutils.drawPixel(i,4, colors.yellow)
  276. paintutils.drawPixel(i,5, colors.lime)
  277. paintutils.drawPixel(i,6, colors.green)
  278. paintutils.drawPixel(i,7, colors.cyan)
  279. paintutils.drawPixel(i,8, colors.blue)
  280. paintutils.drawPixel(i,9, colors.lightBlue)
  281. paintutils.drawPixel(i,10, colors.purple)
  282. paintutils.drawPixel(i,11, colors.magenta)
  283. paintutils.drawPixel(i,12, colors.pink)
  284. paintutils.drawPixel(i,13, colors.brown)
  285. paintutils.drawPixel(i,14, colors.gray)
  286. paintutils.drawPixel(i,15, colors.lightGray)
  287. paintutils.drawPixel(i,16, colors.black)
  288. paintutils.drawPixel(i,17, colors.white)
  289. end
  290.  
  291. -- Frame Count
  292. term.setBackgroundColor(colors.black)
  293. term.setTextColor(colors.white)
  294.  
  295. term.setCursorPos(6, 2)
  296. term.write("Total Frames: ")
  297. term.write(splash_FrameCount)
  298.  
  299. term.setCursorPos(6, 3)
  300. term.write("Current Frame: ")
  301. term.write(splash_currentFrameNumber)
  302.  
  303. term.setCursorPos(5, 4)
  304. term.write("<< Prev | Next >>")
  305.  
  306. term.setCursorPos(8, 6)
  307. term.write("+ New Frame")
  308.  
  309. term.setCursorPos(7, 8)
  310. term.write("+ Copy Frame")
  311.  
  312. term.setCursorPos(6, 10)
  313. term.write("- Current Frame")
  314. end
  315.  
  316. --App
  317.  
  318. while true do
  319.  
  320. term.setBackgroundColor(bgColor)
  321. term.clear()
  322.  
  323. splash_currentFrame = splash_Frames[splash_currentFrameNumber]
  324.  
  325. if playing == true then
  326. if splash_FrameCount >= playing_frame then
  327. --go back to 0
  328. playing_frame = 1
  329. else
  330. --go up a frame
  331. playing_frame = playing_frame + 1
  332. end
  333. renderCurrentFrame(splash_Frames[playing_frame])
  334. else
  335. if showingMenu then
  336. renderMenu()
  337. else
  338. renderCurrentFrame(splash_currentFrame)
  339. end
  340. end
  341.  
  342. checkEvents()
  343.  
  344. if quitting then
  345. term.clear()
  346. term.setTextColor(colors.black)
  347. print("Successfully closed Splash, come paint again!")
  348. break
  349. end
  350.  
  351. os.sleep(0)
  352. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement