Advertisement
koki2000

Touchscreen calculator

Oct 9th, 2015
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.74 KB | None | 0 0
  1. -- v 1.01
  2.  
  3. -- [bugfixek] --
  4. -- first release: 2015.10.09 --
  5. local ujverzio
  6. local regiverzio
  7. local mouseWidth = 0
  8. local mouseHeight = 0
  9. local t1 = {}
  10. local t2 = {}
  11. local index = 0
  12. local index2 = 0
  13. local szam = 0
  14. local szam2 = 0
  15. local num1 = 0
  16. local num2 = 0
  17. local num3 = 0
  18. local number1 = 0
  19. local number2 = 0
  20. local number3 = 0
  21. local action = ""
  22.  
  23. function clear()
  24. term.clear()
  25. term.setCursorPos(1,1)
  26. end
  27.  
  28. local function updateStartup()
  29. clear()
  30.         shell.run("pastebin","get","DuQCkwAz","update")
  31.  
  32.         local file = fs.open("update", "r")
  33.         lx = file.readLine()
  34.         s1 = lx:find("v")
  35.         ujverzio = tonumber(lx:sub(s1+2))
  36.         file.close()
  37.         clear()
  38.         print("Uj verzio: ", ujverzio)
  39.         sleep(1)
  40.        
  41.         local file = fs.open("startup", "r")
  42.         lx = file.readLine()
  43.         s1 = lx:find("v")
  44.         regiverzio = tonumber(lx:sub(s1+2))
  45.         file.close()
  46.         print("regi verzio: ", regiverzio)
  47.         sleep(1)
  48.        
  49.         if regiverzio < ujverzio or regiverzio > ujverzio then
  50.                 fs.delete("startup")
  51.                 fs.copy("update", "startup")
  52.                 fs.delete("update")
  53.                 shell.run("startup")
  54.         else
  55.                 fs.delete("update")
  56.                 clear()
  57.                 print("nincs elerheto frissites")
  58.                 sleep(1)
  59.                 return false
  60.         end
  61. end
  62.  
  63. updateStartup()
  64.  
  65. m = peripheral.wrap("top")
  66. m2 = peripheral.wrap("right")
  67. m.clear()
  68. m.setCursorPos(1,1)
  69. w,h=m.getSize()
  70.  
  71. print(w)
  72. print(h)
  73.  
  74. function kiir2()
  75. m2.clear()
  76. m2.setCursorPos(3,2)
  77. m2.setTextScale(4)
  78. m2.write(op)
  79. end
  80.  
  81. function kiir()
  82. m.setBackgroundColour((colours.red))
  83. m.setCursorPos(12,4)
  84. m.write("(")
  85. m.setCursorPos(14,4)
  86. m.write(")")
  87. m.setCursorPos(16,4)
  88. m.write("%")
  89. m.setCursorPos(18,4)
  90. m.write("C")
  91. m.setCursorPos(12,6)
  92. m.write("7")
  93. m.setCursorPos(14,6)
  94. m.write("8")
  95. m.setCursorPos(16,6)
  96. m.write("9")
  97. m.setCursorPos(18,6)
  98. m.write("/")
  99. m.setCursorPos(12,8)
  100. m.write("4")
  101. m.setCursorPos(14,8)
  102. m.write("5")
  103. m.setCursorPos(16,8)
  104. m.write("6")
  105. m.setCursorPos(18,8)
  106. m.write("*")
  107. m.setCursorPos(12,10)
  108. m.write("1")
  109. m.setCursorPos(14,10)
  110. m.write("2")
  111. m.setCursorPos(16,10)
  112. m.write("3")
  113. m.setCursorPos(18,10)
  114. m.write("-")
  115. m.setCursorPos(12,12)
  116. m.write("0")
  117. m.setCursorPos(14,12)
  118. m.write(".")
  119. m.setCursorPos(16,12)
  120. m.write("=")
  121. m.setCursorPos(18,12)
  122. m.write("+")
  123. m.setBackgroundColour((colours.black))
  124. end
  125.  
  126. function muvelet()
  127. kiir()
  128. local event, button, X, Y = os.pullEvent("monitor_touch")
  129. XY = X..","..Y
  130. m.setCursorPos(1,12)
  131. m.write(X..","..Y)
  132.  
  133. if index == 0 then
  134. print("indexures")
  135. m.clear()
  136. end
  137.  
  138. if XY == "12,12" then
  139. index = index + 1
  140. table.insert(t1, index, 0)
  141. m.setBackgroundColour((colours.blue))
  142. m.setCursorPos(index,1)
  143. m.write("0")
  144. print(t1[index])
  145.  
  146. elseif XY == "12,10" then
  147. index = index + 1
  148. table.insert(t1, index, 1)
  149. m.setBackgroundColour((colours.blue))
  150. m.setCursorPos(index,1)
  151. m.write("1")
  152. print(t1[index])
  153.  
  154. elseif XY == "14,10" then
  155. index = index + 1
  156. table.insert(t1, index, 2)
  157. m.setBackgroundColour((colours.blue))
  158. m.setCursorPos(index,1)
  159. m.write("2")
  160. print(t1[index])
  161.  
  162. elseif XY == "16,10" then
  163. index = index + 1
  164. table.insert(t1, index, 3)
  165. m.setBackgroundColour((colours.blue))
  166. m.setCursorPos(index,1)
  167. m.write("3")
  168. print(t1[index])
  169.  
  170. elseif XY == "12,8" then
  171. index = index + 1
  172. table.insert(t1, index, 4)
  173. m.setBackgroundColour((colours.blue))
  174. m.setCursorPos(index,1)
  175. m.write("4")
  176. print(t1[index])
  177.  
  178. elseif XY == "14,8" then
  179. index = index + 1
  180. table.insert(t1, index, 5)
  181. m.setBackgroundColour((colours.blue))
  182. m.setCursorPos(index,1)
  183. m.write("5")
  184. print(t1[index])
  185.  
  186. elseif XY == "16,8" then
  187. index = index + 1
  188. table.insert(t1, index, 6)
  189. m.setBackgroundColour((colours.blue))
  190. m.setCursorPos(index,1)
  191. m.write("6")
  192. print(t1[index])
  193.  
  194. elseif XY == "12,6" then
  195. index = index + 1
  196. table.insert(t1, index, 7)
  197. m.setBackgroundColour((colours.blue))
  198. m.setCursorPos(index,1)
  199. m.write("7")
  200. print(t1[index])
  201.  
  202. elseif XY == "14,6" then
  203. index = index + 1
  204. table.insert(t1, index, 8)
  205. m.setBackgroundColour((colours.blue))
  206. m.setCursorPos(index,1)
  207. m.write("8")
  208. print(t1[index])
  209.  
  210. elseif XY == "16,6" then
  211. index = index + 1
  212. table.insert(t1, index, 9)
  213. m.setBackgroundColour((colours.blue))
  214. m.setCursorPos(index,1)
  215. m.write("9")
  216. print(t1[index])
  217.  
  218. elseif XY == "18,12" then
  219. action = "+"
  220. m.setCursorPos(17,1)
  221. m.write(" +")
  222. print(action)
  223. muvelet2()
  224.  
  225. elseif XY == "18,10" then
  226. action = "-"
  227. m.setCursorPos(17,1)
  228. m.write(" -")
  229. print(action)
  230. muvelet2()
  231.  
  232. elseif XY == "18,8" then
  233. m.setCursorPos(17,1)
  234. m.write(" *")
  235. action = "*"
  236. print(action)
  237. muvelet2()
  238.  
  239. elseif XY == "18,6" then
  240. action = "/"
  241. m.setCursorPos(17,1)
  242. m.write(" /")
  243. print(action)
  244. muvelet2()
  245. end
  246. end
  247.  
  248. function muvelet2()
  249. print("muv2")
  250. local event, button, X, Y = os.pullEvent("monitor_touch")
  251. XY = X..","..Y
  252. m.setCursorPos(1,12)
  253. m.write(X..","..Y)
  254.  
  255.  
  256. if XY == "12,12" then
  257. index2 = index2 + 1
  258. table.insert(t2, index2, 0)
  259. m.setBackgroundColour((colours.lightBlue))
  260. m.setCursorPos(index2,2)
  261. m.write("0")
  262. print("muv2", t2[index2])
  263. muvelet2()
  264.  
  265. elseif XY == "12,10" then
  266. index2 = index2 + 1
  267. table.insert(t2, index2, 1)
  268. m.setBackgroundColour((colours.lightBlue))
  269. m.setCursorPos(index2,2)
  270. m.write("1")
  271. print(t2[index2])
  272. muvelet2()
  273.  
  274. elseif XY == "14,10" then
  275. index2 = index2 + 1
  276. table.insert(t2, index2, 2)
  277. m.setBackgroundColour((colours.lightBlue))
  278. m.setCursorPos(index2,2)
  279. m.write("2")
  280. print(t2[index2])
  281. muvelet2()
  282.  
  283. elseif XY == "16,10" then
  284. index2 = index2 + 1
  285. table.insert(t2, index2, 3)
  286. m.setBackgroundColour((colours.lightBlue))
  287. m.setCursorPos(index2,2)
  288. m.write("3")
  289. print(t2[index2])
  290. muvelet2()
  291.  
  292. elseif XY == "12,8" then
  293. index2 = index2 + 1
  294. table.insert(t2, index2, 4)
  295. print(t2[index2])
  296. m.setBackgroundColour((colours.lightBlue))
  297. m.setCursorPos(index2,2)
  298. m.write("4")
  299. muvelet2()
  300.  
  301. elseif XY == "14,8" then
  302. index2 = index2 + 1
  303. table.insert(t2, index2, 5)
  304. m.setBackgroundColour((colours.lightBlue))
  305. m.setCursorPos(index2,2)
  306. m.write("5")
  307. print(t2[index2])
  308. muvelet2()
  309.  
  310. elseif XY == "16,8" then
  311. index2 = index2 + 1
  312. table.insert(t2, index2, 6)
  313. m.setBackgroundColour((colours.lightBlue))
  314. m.setCursorPos(index2,2)
  315. m.write("6")
  316. print(t2[index2])
  317. muvelet2()
  318.  
  319. elseif XY == "12,6" then
  320. index2 = index2 + 1
  321. table.insert(t2, index2, 7)
  322. m.setBackgroundColour((colours.lightBlue))
  323. m.setCursorPos(index2,2)
  324. m.write("7")
  325. print(t2[index2])
  326. muvelet2()
  327.  
  328. elseif XY == "14,6" then
  329. index2 = index2 + 1
  330. table.insert(t2, index2, 8)
  331. m.setBackgroundColour((colours.lightBlue))
  332. m.setCursorPos(index2,2)
  333. m.write("8")
  334. print(t2[index2])
  335. muvelet2()
  336.  
  337. elseif XY == "16,6" then
  338. index2 = index2 + 1
  339. table.insert(t2, index2, 9)
  340. m.setBackgroundColour((colours.lightBlue))
  341. m.setCursorPos(index2,2)
  342. m.write("9")
  343. print(t2[index2])
  344. muvelet2()
  345.  
  346. elseif XY == "16,12" then
  347. print("=")
  348. m.setBackgroundColour((colours.black))
  349. m.setCursorPos(18,2)
  350. m.write("=")
  351. muv1()
  352. muv2()
  353. szamol()
  354. end
  355. end
  356.  
  357. function muv1()
  358. for i = 1, #t1 do
  359. szam = szam + 1
  360. tabla1 = t1[i]
  361. print("tabla1: ", tabla1)
  362. if szam == 1 then num1 = tabla1
  363. out1 = num1
  364. print(out1)
  365. elseif szam == 2 then num2 = tabla1
  366. out1 = num1..num2
  367. print(out1)
  368. elseif szam == 3 then num3 = tabla1
  369. out1 = num1..num2..num3
  370. print(out1)
  371. end
  372. end
  373. end
  374.  
  375. function muv2()
  376. for i = 1, #t2 do
  377. szam2 = szam2 + 1
  378. tabla2 = t2[i]
  379. print("tabla2: ", tabla2)
  380. if szam2 == 1 then number1 = tabla2
  381. out2 = number1
  382. print(out1)
  383. elseif szam2 == 2 then number2 = tabla2
  384. out2 = number1..number2
  385. print(out1)
  386. elseif szam2 == 3 then number3 = tabla2
  387. out2 = number1..number2..number3
  388. print(out1)
  389. end
  390. end
  391. end
  392.  
  393. function tremove()
  394. for i = 1, szam do
  395. szam = szam - 1
  396. print("szamolas", szam)
  397. table.remove(t1)
  398. print(i)
  399. print("szam: ", szam)
  400. end
  401. for j = 1, szam2 do
  402. szam2 = szam2 - 1
  403. table.remove(t2)
  404. print("szam2", szam2)
  405. print(j)
  406.  
  407. end
  408. if szam == 0 and szam2 == 0 then
  409. print("teszt")
  410. index = 0
  411. index2 = 0
  412. szam = 0
  413. szam2 = 0
  414. num1 = 0
  415. num2 = 0
  416. num3 = 0
  417. number1 = 0
  418. number2 = 0
  419. number3 = 0
  420. end
  421. end
  422.  
  423. function szamol()
  424. if action == "+" then
  425. eredmeny = out1 + out2
  426. m.setBackgroundColour((colours.red))
  427. m.setCursorPos(1,3)
  428. m.write(eredmeny)
  429. print("Eredmeny: ", eredmeny)
  430. tremove()
  431. elseif action == "-" then
  432. eredmeny = out1 - out2
  433. m.setBackgroundColour((colours.red))
  434. m.setCursorPos(1,3)
  435. m.write(eredmeny)
  436. print("Eredmeny: ", eredmeny)
  437. tremove()
  438. elseif action == "*" then
  439. eredmeny = out1 * out2
  440. m.setBackgroundColour((colours.red))
  441. m.setCursorPos(1,3)
  442. m.write(eredmeny)
  443. print("Eredmeny: ", eredmeny)
  444. tremove()
  445. elseif action == "/" then
  446. eredmeny = out1 / out2
  447. m.setBackgroundColour((colours.red))
  448. m.setCursorPos(1,3)
  449. m.write(eredmeny)
  450. print("Eredmeny: ", eredmeny)
  451. tremove()
  452. end
  453. end
  454.  
  455. while true do
  456. kiir2()
  457. muvelet()
  458. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement