Advertisement
LDDestroier

roterm

Apr 20th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.55 KB | None | 0 0
  1. local getAPI = function(apiname, apipath, apiurl, doDoFile, doScroll)
  2.     apipath = fs.combine(".roterm-api", apipath)
  3.     if (not fs.exists(apipath)) then
  4.         if doScroll then term.scroll(1) end
  5.         print(apiname .. " API not found! Downloading...")
  6.         local prog = http.get(apiurl)
  7.         if not prog then
  8.             if doScroll then term.scroll(1) end
  9.             error("Failed to download " .. apiname .. " API. Abort.")
  10.             term.setCursorPos(1,1)
  11.             return
  12.         end
  13.         local file = fs.open(apipath,"w")
  14.         file.write(prog.readAll())
  15.         file.close()
  16.     end
  17.     if doDoFile then
  18.         return dofile(apipath)
  19.     else
  20.         os.loadAPI(apipath)
  21.     end
  22.     if not _ENV[fs.getName(apipath)] then
  23.         if doScroll then term.scroll(1) end
  24.         error("Failed to load " .. apiname .. " API. Abort.")
  25.         term.setCursorPos(1,1)
  26.         return
  27.     else
  28.         return _ENV[fs.getName(apipath)]
  29.     end
  30. end
  31.  
  32. local nfte  = getAPI("NFT Extra",   "nfte.lua",     "https://github.com/LDDestroier/NFT-Extra/raw/master/nfte.lua", true)
  33. local lddterm   = getAPI("LDDTerm",     "lddterm.lua",  "https://github.com/LDDestroier/CC/raw/master/lddterm-cc.lua",  true)
  34.  
  35. local scr_x, scr_y = term.getSize()
  36.  
  37. lddterm.alwaysRender = false
  38. lddterm.baseTerm = term.current()
  39. local win = lddterm.newWindow(scr_x, scr_y, 1, 1)
  40. local t = win.handle
  41.  
  42. local angle = 0
  43.  
  44. term.redirect(t)
  45.  
  46. lddterm.transformation = function(image)
  47.     local output, adjX, adjY = nfte.rotateImage(image, math.rad(angle))
  48.     return output
  49. end
  50.  
  51. lddterm.drawFunction = function(image, baseTerm)
  52.     baseTerm.clear()
  53.     nfte.drawImageCenter(image, nil, nil, baseTerm)
  54. end
  55.  
  56. lddterm.cursorTransformation = function(x, y)
  57.     local originX = math.floor(scr_x / 2)
  58.     local originY = math.floor(scr_y / 2)
  59.     local ang = math.rad(angle)
  60.     return
  61.         math.floor( 0.5 + (x-originX) * math.cos(ang) - (y-originY) * math.sin(ang) ) + originX,
  62.         math.floor( 0.5 + (x-originX) * math.sin(ang) + (y-originY) * math.cos(ang) ) + originY
  63. end
  64.  
  65. parallel.waitForAny(
  66.     function()
  67.         shell.run("/rom/programs/shell.lua")
  68.     end,
  69.     function()
  70.         local evt
  71.         local tID = os.startTimer(0.05)
  72.         while true do
  73.             evt = {os.pullEvent()}
  74.             if evt[1] == "key" then
  75.                 if evt[2] == keys.pageDown then
  76.                     angle = (angle + 2) % 360
  77.                     lddterm.render(lddterm.transformation, lddterm.drawFunction)
  78.                 elseif evt[2] == keys.pageUp then
  79.                     angle = (angle - 2) % 360
  80.                     lddterm.render(lddterm.transformation, lddterm.drawFunction)
  81.                 end
  82.             elseif evt[1] == "timer" then
  83.                 if evt[2] == tID then
  84.                     lddterm.render(lddterm.transformation, lddterm.drawFunction)
  85.                     tID = os.startTimer(0.05)
  86.                 end
  87.             end
  88.         end
  89.     end
  90. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement