Advertisement
FoxWorn3365

Calculator

Dec 9th, 2021 (edited)
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. term.setCursorPos(1, 1)
  2. term.setBackgroundColor(colors.white)
  3. term.clear()
  4.  
  5. -- Hack OS - v0.19
  6. -- By FoxWorn3365
  7.  
  8.  
  9. -- APPUNTI
  10. -- Configurazioni sistema: .localConf
  11. -- Configurazioni pubbliche: .publicConf
  12. -- Immagini: /Hack/images/
  13. -- APP: /Hack/programmi/
  14. -- App di esempio:
  15. -- Directory: /Hack/programmi/fileManager/
  16. -- Icona: /Hack/programmi/fileManager/app.ico
  17. -- File da eseguire: /Hack/programmi/fileManager/exec.luaDir
  18. -- Configurazioni (facoltativo) (OBBLIGO AUTOGENERAZIONE): /Hack/programmi/fileManager/conf.public
  19. -- Nome dell'APP (massimo 4 caratteri): /Hack/programmi/fileManager/app.name
  20. -- API: https://fcosma.it/hackos/api
  21.  
  22. maxw, maxh = term.getSize()
  23. local function drawPixelInternal(xPos, yPos)
  24. term.setCursorPos(xPos, yPos)
  25. term.write(" ")
  26. end
  27.  
  28. local tColourLookup = {}
  29. for n = 1, 16 do
  30. tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  31. end
  32.  
  33. function drawFilledBox(startX, startY, endX, endY, nColour)
  34. if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
  35. "number" or type(endY) ~= "number" or
  36. (nColour ~= nil and type(nColour) ~= "number") then
  37. error("Expected startX, startY, endX, endY, colour", 2)
  38. end
  39.  
  40. startX = math.floor(startX)
  41. startY = math.floor(startY)
  42. endX = math.floor(endX)
  43. endY = math.floor(endY)
  44.  
  45. if nColour then term.setBackgroundColor(nColour) end
  46. if startX == endX and startY == endY then
  47. drawPixelInternal(startX, startY)
  48. return
  49. end
  50.  
  51. local minX = math.min(startX, endX)
  52. if minX == startX then
  53. minY = startY
  54. maxX = endX
  55. maxY = endY
  56. else
  57. minY = endY
  58. maxX = startX
  59. maxY = startY
  60. end
  61.  
  62. for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
  63. end
  64.  
  65. function giremu(inputstr, sep)
  66. local t={}
  67. for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  68. table.insert(t, str)
  69. end
  70. return t
  71. end
  72.  
  73. function clear()
  74. sfondo(colors.black)
  75. term.clear()
  76. term.setCursorPos(1, 1)
  77. end
  78.  
  79. function clearRed()
  80. sfondo(colors.red)
  81. term.clear()
  82. term.setCursorPos(1, 1)
  83. end
  84.  
  85. function titolo(testo)
  86. drawFilledBox(1, 1, maxw, 1, colors.orange)
  87. term.setCursorPos((maxw - #testo) / 2, 1)
  88. term.setTextColor(colors.white)
  89. term.write(testo)
  90. end
  91.  
  92. function alarm(testo, colore, y)
  93. drawFilledBox(1, y, maxw, y, colors[colore])
  94. term.setCursorPos((maxw - #testo) / 2, y)
  95. term.setTextColor(colors.white)
  96. term.write(testo)
  97. no()
  98. end
  99.  
  100.  
  101. function ico(x, y, color, text)
  102. term.setBackgroundColor(colors[color])
  103. term.setTextColor(colors.white)
  104. term.setCursorPos(x, y)
  105. print(text)
  106. drawA()
  107. end
  108.  
  109. function drawA()
  110. term.setBackgroundColor(colors.white)
  111. term.setTextColor(colors.black)
  112. end
  113.  
  114. function drawMenu()
  115. drawA()
  116. term.clear()
  117. term.setCursorPos(1, 1)
  118. titolo("Hack Calculator")
  119. ico(51, 1, "red", "X")
  120. end
  121. don = 0
  122.  
  123. while true do
  124. if don == 0 then
  125. drawMenu()
  126. print("\n\nAddizione: + | Sottrazione: -\nMoltiplicazione: x | Divisione: /")
  127. print("\n")
  128. num1 = read()
  129. div = read()
  130. num2 = read()
  131. if num1 ~= nil and num1 ~= '' and num2 ~= nil and num2 ~= '' and div ~= nil and div == "+" or div == "-" or div == "x" or div == "/" then
  132. if div == "+" then
  133. ris = tonumber(num1) + tonumber(num2)
  134. elseif div == "-" then
  135. ris = tonumber(num1) - tonumber(num2)
  136. elseif div == "x" then
  137. ris = tonumber(num1) * tonumber(num2)
  138. elseif div == "/" then
  139. ris = tonumber(num1) / tonumber(num2)
  140. else
  141. ris = "Operazione invalida!"
  142. end
  143. else
  144. ris = "Campi invalidi!"
  145. end
  146. term.setCursorPos(15, 9)
  147. print("= "..ris)
  148. ico (15, 16, "green", " ALTRO CALCOLO ")
  149. local event, bt, x, y = os.pullEvent("mouse_click")
  150. if y == 1 and x == 51 then
  151. shell.run("desktop")
  152. elseif y == 16 then
  153. don = 0
  154. end
  155. end
  156. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement