Margresse404

mainFunctionsFile

Jun 16th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. --All functions to be used
  2.  
  3. --Matrix (?)
  4. function matrix(M,N)
  5. local mt
  6. mt = {}
  7. for i=1,M do
  8. mt[i] = {}
  9. for j=1,N do
  10. mt[i][j] = 0
  11. end
  12. end
  13. return mt
  14. end
  15.  
  16.  
  17. function vector(N)
  18. local mt
  19. mt = {}
  20. for i=1,N do
  21. mt[i] = 0
  22. end
  23. return mt
  24. end
  25.  
  26. function vectorMinus(vec1,vec2)
  27. tempVec = vector(#vec1)
  28. for i = 1, #vec1, 1 do
  29. tempVec[i]= vec1[i] - vec2[i]
  30. end
  31. return tempVec
  32. end
  33.  
  34. function resetColors(monitors)
  35. monitors.setTextColor(colors.white)
  36. monitors.setBackgroundColor(colors.black)
  37. end
  38.  
  39. function newLine(monitors)
  40. local x
  41. local y
  42. x, y = monitors.getCursorPos()
  43. y = y + 1
  44. monitors.setCursorPos(1,y)
  45. end
  46.  
  47. function addToList(table, number)
  48. for i = 1, #table - 1, 1 do
  49. j = i + 1
  50. table[i] = table[j]
  51. end
  52. table[#table] = number
  53. return table
  54. end
  55.  
  56.  
  57. --Subdivides regions on the screen
  58. function subDivideRegion(x, y, width, height, parts, divideVertically)
  59.  
  60. local returnTable = {}
  61.  
  62. -- Initialize the return table
  63. for i = 1, parts, 1 do
  64. returnTable[i] = {}
  65. end
  66.  
  67. local sum = 0
  68.  
  69. if divideVertically then -- Make columns
  70. widthSplit = math.floor(width / parts)
  71. for i = 1, parts, 1 do
  72. returnTable[i]["x"] = 1 + widthSplit * (i-1)
  73. returnTable[i]["y"] = y
  74. returnTable[i]["width"] = widthSplit
  75. returnTable[i]["height"] = height
  76. sum = sum + widthSplit
  77. end
  78. returnTable[parts]["width"] = returnTable[parts]["width"] + width - sum
  79. return returnTable
  80. end
  81.  
  82. -- other case, make rows
  83. heightSplit = math.floor(height / parts)
  84. for i = 1, parts, 1 do
  85. returnTable[i]["x"] = x
  86. returnTable[i]["y"] = 1 + heightSplit * (i-1)
  87. returnTable[i]["width"] = width
  88. returnTable[i]["height"] = heightSplit
  89. sum = sum + heightSplit
  90. end
  91.  
  92. returnTable[parts]["height"] = returnTable[parts]["height"] + height - sum
  93. return returnTable
  94. end
  95.  
  96.  
  97. function returnWindows(m, x, y, width, height, parts, divideVertically)
  98.  
  99. local coordinateTable = subDivideRegion(x, y, width, height, parts, divideVertically)
  100. local returnTable = {}
  101.  
  102. for i = 1, parts, 1 do
  103. returnTable[i] = window.create(m, coordinateTable[i]["x"], coordinateTable[i]["y"], coordinateTable[i]["width"], coordinateTable[i]["height"])
  104. end
  105.  
  106. return returnTable
  107. end
  108.  
  109. function checkInRangeWindow(w, xPos, yPos)
  110. local wxPos, wyPos = w.getPosition()
  111. local width, height = w.getSize()
  112. xlimit = wxPos + width
  113. ylimit = wyPos + height
  114.  
  115. if xPos < wxPos then return false end
  116. if yPos < wyPos then return false end
  117. if xPos > xlimit then return false end
  118. if yPos > ylimit then return false end
  119. return true
  120.  
  121. end
Advertisement
Add Comment
Please, Sign In to add comment