Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local WindowWidth, WindowHeight = term.getSize()
- local shapes = {}
- local function main()
- while (true) do
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.black)
- term.clear()
- paintutils.drawFilledBox(1,1, 16,16, colors.white)
- for x=1,16 do
- term.setCursorPos(x,1)
- local sx = tostring(x)
- if (#sx > 1) then
- term.write(string.sub(sx, 2,2))
- else
- term.write(sx)
- end
- end
- for y=1,16 do
- term.setCursorPos(1,y)
- term.write(y)
- end
- for i,s in ipairs(shapes) do
- paintutils.drawPixel(s.x, s.y, colors.red)
- end
- sleep(0.1)
- end
- end
- local function mouseActions(button, x, y, isDrag)
- if (x <= 16 and y <= 16 and button == 1) then
- table.insert(shapes, {x=x, y=y})
- elseif (x <= 16 and y <= 16 and button == 2) then
- for i,s in ipairs(shapes) do
- if (x==s.x and y==s.y) then
- table.remove(shapes, i)
- break
- end
- end
- end
- end
- local function onClick()
- while (true) do
- local event, button, x, y = os.pullEvent("mouse_click")
- mouseActions(button, x, y, false)
- end
- end
- local function onDrag()
- while (true) do
- local event, button, x, y = os.pullEvent("mouse_drag")
- mouseActions(button, x, y, true)
- end
- end
- parallel.waitForAny(main, onClick, onDrag)
Advertisement
Add Comment
Please, Sign In to add comment