Advertisement
Guest User

s.lua

a guest
Feb 17th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. local file = fs.open("Rules.txt","r")
  2. function round(num, dec)
  3.     if dec == nil then dec = 0 end
  4.     local times = math.pow(10,dec)
  5.     num = math.floor(num*times+0.5)
  6.     return num/times
  7. end
  8. function string:split(sep)
  9.     local sep, fields = sep or ":", {}
  10.     local pattern = string.format("([^%s]+)", sep)
  11.     self:gsub(pattern, function(c) fields[#fields+1] = c end)
  12.     return fields
  13. end
  14. function writeM(mon,txt,x,y,tC,bC)
  15.     if tC == nil then tC = colors.white end
  16.     if bC == nil then bC = colors.black end
  17.     mon.setBackgroundColor(bC)
  18.     mon.setTextColor(tC)
  19.     mon.setCursorPos(x,y)
  20.     mon.write(txt)
  21. end
  22. function clearM(mon, color)
  23.     mon.setBackgroundColor(color)
  24.     mon.clear()
  25. end
  26. function drawLineM(mon, x1, y1, x2, y2, color)
  27.     local dY = y2-y1
  28.     local dX = x2-x1
  29.     local a = dY/dX
  30.     local b = y1-a*x1
  31.    
  32.     local pxl = math.sqrt(dY*dY+dX*dX)
  33.     for i = 1, pxl+1 do
  34.         local x = round(dX/pxl*i)
  35.         local y = round(a*x+b)
  36.         local e = "\t|\t"
  37.         if i%5 == 0 then e = "\n" end
  38.         write(x.."\t"..y..e)
  39.         mon.setCursorPos(x,y)
  40.         mon.setBackgroundColor(color)
  41.         mon.write(" ")
  42.     end
  43. end
  44. local rules = file.readAll():split("\n")
  45.  
  46. file.close()
  47. print(rules)
  48.  
  49. local monitor = peripheral.wrap("top")
  50. local mW,mH = monitor.getSize()
  51. print(monitor, mW, mH)
  52.  
  53. clearM(monitor,colors.red)
  54. drawLineM(monitor,1,1,mW,mH,colors.blue)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement