SHARE
TWEET

Untitled

a guest Jan 28th, 2020 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Get hold of the canvas
  2. local interface = peripheral.wrap("back")
  3. local canvas = interface.canvas()
  4. -- And add a rectangle
  5. local rect = canvas.addRectangle(0, 0, 100, 100, 0xFF0000FF)
  6. rect.setSize(250, 30)
  7. rect.setAlpha(100) -- Let's make this see through
  8.  
  9. local text = canvas.addText({ x = 5, y = 5 }, "")
  10. text.setScale(3)
  11. while true do
  12.   text.setText("Time is " .. textutils.formatTime(os.time()))
  13.   sleep(1)
  14. end
  15.  
  16. -- CUTT HERE
  17.  
  18. local canvas = peripheral.wrap("back").canvas()
  19. canvas.clear() -- Get rid of our previous clock
  20.  
  21. local group = canvas.addGroup({ 0, 0 })
  22.  
  23. -- Look, we add items to our group instead
  24. group.addRectangle(0, 0, 240, 30, 0xFF000064)
  25.  
  26. local text = group.addText({ 5, 5 }, "")
  27. text.setScale(3)
  28.  
  29. local x, y, dx, dy = 0, 0, 5, 5
  30.  
  31. -- Compute the dimensions we can move within
  32. local width, height = canvas.getSize()
  33. width = width - 240
  34. height = height - 30
  35.  
  36. while true do
  37.   -- Bounce the group around the canvas
  38.   x = x + dx
  39.   if x < 0 then x, dx = 0, -dx end
  40.   if x > width then x, dx = width, -dx end
  41.  
  42.   y = y + dy
  43.   if y < 0 then y, dy = 0, -dy end
  44.   if y > height then y, dy = height, -dy end
  45.  
  46.   group.setPosition(x, y)
  47.  
  48.   -- And update the time
  49.   text.setText("Time is " .. textutils.formatTime(os.time()))
  50.  
  51.   sleep(0.05)
  52. 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. OK, I Understand
Top