• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# drawv2

a guest Apr 7th, 2020 195 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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.black,
20.     colors.red,
21.     colors.green,
22.     colors.blue,
23.     colors.brown,
24.     colors.yellow,
25.     colors.magenta,
26.     colors.cyan,
27.     colors.orange,
28.     colors.white
29. }
30.
31. local btns = {
32.     [1]={1,10,18,12,colors.black},
33.     [2]={1,11,2,12,colors.red},
34.     [3]={3,11,4,12,colors.green},
35.     [4]={5,11,6,12,colors.blue},
36.     [5]={7,11,8,12,colors.brown},
37.     [6]={9,11,10,12,colors.yellow},
38.     [7]={11,11,12,12,colors.magenta},
39.     [8]={13,11,14,12,colors.cyan},
40.     [9]={15,11,16,12,colors.orange},
41.     [10]={17,11,19,11,colors.white},
42. }
43.
44. while true do
45.     paintFlag = true
46.     m2.setCursorPos(1,1)
47.
48.     for k, b in ipairs(btns) do
49.         paintutils.drawFilledBox(b[1],b[2],b[3],b[4],b[5])
50.     end
51.
52.     local e = {os.pullEvent()}
53.     m2.write(e[3])
54.     m2.write(e[4])
55.     if (e[1] == "monitor_touch") then
56.
57.         for k, b in ipairs(btns) do
58.             if (contains(b,e[3],e[4])==true) then
59.                 c = cols[k]
60.                 m2.setCursorPos(1,2)
61.                 m2.write()
62.                 paintFlag=false
63.             end
64.         end
65.
66.         if(paintFlag) then
67.             paintutils.drawPixel(e[3],e[4],c)
68.         end
69.
70.     end
71. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top