SHOW:
|
|
- or go back to the newest paste.
1 | --Coded by SuicidalSTDz | |
2 | --License: | |
3 | - | --The code of "EnderOS" in any form is intellectual |
3 | + | --The code of "EnderCalc" in any form is intellectual |
4 | --property of SuicidalSTDz. You may revise code for | |
5 | --personal use only! Do not distribute! You may use this calculator | |
6 | --in any programs or OS's as long as credit is given the the | |
7 | --original author "SuicidalSTDz" | |
8 | ||
9 | --Enjoy! | |
10 | ||
11 | function calculator() | |
12 | function reset() | |
13 | term.clear() | |
14 | term.setCursorPos(1,1) | |
15 | end | |
16 | reset() | |
17 | term.setTextColor(colors.orange) | |
18 | print("What would you like to do?") | |
19 | term.setCursorPos(1,3) | |
20 | term.setTextColor(colors.lime) | |
21 | print("{Add} {Subtract} {Multiply} {Divide}") | |
22 | term.setCursorPos(1,5) | |
23 | print("{Generate a random number}") | |
24 | local event, button, xPos, yPos = os.pullEvent("mouse_click") | |
25 | if button == 1 then | |
26 | if (xPos >=1 and xPos <=5 and yPos == 3) then | |
27 | reset() | |
28 | term.setTextColor(colors.orange) | |
29 | print("Please enter your first number") | |
30 | term.setTextColor(colors.white) | |
31 | firstNum = read() | |
32 | if #firstNum >6 then | |
33 | reset() | |
34 | term.setTextColor(colors.red) | |
35 | print("I'm sorry, us Endermen cannot calculate that much") | |
36 | sleep(3) | |
37 | calculator() | |
38 | end | |
39 | numOneIsValid = tonumber(firstNum) | |
40 | if type(numOneIsValid) == "number" then | |
41 | term.setTextColor(colors.orange) | |
42 | print("Please type your second number") | |
43 | term.setTextColor(colors.white) | |
44 | secondNum = read() | |
45 | if #secondNum >6 then | |
46 | reset() | |
47 | term.setTextColor(colors.red) | |
48 | print("I'm sorry, us Endermen cannot calculate that much") | |
49 | sleep(3) | |
50 | calculator() | |
51 | end | |
52 | numTwoIsValid = tonumber(secondNum) | |
53 | if type(numTwoIsValid) == "number" then | |
54 | reset() | |
55 | local sum = (firstNum+secondNum) | |
56 | term.setTextColor(colors.lightBlue) | |
57 | print("The sum of your numbers is "..sum) | |
58 | term.setCursorPos(1,3) | |
59 | term.setTextColor(colors.lime) | |
60 | print("{Clear} {Exit}") | |
61 | local event, button, xPos, yPos = os.pullEvent("mouse_click") | |
62 | if button == 1 then | |
63 | if (xPos >=1 and xPos <=7 and yPos == 3) then | |
64 | calculator() | |
65 | elseif (xPos >=9 and xPos <=14 and yPos == 3) then | |
66 | calculator() | |
67 | else | |
68 | calculator() | |
69 | end | |
70 | else | |
71 | calculator() | |
72 | end | |
73 | else | |
74 | reset() | |
75 | term.setTextColor(colors.red) | |
76 | print("The Endermen are not amused!") | |
77 | sleep(3) | |
78 | calculator() | |
79 | end | |
80 | else | |
81 | reset() | |
82 | term.setTextColor(colors.red) | |
83 | print("The Endermen are not amused!") | |
84 | sleep(3) | |
85 | calculator() | |
86 | end | |
87 | elseif (xPos >=7 and xPos <=16 and yPos == 3) then | |
88 | reset() | |
89 | term.setTextColor(colors.orange) | |
90 | print("Please enter your first number") | |
91 | term.setTextColor(colors.white) | |
92 | firstNum = read() | |
93 | if #firstNum >6 then | |
94 | reset() | |
95 | term.setTextColor(colors.red) | |
96 | print("I'm sorry, us Endermen cannot calculate that much") | |
97 | sleep(3) | |
98 | calculator() | |
99 | end | |
100 | numOneIsValid = tonumber(firstNum) | |
101 | if type(numOneIsValid) == "number" then | |
102 | term.setTextColor(colors.orange) | |
103 | print("Please type your second number") | |
104 | term.setTextColor(colors.white) | |
105 | secondNum = read() | |
106 | if #secondNum >6 then | |
107 | reset() | |
108 | term.setTextColor(colors.red) | |
109 | print("I'm sorry, us Endermen cannot calculate that much") | |
110 | sleep(3) | |
111 | calculator() | |
112 | end | |
113 | numTwoIsValid = tonumber(secondNum) | |
114 | if type(numTwoIsValid) == "number" then | |
115 | reset() | |
116 | local diff = (firstNum-secondNum) | |
117 | term.setTextColor(colors.lightBlue) | |
118 | term.write("The difference of your numbers is "..diff) | |
119 | term.setCursorPos(1,3) | |
120 | term.setTextColor(colors.lime) | |
121 | print("{Clear} {Exit}") | |
122 | local event, button, xPos, yPos = os.pullEvent("mouse_click") | |
123 | if button == 1 then | |
124 | if (xPos >=1 and xPos <=7 and yPos == 3) then | |
125 | calculator() | |
126 | elseif (xPos >=9 and xPos <=14 and yPos == 3) then | |
127 | calculator() | |
128 | else | |
129 | calculator() | |
130 | end | |
131 | else | |
132 | calculator() | |
133 | end | |
134 | else | |
135 | reset() | |
136 | term.setTextColor(colors.red) | |
137 | print("The Endermen are not amused!") | |
138 | sleep(3) | |
139 | calculator() | |
140 | end | |
141 | else | |
142 | reset() | |
143 | term.setTextColor(colors.red) | |
144 | print("The Endermen are not amused!") | |
145 | sleep(3) | |
146 | calculator() | |
147 | end | |
148 | elseif (xPos >=18 and xPos <=27 and yPos == 3) then | |
149 | reset() | |
150 | term.setTextColor(colors.orange) | |
151 | print("Please enter your first number") | |
152 | term.setTextColor(colors.white) | |
153 | firstNum = read() | |
154 | if #firstNum >6 then | |
155 | reset() | |
156 | term.setTextColor(colors.red) | |
157 | print("I'm sorry, us Endermen cannot calculate that much") | |
158 | sleep(3) | |
159 | calculator() | |
160 | end | |
161 | numOneIsValid = tonumber(firstNum) | |
162 | if type(numOneIsValid) == "number" then | |
163 | term.setTextColor(colors.orange) | |
164 | print("Please type your second number") | |
165 | term.setTextColor(colors.white) | |
166 | secondNum = read() | |
167 | if #secondNum >6 then | |
168 | reset() | |
169 | term.setTextColor(colors.red) | |
170 | print("I'm sorry, us Endermen cannot calculate that much") | |
171 | sleep(3) | |
172 | calculator() | |
173 | end | |
174 | numTwoIsValid = tonumber(secondNum) | |
175 | if type(numTwoIsValid) == "number" then | |
176 | local product = (firstNum*secondNum) | |
177 | reset() | |
178 | term.setTextColor(colors.lightBlue) | |
179 | term.write("The product of your two numbers is "..product) | |
180 | term.setCursorPos(1,3) | |
181 | term.setTextColor(colors.lime) | |
182 | print("{Clear} {Exit}") | |
183 | local event, button, xPos, yPos = os.pullEvent("mouse_click") | |
184 | if button == 1 then | |
185 | if (xPos >=1 and xPos <=7 and yPos == 3) then | |
186 | calculator() | |
187 | elseif (xPos >=9 and xPos <=14 and yPos == 3) then | |
188 | calculator() | |
189 | else | |
190 | calculator() | |
191 | end | |
192 | else | |
193 | calculator() | |
194 | end | |
195 | else | |
196 | reset() | |
197 | term.setTextColor(colors.red) | |
198 | print("The Endermen are not amused!") | |
199 | sleep(3) | |
200 | calculator() | |
201 | end | |
202 | else | |
203 | reset() | |
204 | term.setTextColor(colors.red) | |
205 | print("The Endermen are not amused!") | |
206 | sleep(3) | |
207 | calculator() | |
208 | end | |
209 | elseif (xPos >=29 and xPos <=36 and yPos == 3) then | |
210 | reset() | |
211 | term.setTextColor(colors.orange) | |
212 | print("Please enter your first number") | |
213 | term.setTextColor(colors.white) | |
214 | firstNum = read() | |
215 | if #firstNum >6 then | |
216 | reset() | |
217 | term.setTextColor(colors.red) | |
218 | print("I'm sorry, us Endermen cannot calculate that much") | |
219 | sleep(3) | |
220 | calculator() | |
221 | end | |
222 | numOneIsValid = tonumber(firstNum) | |
223 | if type(numOneIsValid) == "number" then | |
224 | term.setTextColor(colors.orange) | |
225 | print("Please type your second number") | |
226 | term.setTextColor(colors.white) | |
227 | secondNum = read() | |
228 | if #firstNum >6 then | |
229 | reset() | |
230 | term.setTextColor(colors.red) | |
231 | print("I'm sorry, us Endermen cannot calculate that much") | |
232 | sleep(3) | |
233 | calculator() | |
234 | end | |
235 | numTwoIsValid = tonumber(secondNum) | |
236 | if type(numTwoIsValid) == "number" then | |
237 | reset() | |
238 | local quotient = (firstNum/secondNum) | |
239 | term.setTextColor(colors.lightBlue) | |
240 | term.write("The quotient of your two numbers is "..quotient) | |
241 | term.setCursorPos(1,3) | |
242 | term.setTextColor(colors.lime) | |
243 | print("{Clear} {Exit}") | |
244 | local event, button, xPos, yPos = os.pullEvent("mouse_click") | |
245 | if button == 1 then | |
246 | if (xPos >=1 and xPos <=7 and yPos == 3) then | |
247 | calculator() | |
248 | elseif (xPos >=9 and xPos <=14 and yPos == 3) then | |
249 | calculator() | |
250 | else | |
251 | calculator() | |
252 | end | |
253 | else | |
254 | calculator() | |
255 | end | |
256 | else | |
257 | reset() | |
258 | term.setTextColor(colors.red) | |
259 | print("The Endermen are not amused!") | |
260 | sleep(3) | |
261 | calculator() | |
262 | end | |
263 | else | |
264 | reset() | |
265 | term.setTextColor(colors.red) | |
266 | print("The Endermen are not amused!") | |
267 | sleep(3) | |
268 | calculator() | |
269 | end | |
270 | elseif (xPos >=1 and xPos <=26 and yPos == 5) then | |
271 | reset() | |
272 | term.setTextColor(colors.orange) | |
273 | print("Please enter your first number") | |
274 | term.setTextColor(colors.white) | |
275 | firstNum = read() | |
276 | numOneIsValid = tonumber(firstNum) | |
277 | if type(numOneIsValid) == "number" then | |
278 | term.setTextColor(colors.orange) | |
279 | print("Please type your second number") | |
280 | term.setTextColor(colors.white) | |
281 | secondNum = read() | |
282 | if #secondNum >6 then | |
283 | reset() | |
284 | term.setTextColor(colors.red) | |
285 | print("I'm sorry, us Endermen cannot calculate that much") | |
286 | sleep(3) | |
287 | calculator() | |
288 | end | |
289 | numTwoIsValid = tonumber(secondNum) | |
290 | if type(numTwoIsValid) == "number" then | |
291 | if firstNum > secondNum then | |
292 | term.setTextColor(colors.red) | |
293 | print("Try reversing your numbers, smaller first, larger last") | |
294 | sleep(3) | |
295 | calculator() | |
296 | end | |
297 | reset() | |
298 | local randomNum = math.random(firstNum,secondNum) | |
299 | term.setTextColor(colors.lightBlue) | |
300 | term.write("A random number between "..firstNum.." and "..secondNum.." is "..randomNum) | |
301 | term.setCursorPos(1,3) | |
302 | term.setTextColor(colors.lime) | |
303 | print("{Clear} {Exit}") | |
304 | local event, button, xPos, yPos = os.pullEvent("mouse_click") | |
305 | if button == 1 then | |
306 | if (xPos >=1 and xPos <=7 and yPos == 3) then | |
307 | calculator() | |
308 | elseif (xPos >=9 and xPos <=14 and yPos == 3) then | |
309 | calculator() | |
310 | else | |
311 | calculator() | |
312 | end | |
313 | else | |
314 | calculator() | |
315 | end | |
316 | else | |
317 | reset() | |
318 | term.setTextColor(colors.red) | |
319 | print("The Endermen are not amused!") | |
320 | sleep(3) | |
321 | calculator() | |
322 | end | |
323 | else | |
324 | reset() | |
325 | term.setTextColor(colors.red) | |
326 | print("The Endermen are not amused!") | |
327 | sleep(3) | |
328 | calculator() | |
329 | end | |
330 | else | |
331 | calculator() | |
332 | end | |
333 | else | |
334 | calculator() | |
335 | end | |
336 | end | |
337 | calculator() |