Advertisement
LDDestroier

CC test rotate toy

Apr 25th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. local tArg = {...}
  2. local filename = tArg[1]
  3.  
  4. getPicDetails = function(picture)
  5.     local top, bottom, left, right
  6.     for a = 1, #picture do
  7.         if #picture[a] > 0 then
  8.             top = a
  9.             break
  10.         end
  11.     end
  12.     for a = 1, #picture do
  13.         if #picture[#picture-(a-1)] > 0 then
  14.             bottom = #picture-(a-1)
  15.             break
  16.         end
  17.     end
  18.     left, right = 10000, 0
  19.     for a = 1, #picture do
  20.         for b = 1, #picture[a] do
  21.             if picture[a][b] then
  22.                 if picture[a][b] ~= 0 then
  23.                     if b < left then
  24.                         left = b
  25.                     end
  26.                     if b > right then
  27.                         right = b
  28.                     end
  29.                 end
  30.             end
  31.         end
  32.     end
  33.     return top, bottom, left, right, math.floor((left+right)/2), math.floor((bottom+top)/2)
  34. end
  35.  
  36. skewImage = function(pic,xrotate,yrotate,cenX,cenY) --0 is normal
  37.     local newPic = {}
  38.     local picTop,picBot,picLeft,picRight,centerX,centerY = getPicDetails(pic)
  39.     centerX = cenX or centerX
  40.     centerY = cenY or centerY
  41.     for y = 1, #pic do
  42.         if pic[y] then
  43.             newPic[math.floor(((y)*math.cos(yrotate or 0))+centerY)] = {}
  44.             for x = 1, #pic[y] do
  45.                 if pic[y][x] then
  46.                     newPic[math.floor(((y)*math.cos(yrotate or 0))+centerY)][math.floor(((x)*math.cos(xrotate or 0))+centerX)] = pic[y][x]
  47.                 end
  48.             end
  49.         end
  50.     end
  51.     return newPic
  52. end
  53.  
  54. if not filename then
  55.     return print(fs.getName(shell.getRunningProgram()).." <nfp file>")
  56. end
  57. paint = paintutils.loadImage(filename)
  58.  
  59. term.setBackgroundColor(colors.black)
  60. term.clear()
  61.  
  62. local scr_x, scr_y = term.getSize()
  63.  
  64. while true do
  65.     for a = 1, 360 do
  66.         local pickcher = skewImage(paint,a,0)
  67.         paintutils.drawImage(pickcher,scr_x/2,scr_y/2)
  68.         sleep(0.1)
  69.         term.setBackgroundColor(colors.black)
  70.         term.clear()
  71.     end
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement