paramus

3D printer modeler

Sep 9th, 2026 (edited)
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | Gaming | 0 0
  1. local WindowWidth, WindowHeight = term.getSize()
  2. local shapes = {}
  3.  
  4. local function main()
  5.     while (true) do
  6.         term.setBackgroundColor(colors.black)
  7.         term.setTextColor(colors.black)
  8.         term.clear()
  9.        
  10.         paintutils.drawFilledBox(1,1, 16,16, colors.white)
  11.        
  12.         for x=1,16 do
  13.             term.setCursorPos(x,1)
  14.             local sx = tostring(x)
  15.             if (#sx > 1) then
  16.                 term.write(string.sub(sx, 2,2))
  17.             else
  18.                 term.write(sx)
  19.             end
  20.         end
  21.        
  22.         for y=1,16 do
  23.             term.setCursorPos(1,y)
  24.             term.write(y)
  25.         end
  26.        
  27.         for i,s in ipairs(shapes) do
  28.             paintutils.drawPixel(s.x, s.y, colors.red)
  29.         end
  30.        
  31.         sleep(0.1)
  32.     end
  33. end
  34.  
  35. local function mouseActions(button, x, y, isDrag)
  36.     if (x <= 16 and y <= 16 and button == 1) then
  37.         table.insert(shapes, {x=x, y=y})
  38.     elseif (x <= 16 and y <= 16 and button == 2) then
  39.         for i,s in ipairs(shapes) do
  40.             if (x==s.x and y==s.y) then
  41.                 table.remove(shapes, i)
  42.                 break
  43.             end
  44.         end
  45.     end
  46. end
  47.  
  48. local function onClick()
  49.     while (true) do
  50.         local event, button, x, y = os.pullEvent("mouse_click")
  51.         mouseActions(button, x, y, false)
  52.     end
  53. end
  54.  
  55. local function onDrag()
  56.     while (true) do
  57.         local event, button, x, y = os.pullEvent("mouse_drag")
  58.         mouseActions(button, x, y, true)
  59.     end
  60. end
  61.  
  62. parallel.waitForAny(main, onClick, onDrag)
Advertisement
Add Comment
Please, Sign In to add comment