Advertisement
Guest User

drawv2

a guest
Apr 7th, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.74 KB | None | 0 0
  1. function contains(b,x,y)
  2.     if (b[1]<=x and x<=b[2]) and (b[3]<=y and y<=b[4]) then
  3.         return true
  4.     else
  5.         return false
  6.     end
  7. end
  8.  
  9. local m = peripheral.wrap("left")
  10. local m2 = peripheral.wrap("top")
  11. m2.clear()
  12. local paintFlag = true
  13.  
  14. term.redirect(m)
  15. term.setBackgroundColor(colors.white)
  16. term.clear()
  17.  
  18. local cols = {
  19.     colors.red,
  20.     colors.green,
  21.     colors.blue,
  22.     colors.brown,
  23.     colors.yellow,
  24.     colors.magenta,
  25.     colors.cyan,
  26.     colors.orange,
  27.     colors.white
  28. }
  29.  
  30. local btns = {
  31.     [1]={1,10,18,12,colors.black},
  32.     [2]={1,11,2,12,colors.red},
  33.     [3]={3,11,4,12,colors.green},
  34.     [4]={5,11,6,12,colors.blue},
  35.     [5]={7,11,8,12,colors.brown},
  36.     [6]={9,11,10,12,colors.yellow},
  37.     [7]={11,11,12,12,colors.magenta},
  38.     [8]={13,11,14,12,colors.cyan},
  39.     [9]={15,11,16,12,colors.orange},
  40.     [10]={17,11,19,11,colors.white},
  41. }
  42.  
  43. while true do
  44.     paintFlag = true
  45.     m2.setCursorPos(1,1)
  46.      
  47.     for k, b in ipairs(btns) do
  48.         paintutils.drawFilledBox(b[1],b[2],b[3],b[4],b[5])
  49.     end    
  50.                                                                                                                                                                                                
  51.     local e = {os.pullEvent()}
  52.     m2.write(e[3])
  53.     m2.write(e[4])
  54.     if (e[1] == "monitor_touch") then
  55.        
  56.         for k, b in ipairs(btns) do
  57.             if (contains(b,e[3],e[4])==true) then
  58.                 c = cols[k]
  59.                 m2.setCursorPos(1,2)
  60.                 m2.write()
  61.                 paintFlag=false
  62.             end
  63.         end
  64.        
  65.         if(paintFlag) then
  66.             paintutils.drawPixel(e[3],e[4],c)
  67.         end
  68.                    
  69.     end
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement