Advertisement
guitarplayer616

Projection (Updated Paint)

Jun 23rd, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.44 KB | None | 0 0
  1. --[[INSTRUCTIONS:
  2.         pixels in upper-right corner represent color selection.
  3.         left = text color.
  4.         middle = background color (leftClick).
  5.         right = alternate background color (rightClick).
  6.        
  7.         click on an upper-right pixel and use shift/control to cycle through its colors.
  8.         press any keyboard character to select it.
  9.         use mouseclick/drag to paint.
  10.         press alt to exit.
  11.     ]]
  12.        
  13. local w,h = term.getSize()
  14.  
  15. function switchColors()
  16.   local alphabet = {"a","b","c","d","e","f"}
  17.   for i,v in pairs(colors) do
  18.     if tonumber(v) then
  19.       res = math.log(v)/math.log(2)
  20.       if res > 9 then
  21.         res = alphabet[res-9]
  22.       end
  23.       colors[i] = tostring(res)
  24.     end
  25.   end
  26. end
  27.  
  28. function draw(str,xPos,yPos,txtcol,bakcol)
  29.   local str = tostring(str) or ""
  30.   local txtcol = txtcol or txtsel
  31.   local bakcol = bakcol or baksel
  32.   if xPos and yPos then
  33.     term.setCursorPos(xPos, yPos)
  34.   end
  35.   if term.blit then
  36.     term.blit(str,string.rep(txtcol,#str),string.rep(bakcol,#str))
  37.   else
  38.     term.setBackgroundColor(bakcol)
  39.     term.setTextColor(txtcol)
  40.     term.write(str)
  41.   end
  42. end
  43.  
  44. if term.blit then
  45.     switchColors()
  46. else
  47.     os.loadAPI(shell.resolve("rom/apis/colors"))
  48. end
  49.  
  50. term.clear()
  51. baksel = colors.yellow
  52. txtsel = colors.white
  53. altsel = colors.black
  54.  
  55. local pallet = {}
  56. n = 0
  57. for i,v in pairs(colors) do
  58.     if tonumber(v) then
  59.       n = n + 1
  60.       pallet[n] = v
  61.     end
  62. end
  63.  
  64. local sel = 'bak'
  65. local nCol = 1
  66. local tCol = 1
  67. local aCol = 1
  68. local key = " "
  69. while true do
  70.     local events = {coroutine.yield()}
  71.     if events[1] == "mouse_click" or events[1] == "mouse_drag" then
  72.         if events[2] == 1 then
  73.             if events[3] == w-1 and events[4] == 1 then
  74.                 sel = 'txt'
  75.             elseif events[3] == w-2 and events[4] == 1 then
  76.                 sel = 'bak'
  77.             elseif events[3] == w and events[4] == 1 then
  78.                 sel = 'alt'
  79.             else
  80.               draw(key,events[3],events[4])
  81.             end
  82.         elseif events[2] == 2 then
  83.             draw(key,events[3],events[4],txtsel,altsel)
  84.         end
  85.     elseif events[1] == "char" then
  86.         key = tostring(events[2])
  87.     --[[elseif events[1] == "mouse_scroll" then
  88.         if events[2] == 1 then
  89.             if nCol < #pallet then
  90.               nCol = nCol + 1
  91.               baksel = pallet[nCol]
  92.             end
  93.         elseif events[2] == -1 then
  94.             if nCol > 1 then
  95.               nCol = nCol - 1
  96.               baksel = pallet[nCol]
  97.             end
  98.         end]]
  99.     elseif events[1] == "key" then
  100.         if events[2] == 42 then
  101.             if sel == 'txt' then
  102.               if tCol < #pallet then
  103.                 tCol = tCol + 1
  104.                 txtsel = pallet[tCol]
  105.               end
  106.             elseif sel == 'bak' then
  107.                 if nCol < #pallet then
  108.                     nCol = nCol + 1
  109.                     baksel = pallet[nCol]
  110.                 end
  111.             elseif sel == 'alt' then
  112.                 if aCol < #pallet then
  113.                     aCol = aCol + 1
  114.                     altsel = pallet[aCol]
  115.                 end
  116.             end
  117.         elseif events[2] == 29 then
  118.             if sel == 'txt' then
  119.               if tCol > 1 then
  120.                 tCol = tCol - 1
  121.                 txtsel = pallet[tCol]
  122.               end
  123.             elseif sel == 'bak' then
  124.                 if nCol > 1 then
  125.                     nCol = nCol - 1
  126.                     baksel = pallet[nCol]
  127.                 end
  128.             elseif sel == 'alt' then
  129.                 if aCol > 1 then
  130.                     aCol = aCol - 1
  131.                     altsel = pallet[aCol]
  132.                 end
  133.             end
  134.         end
  135.         elseif events[2] == 56 then
  136.             break
  137.         end
  138.     draw(" ",w-1,1,_,txtsel)
  139.     draw(" ",w-2,1)
  140.     draw(" ",w,1,_,altsel)
  141. end
  142.  
  143.  
  144. for i,v in pairs(pallet) do
  145.     print(i,": ",v)
  146. end
  147. print(#pallet)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement