Guest User

screen.lua

a guest
Jul 7th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. function wrapMon()
  2.     for i, v in ipairs(peripheral.getNames()) do
  3.         if peripheral.getType(v) == 'monitor' then
  4.             monitor = peripheral.wrap(v)
  5.             return monitor
  6.         end
  7.     end
  8. end
  9.  
  10. wrapMon()
  11.  
  12.  
  13. function middle()
  14.     width, height = monitor.getSize()
  15.     x = math.floor(width/2)
  16.     y = math.floor(height/2)
  17.     return x, y
  18. end
  19.  
  20. function draw(color)
  21.     monitor.setBackgroundColor(color)
  22.     monitor.write(' ')
  23.     monitor.setBackgroundColor(colors.black)
  24. end
  25.  
  26. function drawDot(x, y, color)
  27.     monitor.setCursorPos(x, y)
  28.     draw(color)
  29. end
  30.  
  31. function drawLine(x1, y1, x2, y2, color)
  32.     x = x2 - x1
  33.     y = y2 - y1
  34.     if x < 0 then
  35.         xinc = -1
  36.     else
  37.         xinc = 1
  38.     end
  39.     if y < 0 then
  40.         yinc = -1
  41.     else
  42.         yinc = 1
  43.     end -- if x1 > x2,
  44.     if math.abs(y/x)>1 then --if the gradient is more than 1
  45.         for i = y1, y2, yinc do
  46.            drawDot(math.floor((x1 + (x/y)*(i-y1)+0.5)), i, color)
  47.         end
  48.     elseif math.abs(y/x)<1 then --if the gradient is less than 1
  49.         for i = x1, x2, xinc do --go along
  50.             drawDot(i, math.floor((y1+(y/x)*(i-x1))+0.5), color)
  51.         end
  52.     else
  53.         for i = x1, x2, xinc do
  54.             drawDot(i, y1+(i-x1), color)
  55.         end
  56.     end
  57. end
Advertisement
Add Comment
Please, Sign In to add comment