SuicidalSTDz

EnderCalc v2.0

Feb 12th, 2013
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.35 KB | None | 0 0
  1. function reset()
  2. term.clear()
  3. term.setCursorPos(1,1)
  4. end
  5.  
  6. function frame()
  7. print("+-------------------------------------------------+")
  8. for i = 1,17 do
  9. print("| |")
  10. end
  11. term.write("+-------------------------------------------------+")
  12. end
  13.  
  14. lastAnswer = false --I will be adding this back in later, it got delete when I re-coded everything :)
  15. while true do
  16. reset()
  17. term.setTextColor(colors.purple)
  18. frame()
  19. term.setCursorPos(4,1)
  20. term.setTextColor(colors.orange)
  21. io.write("[Back]")
  22. term.setCursorPos(19,1)
  23. term.setTextColor(colors.lime)
  24. io.write("[EnderCalc]")
  25. term.setCursorPos(3,3)
  26. io.write("{Add} {Subtract} {Multiply} {Divide} {Square}")
  27. term.setCursorPos(3,5)
  28. io.write("{Square Root} {Pythagorean Theorem} {x^y}")
  29. term.setCursorPos(3,7)
  30. io.write("{Generate A Random Number Between Two Numbers}")
  31. local event, button, xPos, yPos = os.pullEvent("mouse_click")
  32. if button == 1 then
  33. if (xPos >=3 and xPos <=7 and yPos ==3) then --ADD
  34. repeat
  35. reset()
  36. term.setTextColor(colors.orange)
  37. print("What is your first number?")
  38. term.setTextColor(colors.white)
  39. firstNum = read()
  40. valid = tonumber(firstNum)
  41. validNum = type(valid)
  42. if validNum ~= "number" then
  43. term.setTextColor(colors.red)
  44. io.write("This is not a number...")
  45. sleep(2.3)
  46. end
  47. until validNum == "number" and #firstNum <= 8
  48. repeat
  49. reset()
  50. term.setTextColor(colors.orange)
  51. print("What is your second number?")
  52. term.setTextColor(colors.white)
  53. secondNum = read()
  54. valid = tonumber(secondNum)
  55. validNum = type(valid)
  56. if validNum ~= "number" then
  57. term.setTextColor(colors.red)
  58. io.write("This is not a number...")
  59. sleep(2.3)
  60. end
  61. until validNum == "number" and #secondNum <= 8
  62. sum = (firstNum+secondNum)
  63. reset()
  64. term.setTextColor(colors.lightBlue)
  65. io.write("The sum of "..firstNum.." and "..secondNum.." is "..sum)
  66. term.setCursorPos(1,19)
  67. term.setTextColor(colors.orange)
  68. io.write("Press any key to continue")
  69. local event = os.pullEvent()
  70. if event == "key" then
  71. reset()
  72. end
  73. elseif (xPos >=9 and xPos <=18 and yPos ==3) then --SUBTRACT
  74. repeat
  75. reset()
  76. term.setTextColor(colors.orange)
  77. print("What is your first number?")
  78. term.setTextColor(colors.white)
  79. firstNum = read()
  80. valid = tonumber(firstNum)
  81. validNum = type(valid)
  82. if validNum ~= "number" then
  83. term.setTextColor(colors.red)
  84. io.write("This is not a number...")
  85. sleep(2.3)
  86. end
  87. until validNum == "number" and #firstNum <= 8
  88. repeat
  89. reset()
  90. term.setTextColor(colors.orange)
  91. print("What is your second number?")
  92. term.setTextColor(colors.white)
  93. secondNum = read()
  94. valid = tonumber(secondNum)
  95. validNum = type(valid)
  96. if validNum ~= "number" then
  97. term.setTextColor(colors.red)
  98. io.write("This is not a number...")
  99. sleep(2.3)
  100. end
  101. until validNum == "number" and #secondNum <= 8
  102. diff = (firstNum-secondNum)
  103. reset()
  104. term.setTextColor(colors.lightBlue)
  105. io.write("The difference between "..firstNum.." and "..secondNum.." is "..diff)
  106. term.setCursorPos(1,19)
  107. term.setTextColor(colors.orange)
  108. io.write("Press any key to continue")
  109. local event = os.pullEvent()
  110. if event == "key" then
  111. reset()
  112. end
  113. elseif (xPos >=20 and xPos <=29 and yPos ==3) then --MULTIPLY
  114. repeat
  115. reset()
  116. term.setTextColor(colors.orange)
  117. print("What is your first number?")
  118. term.setTextColor(colors.white)
  119. firstNum = read()
  120. valid = tonumber(firstNum)
  121. validNum = type(valid)
  122. if validNum ~= "number" then
  123. term.setTextColor(colors.red)
  124. io.write("This is not a number...")
  125. sleep(2.3)
  126. end
  127. until validNum == "number" and #firstNum <= 8
  128. repeat
  129. reset()
  130. term.setTextColor(colors.orange)
  131. print("What is your second number?")
  132. term.setTextColor(colors.white)
  133. secondNum = read()
  134. valid = tonumber(secondNum)
  135. validNum = type(valid)
  136. if validNum ~= "number" then
  137. term.setTextColor(colors.red)
  138. io.write("This is not a number...")
  139. sleep(2.3)
  140. end
  141. until validNum == "number" and #secondNum <= 8
  142. diff = (firstNum*secondNum)
  143. reset()
  144. term.setTextColor(colors.lightBlue)
  145. io.write("The product of "..firstNum.." and "..secondNum.." is "..diff)
  146. term.setCursorPos(1,19)
  147. term.setTextColor(colors.orange)
  148. io.write("Press any key to continue")
  149. local event = os.pullEvent()
  150. if event == "key" then
  151. reset()
  152. end
  153. elseif (xPos >=31 and xPos <=38 and yPos ==3) then --DIVIDE
  154. repeat
  155. reset()
  156. term.setTextColor(colors.orange)
  157. print("What is your first number?")
  158. term.setTextColor(colors.white)
  159. firstNum = read()
  160. valid = tonumber(firstNum)
  161. validNum = type(valid)
  162. if validNum ~= "number" then
  163. term.setTextColor(colors.red)
  164. io.write("This is not a number...")
  165. sleep(2.3)
  166. end
  167. until validNum == "number" and #firstNum <= 8
  168. repeat
  169. reset()
  170. term.setTextColor(colors.orange)
  171. print("What is your second number?")
  172. term.setTextColor(colors.white)
  173. secondNum = read()
  174. valid = tonumber(secondNum)
  175. validNum = type(valid)
  176. if validNum ~= "number" then
  177. term.setTextColor(colors.red)
  178. io.write("This is not a number...")
  179. sleep(2.3)
  180. end
  181. until validNum == "number" and #secondNum <= 8
  182. diff = (firstNum/secondNum)
  183. reset()
  184. term.setTextColor(colors.lightBlue)
  185. io.write("The quotient of "..firstNum.." and "..secondNum.." is "..diff)
  186. term.setCursorPos(1,19)
  187. term.setTextColor(colors.orange)
  188. io.write("Press any key to continue")
  189. local event = os.pullEvent()
  190. if event == "key" then
  191. reset()
  192. end
  193. elseif (xPos >=40 and xPos <=47 and yPos ==3) then --SQUARE
  194. repeat
  195. reset()
  196. term.setTextColor(colors.orange)
  197. print("What number would you like to square?")
  198. term.setTextColor(colors.white)
  199. sq = read()
  200. valid = tonumber(sq)
  201. validNum = type(valid)
  202. if validNum ~= "number" then
  203. term.setTextColor(colors.red)
  204. io.write("This is not a number...")
  205. sleep(2.3)
  206. end
  207. until validNum == "number" and #sq <= 8
  208. square = (sq^2)
  209. reset()
  210. term.setTextColor(colors.lightBlue)
  211. io.write("The square of "..sq.." is "..square)
  212. term.setCursorPos(1,19)
  213. term.setTextColor(colors.orange)
  214. io.write("Press any key to continue")
  215. local event = os.pullEvent()
  216. if event == "key" then
  217. reset()
  218. end
  219. elseif (xPos >=3 and xPos <=15 and yPos ==5) then --SQUARE ROOT
  220. repeat
  221. reset()
  222. term.setTextColor(colors.orange)
  223. print("What number do you need the square root of?")
  224. term.setTextColor(colors.white)
  225. sqRt = read()
  226. valid = tonumber(sqRt)
  227. validNum = type(valid)
  228. if validNum ~= "number" then
  229. term.setTextColor(colors.red)
  230. io.write("This is not a number...")
  231. sleep(2.3)
  232. end
  233. until validNum == "number" and #sqRt <= 8
  234. squareRoot = math.sqrt(sqRt)
  235. reset()
  236. term.setTextColor(colors.lightBlue)
  237. io.write("The square of "..sqRt.." is "..squareRoot)
  238. term.setCursorPos(1,19)
  239. term.setTextColor(colors.orange)
  240. io.write("Press any key to continue")
  241. local event = os.pullEvent()
  242. if event == "key" then
  243. reset()
  244. end
  245. elseif (xPos >=17 and xPos <=37 and yPos ==5) then --PYTHAGOREAN THEOREM
  246. reset()
  247. term.setTextColor(colors.orange)
  248. print("What value are you missing?")
  249. term.setCursorPos(1,3)
  250. term.setTextColor(colors.lime)
  251. io.write("{a} {b} {c}")
  252. event, button, xPos, yPos = os.pullEvent("mouse_click")
  253. if button == 1 then
  254. if (xPos >=1 and xPos <=3 and yPos == 3) then
  255. repeat
  256. reset()
  257. term.setTextColor(colors.orange)
  258. print("What is the value of b?")
  259. term.setTextColor(colors.white)
  260. b = read()
  261. valid = tonumber(b)
  262. validNum = type(valid)
  263. if validNum ~= "number" then
  264. term.setTextColor(colors.red)
  265. io.write("This is not a number...")
  266. sleep(2.3)
  267. end
  268. until validNum == "number" and #b <=8
  269. repeat
  270. reset()
  271. term.setTextColor(colors.orange)
  272. print("What is the value of c?")
  273. term.setTextColor(colors.white)
  274. c = read()
  275. valid = tonumber(valid)
  276. if validNum ~= "number" then
  277. term.setTextColor(colors.red)
  278. io.write("This is not a number...")
  279. sleep(2.3)
  280. end
  281. sleep(0.1)
  282. if b >= c then
  283. term.setTextColor(colors.red)
  284. io.write("The leg(s) of a triangle cannot be greater or equal to the hypotenuse!")
  285. sleep(2.3)
  286. end
  287. until validNum == "number" and #c <=8 and b<c
  288. bSq = (b^2)
  289. cSq = (c^2)
  290. aSq = (cSq-bSq)
  291. a = math.sqrt(aSq)
  292. reset()
  293. term.setTextColor(colors.lightBlue)
  294. io.write("a = "..a.." b = "..b.." c = "..c)
  295. term.setCursorPos(1,19)
  296. term.setTextColor(colors.orange)
  297. io.write("Press any key to continue")
  298. local event = os.pullEvent()
  299. if event == "key" then
  300. reset()
  301. end
  302. elseif (xPos >=5 and xPos <=7 and yPos == 3) then
  303. repeat
  304. reset()
  305. term.setTextColor(colors.orange)
  306. print("What is the value of a?")
  307. term.setTextColor(colors.white)
  308. a = read()
  309. valid = tonumber(a)
  310. validNum = type(valid)
  311. if validNum ~= "number" then
  312. term.setTextColor(colors.red)
  313. io.write("This is not a number...")
  314. sleep(2.3)
  315. end
  316. until validNum == "number" and #a <=8
  317. repeat
  318. reset()
  319. term.setTextColor(colors.orange)
  320. print("What is the value of c?")
  321. term.setTextColor(colors.white)
  322. c = read()
  323. valid = tonumber(valid)
  324. if validNum ~= "number" then
  325. term.setTextColor(colors.red)
  326. io.write("This is not a number...")
  327. sleep(2.3)
  328. end
  329. sleep(0.1)
  330. if a >= c then
  331. term.setTextColor(colors.red)
  332. io.write("The leg(s) of a triangle cannot be greater or equal to the hypotenuse!")
  333. sleep(2.3)
  334. end
  335. until validNum == "number" and #c <=8 and a<c
  336. aSq = (a^2)
  337. cSq = (c^2)
  338. bSq = (cSq-aSq)
  339. b = math.sqrt(bSq)
  340. reset()
  341. term.setTextColor(colors.lightBlue)
  342. io.write("a = "..a.." b = "..b.." c = "..c)
  343. term.setCursorPos(1,19)
  344. term.setTextColor(colors.orange)
  345. io.write("Press any key to continue")
  346. local event = os.pullEvent()
  347. if event == "key" then
  348. reset()
  349. end
  350. elseif (xPos >=9 and xPos <=11 and yPos == 3) then
  351. repeat
  352. reset()
  353. term.setTextColor(colors.orange)
  354. print("What is the value of a?")
  355. term.setTextColor(colors.white)
  356. a = read()
  357. valid = tonumber(a)
  358. validNum = type(valid)
  359. if validNum ~= "number" then
  360. term.setTextColor(colors.red)
  361. io.write("This is not a number...")
  362. sleep(2.3)
  363. end
  364. until validNum == "number" and #a <=8
  365. repeat
  366. reset()
  367. term.setTextColor(colors.orange)
  368. print("What is the value of b?")
  369. term.setTextColor(colors.white)
  370. b = read()
  371. valid = tonumber(valid)
  372. if validNum ~= "number" then
  373. term.setTextColor(colors.red)
  374. io.write("This is not a number...")
  375. sleep(2.3)
  376. end
  377. sleep(0.1)
  378. until validNum == "number" and #b <=8
  379. aSq = (a^2)
  380. bSq = (b^2)
  381. cSq = (aSq+bSq)
  382. c = math.sqrt(cSq)
  383. reset()
  384. term.setTextColor(colors.lightBlue)
  385. io.write("a = "..a.." b = "..b.." c = "..c)
  386. term.setCursorPos(1,19)
  387. term.setTextColor(colors.orange)
  388. io.write("Press any key to continue")
  389. local event = os.pullEvent()
  390. if event == "key" then
  391. reset()
  392. end
  393.  
  394. end
  395. end
  396. elseif (xPos >=39 and xPos <=43 and yPos == 5) then
  397. repeat
  398. reset()
  399. term.setTextColor(colors.orange)
  400. print("What is the value of x?")
  401. term.setTextColor(colors.white)
  402. x = read()
  403. valid = tonumber(x)
  404. validNum = type(valid)
  405. if validNum ~= "number" then
  406. term.setTextColor(colors.red)
  407. io.write("This is not a number...")
  408. sleep(2.3)
  409. end
  410. until validNum == "number" and #x <=8
  411. repeat
  412. reset()
  413. term.setTextColor(colors.orange)
  414. print("What is the value of y?")
  415. term.setTextColor(colors.white)
  416. y = read()
  417. valid = tonumber(y)
  418. validNum = type(valid)
  419. if validNum ~= "number" then
  420. term.setTextColor(colors.red)
  421. io.write("This is not a number...")
  422. sleep(2.3)
  423. end
  424. until validNum == "number" and #y <=8
  425. xy = (x^y)
  426. reset()
  427. term.setTextColor(colors.lightBlue)
  428. io.write(x.."^"..y.." equals "..xy)
  429. term.setCursorPos(1,19)
  430. term.setTextColor(colors.orange)
  431. io.write("Press any key to continue")
  432. local event = os.pullEvent()
  433. if event == "key" then
  434. reset()
  435. end
  436. elseif (xPos >=3 and xPos <=48 and yPos == 7) then
  437. repeat
  438. reset()
  439. term.setTextColor(colors.orange)
  440. print("What is your first param/number?")
  441. term.setTextColor(colors.white)
  442. firstParam = read()
  443. valid = tonumber(firstParam)
  444. validNum = type(valid)
  445. if validNum ~= "number" then
  446. term.setTextColor(colors.red)
  447. io.write("This is not a number...")
  448. sleep(2.3)
  449. end
  450. until validNum == "number" and #firstParam <=8
  451. repeat
  452. reset()
  453. term.setTextColor(colors.orange)
  454. print("What is your second param/number?")
  455. term.setTextColor(colors.white)
  456. secondParam = read()
  457. valid = tonumber(secondParam)
  458. validNum = type(valid)
  459. if validNum ~= "number" then
  460. term.setTextColor(colors.red)
  461. io.write("This is not a number...")
  462. sleep(2.3)
  463. end
  464. sleep(0.1)
  465. if secondParam == firstParam then
  466. term.setTextColor(colors.red)
  467. io.write("The Endermen substitute your answer with a response too harsh to repeat!")
  468. sleep(3.5)
  469. end
  470. until validNum == "number" and #secondParam <=8 and secondParam ~= firstParam
  471. rdm = math.random(firstParam,secondParam)
  472. reset()
  473. term.setTextColor(colors.lightBlue)
  474. io.write("A random number between "..firstParam.." and "..secondParam.." is "..rdm)
  475. term.setCursorPos(1,19)
  476. term.setTextColor(colors.orange)
  477. io.write("Press any key to continue")
  478. local event = os.pullEvent()
  479. if event == "key" then
  480. reset()
  481. end
  482. end
  483. end
  484. end
Advertisement
Add Comment
Please, Sign In to add comment