Advertisement
Guest User

John code test

a guest
Feb 27th, 2020
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.18 KB | None | 0 0
  1. import org.qscript.*; //<>// //<>//
  2. import org.qscript.eventsonfire.*;
  3. import org.qscript.events.*;
  4. import org.qscript.editor.*;
  5. import org.qscript.operator.*;
  6. import org.qscript.errors.*;
  7.  
  8. String input = "";
  9. int main_calc_state = 1;
  10.  
  11. float num1;
  12. float num2;
  13. float temp_num;
  14. float ans;
  15. float trig_ans = 0;
  16. boolean showAns = false;
  17.  
  18. float angle1 = 0;
  19. float angle2 = 0;
  20. String side_a;
  21. String side_b;
  22.  
  23. int calc_state = 0;
  24. int trig_calc_state = 0;
  25. int trig_calc_state_denoter = 0;
  26.  
  27. String trig_ans_error = "Side is less than zero.";
  28.  
  29. boolean flag = false;
  30. boolean calc_flag = false;
  31. boolean adv_trig_calc_flag = false;
  32.  
  33. int x = width/10;
  34. int y = height/10;
  35.  
  36. String a = "";
  37. String b = "";
  38. int c = 0;
  39. String trig_c = "";
  40.  
  41. String[] pres1 = match(input, "\\*");
  42. String[] pres2 = match(input, "/");
  43. String[] pres3 = match(input, "-");
  44. String[] pres4 = match(input, "\\+");
  45. String[] pres5 = match(input, "^");
  46.  
  47. //______________________________________// Above is setup for calculator.
  48. String input1 = "";
  49. boolean check=false;
  50. int deltax=0;
  51. int deltay=0;
  52. int delx=0;
  53. int dely=0;
  54. int inX;
  55. int inY;
  56. int whiteout=0;
  57. boolean check2=true;
  58. float[] x_coord = new float[10000];
  59. float[] y_coord = new float[10000];
  60. float[] tempy = new float[10000];
  61. String LOG;
  62. String COS;
  63. String SIN;
  64. String TAN;
  65. Boolean test = false;
  66.  
  67. void setup() {
  68. size(768, 1024);
  69. background(255);
  70. frameRate(60);
  71. fill(0);
  72. boolean checker=true;
  73. if (checker==true) {
  74. check = true;
  75. checker=false;
  76. }
  77. for (int i=0; i<=2999; i++) {
  78. x_coord[i]=0;
  79. }
  80. for (int i=0; i<=2999; i++) {
  81. y_coord[i]=0;
  82. }
  83. }
  84.  
  85. void draw() {
  86. if (main_calc_state == 1) {
  87. main_operation_draw();
  88. number_draw();
  89. fill(150);
  90. rect(0, 900, 768, 74);
  91. fill(0);
  92. if (showAns) {
  93. text(ans, 50, 945);
  94. } else {
  95. text(input, 300, 945);
  96. text(num1, 50, 945);
  97. }
  98. }
  99. if (main_calc_state == 2) {
  100. println(a, b, trig_c, flag, calc_flag, adv_trig_calc_flag);
  101. }
  102. if (main_calc_state == 3) {
  103. graph_operation_draw();
  104. }
  105. fill(0);
  106. rect(0, 974, 768/4, 50);
  107. rect(192, 974, 768/4, 50);
  108. rect(192*2, 974, 768/4, 50);
  109. rect(192*3, 974, 768/4, 50);
  110. fill(255);
  111. textSize(20);
  112. text("Standard Calculator", 10, 1000);
  113. text("Trig Calculator", 307, 1000);
  114. text("Graphing Calculator", 560, 1000);
  115. if (mouseX >= 0 && mouseX < 270 && mouseY >= 974) {
  116. main_calc_state = 1;
  117. }
  118. if (mouseX >= 270 && mouseX < 520 && mouseY >= 974) {
  119. main_calc_state = 2;
  120. }
  121. if (mouseX >= 520 && mouseX <= 768 && mouseY >= 974) {
  122. main_calc_state = 3;
  123. }
  124. }
  125.  
  126. void mousePressed() {
  127. if (main_calc_state == 1) {
  128. standard_calc_draw();
  129. }
  130. if (main_calc_state == 2) {
  131. trig_operation_draw();
  132. }
  133. }
  134.  
  135. void main_operation_draw() {
  136. int x = width/10;
  137. int y = height/10;
  138. background(255);
  139. fill(0);
  140. textSize(25);
  141. text("n^2", 3*x + 30, y + 40);
  142. text("sqrt", 4*x + 30, y +40);
  143. textSize(40);
  144. text("C", 8*x + 30, y*0 + 40);
  145. text("Ans", 8*x + 30, y*2 + 40);
  146. text("=", 8*x + 30, y*3 + 40);
  147. text("+", 3*x + 30, y*0 + 40);
  148. text("-", 4*x + 30, y*0 + 40);
  149. text("*", 5*x + 30, y*0 + 40);
  150. text("/", 6*x + 30, y*0 + 40);
  151. }
  152.  
  153. void number_draw() {
  154. int x = width/10;
  155. int y = height/10;
  156. text("1", 0*x + 30, y*0 + 40);
  157. text("2", 0*x + 30, y + 40);
  158. text("3", 0*x + 30, y*2 + 40);
  159. text("4", 0*x + 30, y*3 + 40);
  160. text("5", 0*x + 30, y*4 + 40);
  161. text("6", x + 30, y*0 + 40);
  162. text("7", x + 30, y + 40);
  163. text("8", x + 30, y*2 + 40);
  164. text("9", x + 30, y*3 + 40);
  165. text("0", x + 30, y*4 + 40);
  166. }
  167.  
  168. void trig_operation_draw() {
  169. background(255);
  170. textSize(30);
  171. fill(0);
  172. text("What type of trig question do you need help with?", 20, 60);
  173. text("Pythagoras", 30, 200);
  174. text("Sine Rule", 30, 300);
  175. text("Cosine Rule", 30, 400);
  176. if (mouseX > 20 && mouseX <= 280 && mouseY > 850 && mouseY <= 950) {
  177. trig_calc_state = 0;
  178. }
  179. if (trig_calc_state == 0) {
  180. if (mouseX > 20 && mouseX < 220) {
  181. if (mouseY > 150 && mouseY <= 250) {
  182. trig_calc_state = 1;
  183. trig_calc_state_denoter = 0;
  184. }
  185. if (mouseY > 250 && mouseY <= 350) {
  186. trig_calc_state = 2;
  187. trig_calc_state_denoter = 1;
  188. }
  189. if (mouseY > 350 && mouseY <= 450) {
  190. trig_calc_state = 3;
  191. trig_calc_state_denoter = 2;
  192. }
  193. }
  194. a = "";
  195. b = "";
  196. c = 0;
  197. trig_c = "";
  198. flag = false;
  199. calc_flag = false;
  200. }
  201. if (trig_calc_state == 1) {
  202. background(255);
  203. fill(0);
  204. text("Which side are you attempting to find?", 110, 60);
  205. text("Hypotnuse", 170, 200);
  206. text("Shorter Side", 420, 200);
  207. text("BACK TO MENU", 30, 900);
  208. if (mouseY > 150 && mouseY <= 250) {
  209. if (mouseX > 120 && mouseX <= 270) {
  210. trig_calc_state = 4;
  211. }
  212. if (mouseX > 370 && mouseX <= 520) {
  213. trig_calc_state = 5;
  214. }
  215. }
  216. if (mouseX > 10 && mouseX <= 150) {
  217. if (mouseY > 850 && mouseY <= 950) {
  218. trig_calc_state = 0;
  219. }
  220. }
  221. }
  222. if (trig_calc_state == 2 || trig_calc_state == 3) {
  223. background(255);
  224. fill(0);
  225. text("Do you want to solve for a side or angle?", 100, 60);
  226. text("Side", 220, 200);
  227. text("Angle", 450, 200);
  228. text("BACK TO MENU", 30, 900);
  229. if (mouseY > 150 && mouseY <= 250) {
  230. if (mouseX > 150 && mouseX <= 300) {
  231. trig_calc_state = 6;
  232. }
  233. if (mouseX > 400 && mouseX <= 550) {
  234. trig_calc_state = 7;
  235. }
  236. if (mouseX > 10 && mouseX <= 150) {
  237. if (mouseY > 850 && mouseY <= 950) {
  238. trig_calc_state = 0;
  239. }
  240. }
  241. }
  242. }
  243. if (trig_calc_state == 4) {
  244. background(255);
  245. fill(0);
  246. text("Press Enter after you type your number.", 90, 600);
  247. number_draw();
  248. text("Enter your known sides:", 200, 60);
  249. text("Side A:", 200, 150);
  250. text("Side B:", 200, 200);
  251. number_operation();
  252. c = parseInt(a) * parseInt(a) + parseInt(b) * parseInt(b);
  253. trig_ans = sqrt(c);
  254. if (a != "" && b != "") {
  255. text("Missing Side is:", 200, 280);
  256. text(trig_ans, 420, 280);
  257. }
  258. text(a, 350, 150);
  259. text(b, 350, 200);
  260. text("BACK TO MENU", 30, 900);
  261. }
  262. if (trig_calc_state == 5) {
  263. background(255);
  264. fill(0);
  265. text("Press Enter after you type your number.", 90, 600);
  266. number_draw();
  267. text("Enter your known sides:", 200, 60);
  268. text("Hypotnuse:", 200, 150);
  269. text("Side B:", 200, 200);
  270. number_operation();
  271. c = parseInt(a) * parseInt(a) - parseInt(b) * parseInt(b);
  272. trig_ans = sqrt(c);
  273. if (a != "" && b != "") {
  274. text("Missing Side is:", 200, 280);
  275. if (c <= 0) {
  276. text(trig_ans_error, 430, 280);
  277. } else {
  278. text(trig_ans, 430, 280);
  279. }
  280. }
  281. text(a, 400, 150);
  282. text(b, 350, 200);
  283. text("BACK TO MENU", 30, 900);
  284. }
  285. if (trig_calc_state == 6 && trig_calc_state_denoter == 1) {
  286. background(255);
  287. fill(0);
  288. text("Press Enter after you type your number.", 90, 600);
  289. number_draw();
  290. text("Enter your two known angles and side:", 120, 60);
  291. text("Opp. Angle:", 200, 150);
  292. text("Side 2:", 200, 200);
  293. text("Angle 2:", 200, 250);
  294. number_operation();
  295. side_a = Integer.parseInt(a);
  296. trig_ans = parseInt(a) * parseInt(b)/parseInt(trig_c);
  297. text(a, 400, 150);
  298. text(b, 350, 200);
  299. text(trig_c, 350, 250);
  300. text("BACK TO MENU", 30, 900);
  301. }
  302. }
  303.  
  304. void standard_calc_draw() {
  305. String[] pres1 = match(input, "\\*");
  306. String[] pres2 = match(input, "/");
  307. String[] pres3 = match(input, "-");
  308. String[] pres4 = match(input, "\\+");
  309. String[] pres5 = match(input, "^");
  310. if (mouseX >= 0 && mouseX < 78) {
  311. if (mouseY >= 0 && mouseY < 70) {
  312. input = input + 1;
  313. } else if (mouseY >= 70 && mouseY < 102 + 70) {
  314. input = input + 2;
  315. } else if (mouseY >= 70 + 102 && mouseY < 102*2 + 70) {
  316. input = input + 3;
  317. } else if (mouseY >= 70 + 102*2 && mouseY < 102*3 + 70) {
  318. input = input + 4;
  319. } else if (mouseY >= 70 + 102*3 && mouseY < 102*4 + 70) {
  320. input = input + 5;
  321. }
  322. showAns = false;
  323. } else if (mouseX >= 78 && mouseX < 78*2) {
  324. if (mouseY >= 0 && mouseY < 70) {
  325. input = input + 6;
  326. } else if (mouseY >= 70 && mouseY < 102 + 70) {
  327. input = input + 7;
  328. } else if (mouseY >= 70 + 102 && mouseY < 102*2 + 70) {
  329. input = input + 8;
  330. } else if (mouseY >= 70 + 102*2 && mouseY < 102*3 + 70) {
  331. input = input + 9;
  332. } else if (mouseY >= 70 + 102*3 && mouseY < 102*4 + 70) {
  333. input = input + 0;
  334. }
  335. showAns = false;
  336. } else if (mouseX >= 78*3 && mouseX < 78*4) {
  337. if (mouseY >= 0 && mouseY < 70) {
  338. if (num1 == 0) {
  339. num1 = parseInt(input);
  340. } else if (calc_state == 5) {
  341. } else if (input != "") {
  342. temp_num = parseInt(input.substring(1));
  343. } else {
  344.  
  345. if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null) {
  346. num1 = temp_num + num1;
  347. } else {
  348. operation_input_result();
  349. }
  350. }
  351. input = "+";
  352. calc_state = 1;
  353. showAns = false;
  354. } else if (mouseY >= 70 && mouseY < 70 + 102) {
  355. if (num1 == 0) {
  356. if (ans == 0) {
  357. num1 = parseInt(input) * parseInt(input);
  358. } else {
  359. num1 = ans * ans;
  360. }
  361. } else {
  362. if (input != "") {
  363. temp_num = parseInt(input.substring(1));
  364. }
  365. if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null) {
  366. num1 = num1 * num1;
  367. } else {
  368. operation_input_result();
  369. }
  370. }
  371. if (num1 < 0) {
  372. num1 = abs(num1);
  373. }
  374. input = "";
  375. ans = 0;
  376. text(num1, 50, 995);
  377. }
  378. } else if (mouseX >= 78*4 && mouseX < 78*5) {
  379. if (mouseY >= 0 && mouseY < 70) {
  380. if (num1 == 0) {
  381. num1 = parseInt(input);
  382. } else {
  383. temp_num = parseInt(input.substring(1));
  384. if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null) {
  385. num1 = temp_num * num1;
  386. } else if (calc_state == 5) {
  387. } else {
  388. operation_input_result();
  389. }
  390. }
  391. input = "-";
  392. calc_state = 2;
  393. showAns = false;
  394. } else if (mouseY >= 70 && mouseY < 70 + 102) {
  395. if (num1 == 0) {
  396. if (ans == 0) {
  397. num1 = sqrt(parseInt(input));
  398. } else {
  399. num1 = sqrt(ans);
  400. }
  401. } else {
  402. if (input != "") {
  403. temp_num = parseInt(input.substring(1));
  404. }
  405. if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null && num1 >=0) {
  406. num1 = sqrt(num1);
  407. } else {
  408. if (num1 < 0) {
  409. num1 = abs(num1);
  410. num1 = sqrt(num1);
  411. } else {
  412. operation_input_result();
  413. }
  414. }
  415. }
  416.  
  417. input = "";
  418. showAns = false;
  419. ans = 0;
  420. text(num1, 50, 995);
  421. }
  422. } else if (mouseX >= 78*5 && mouseX < 78*6) {
  423. if (mouseY >= 0 && mouseY < 70) {
  424. if (num1 == 0) {
  425. num1 = parseInt(input);
  426. } else {
  427. temp_num = parseInt(input.substring(1));
  428. if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null) {
  429. num1 = temp_num * num1;
  430. } else if (calc_state == 5) {
  431. } else {
  432. operation_input_result();
  433. }
  434. }
  435. input = "*";
  436. calc_state = 3;
  437. showAns = false;
  438. }
  439. } else if (mouseX >= 78*6 && mouseX < 78*7) {
  440. if (mouseY >= 0 && mouseY < 70) {
  441. if (num1 == 0) {
  442. num1 = parseInt(input);
  443. } else {
  444. temp_num = parseInt(input.substring(1));
  445. if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null) {
  446. num1 = num1 / temp_num;
  447. } else if (calc_state == 5) {
  448. } else {
  449. operation_input_result();
  450. }
  451. }
  452. input = "/";
  453. calc_state = 4;
  454. showAns = false;
  455. }
  456. } else if (mouseX >= 77*8 && mouseX < 77*9) {
  457. if (mouseY >= 70 + 102*2 && mouseY < 70 + 102*3) {
  458. if (num1 == 0) {
  459. ans = parseInt(input);
  460. showAns = true;
  461. } else if (input != "") {
  462. num2 = parseInt(input.substring(1));
  463. input = input + "=";
  464. if (calc_state == 1) {
  465. ans = num1 + num2;
  466. }
  467. if (calc_state == 2) {
  468. ans = num1 - num2;
  469. }
  470. if (calc_state == 3) {
  471. ans = num1 * num2;
  472. }
  473. if (calc_state == 4) {
  474. ans = num1 / num2;
  475. }
  476. showAns = true;
  477. input = "";
  478. num1 = 0;
  479. num2 = 0;
  480. calc_state = 0;
  481. } else {
  482. ans = num1;
  483. }
  484. }
  485. if (mouseY >= 0 && mouseY < 70) {
  486. input = "";
  487. num1 = 0;
  488. num2 = 0;
  489. temp_num = 0;
  490. ans = 0;
  491. }
  492. if (mouseY >= 70 + 102 && mouseY < 70 + 102*2) {
  493. num1 = ans;
  494. showAns = false;
  495. ans = 0;
  496. calc_state = 5;
  497. }
  498. }
  499. }
  500.  
  501. void number_operation_adv_trig() {
  502. if (mouseX >= 0 && mouseX < 78) {
  503. if (mouseY >= 0 && mouseY < 70) {
  504. trig_c = trig_c + 1;
  505. } else if (mouseY >= 70 && mouseY < 102 + 70) {
  506. trig_c = trig_c + 2;
  507. } else if (mouseY >= 70 + 102 && mouseY < 102*2 + 70) {
  508. trig_c = trig_c + 3;
  509. } else if (mouseY >= 70 + 102*2 && mouseY < 102*3 + 70) {
  510. trig_c = trig_c + 4;
  511. } else if (mouseY >= 70 + 102*3 && mouseY < 102*4 + 70) {
  512. trig_c = trig_c + 5;
  513. }
  514. } else if (mouseX >= 78 && mouseX < 78*2) {
  515. if (mouseY >= 0 && mouseY < 70) {
  516. trig_c = trig_c + 6;
  517. } else if (mouseY >= 70 && mouseY < 102 + 70) {
  518. trig_c = trig_c + 7;
  519. } else if (mouseY >= 70 + 102 && mouseY < 102*2 + 70) {
  520. trig_c = trig_c + 8;
  521. } else if (mouseY >= 70 + 102*2 && mouseY < 102*3 + 70) {
  522. trig_c = trig_c + 9;
  523. } else if (mouseY >= 70 + 102*3 && mouseY < 102*4 + 70) {
  524. trig_c = trig_c + 0;
  525. }
  526. }
  527. }
  528.  
  529. void number_operation() {
  530. if (calc_state == 6) {
  531. a = side_a;
  532. }
  533. if (flag == false) {
  534. text("Enter numbers:", 470, 150);
  535. if (mouseX >= 0 && mouseX < 78) {
  536. if (mouseY >= 0 && mouseY < 70) {
  537. a = a + 1;
  538. } else if (mouseY >= 70 && mouseY < 102 + 70) {
  539. a = a + 2;
  540. } else if (mouseY >= 70 + 102 && mouseY < 102*2 + 70) {
  541. a = a + 3;
  542. } else if (mouseY >= 70 + 102*2 && mouseY < 102*3 + 70) {
  543. a = a + 4;
  544. } else if (mouseY >= 70 + 102*3 && mouseY < 102*4 + 70) {
  545. a = a + 5;
  546. }
  547. } else if (mouseX >= 78 && mouseX < 78*2) {
  548. if (mouseY >= 0 && mouseY < 70) {
  549. a = a + 6;
  550. } else if (mouseY >= 70 && mouseY < 102 + 70) {
  551. a = a + 7;
  552. } else if (mouseY >= 70 + 102 && mouseY < 102*2 + 70) {
  553. a = a + 8;
  554. } else if (mouseY >= 70 + 102*2 && mouseY < 102*3 + 70) {
  555. a = a + 9;
  556. } else if (mouseY >= 70 + 102*3 && mouseY < 102*4 + 70) {
  557. a = a + 0;
  558. }
  559. }
  560. }
  561. if (flag == true && calc_flag == false) {
  562. if (mouseX >= 0 && mouseX < 78) {
  563. if (mouseY >= 0 && mouseY < 70) {
  564. b = b + 1;
  565. } else if (mouseY >= 70 && mouseY < 102 + 70) {
  566. b = b + 2;
  567. } else if (mouseY >= 70 + 102 && mouseY < 102*2 + 70) {
  568. b = b + 3;
  569. } else if (mouseY >= 70 + 102*2 && mouseY < 102*3 + 70) {
  570. b = b + 4;
  571. } else if (mouseY >= 70 + 102*3 && mouseY < 102*4 + 70) {
  572. b = b + 5;
  573. }
  574. } else if (mouseX >= 78 && mouseX < 78*2) {
  575. if (mouseY >= 0 && mouseY < 70) {
  576. b = b + 6;
  577. } else if (mouseY >= 70 && mouseY < 102 + 70) {
  578. b = b + 7;
  579. } else if (mouseY >= 70 + 102 && mouseY < 102*2 + 70) {
  580. b = b + 8;
  581. } else if (mouseY >= 70 + 102*2 && mouseY < 102*3 + 70) {
  582. b = b + 9;
  583. } else if (mouseY >= 70 + 102*3 && mouseY < 102*4 + 70) {
  584. b = b + 0;
  585. }
  586. }
  587. }
  588. if (calc_flag == true) {
  589. number_operation_adv_trig();
  590. }
  591. keyPressed();
  592. }
  593.  
  594. void keyPressed() {
  595. if (keyCode == ENTER) {
  596. if (b == "") {
  597. flag = true;
  598. }
  599. else if (trig_c == "") {
  600. calc_flag = true;
  601. }
  602. else if (trig_c != "" && b != "") {
  603. adv_trig_calc_flag = true;
  604. }
  605. }
  606. }
  607.  
  608. void operation_input_result() {
  609. String[] pres1 = match(input, "\\*");
  610. String[] pres2 = match(input, "/");
  611. String[] pres3 = match(input, "-");
  612. String[] pres4 = match(input, "\\+");
  613. String[] pres5 = match(input, "^");
  614. if (pres1 != null) {
  615. num1 = temp_num * num1;
  616. } else if (pres2 != null) {
  617. num1 = num1 / temp_num;
  618. } else if (pres3 != null) {
  619. num1 = num1 - temp_num;
  620. } else if (pres4 != null) {
  621. num1 = num1 + temp_num;
  622. } else if (pres5 != null) {
  623. num1 = num1 * num1;
  624. }
  625. }
  626.  
  627. void graph_operation_draw() {
  628. background(255);
  629. float[] xline = new float[9];
  630. float[] yline = new float[9];
  631.  
  632. for (int i=0; i<=8; i++) {
  633. yline[i] = (40-i*10);
  634. fill(0);
  635. textSize(10);
  636. fill(whiteout);
  637. text(yline[i], (width/2 + 20)+delx, 102.4+102.4*i+dely);
  638. }
  639.  
  640. for (int i=0; i<=8; i++) {
  641. xline[i] = ((-20+i*10));
  642. fill(0);
  643. textSize(10);
  644. text(xline[i], 179.2+102.4*i+delx, (height/2)+dely-5);
  645. }
  646. for (int i =0; i<=9; i++) {
  647. if (keyPressed && check2==true) {
  648. if (key == '1' || key == '2' || key == '3' || key == '4' || key == '5' || key == '6' ||
  649. key == '7' || key == '8' || key == '9' || key == '0' || key == '^' || key == 'x' ||
  650. key == '*' || key == '/' || key == '+' || key == '-' || key == '(' || key == ')' || key == '.') {
  651. input1 = input1+key;
  652. check2 = false;
  653. }
  654. if (key == BACKSPACE && check2==true && input1.length()>0) {
  655. input1 = input1.substring(0, input1.length()-1);
  656. check2 = false;
  657. }
  658. }
  659. }
  660. textSize(20);
  661. LOG = "Ln("+input1+")";
  662. COS = "cos("+input1+")";
  663. SIN = "sin("+input1+")";
  664. TAN = "tan("+input1+")";
  665. text(LOG, 50, 100);
  666. text(SIN, 50, 150);
  667. text(COS, 50, 200);
  668. text(TAN, 50, 250);
  669. if (mouseX>10 && mouseX<90 && mouseY>80 && mouseY<=100 && mousePressed==true) {
  670. for (int i=0; i<=9999; i++) {
  671. x_coord[i]=(i-3000)*0.01;
  672. }
  673. for (int i=0; i<=9999; i++) {
  674. tempy[i] = (function(input1, x_coord[i]));
  675. }
  676. for (int i=0; i<=9999; i++) {
  677. y_coord[i] = (logfunction(tempy[i]));
  678. }
  679. for (int i=0; i<=9999; i++) {
  680. Point[] p = new Point[10000];
  681. p[i] = new Point((x_coord[i]/0.1024+384+delx), dely+512-y_coord[i]/0.1024);
  682. p[i].display();
  683. if (mousePressed ==true && mouseX == (x_coord[i]/0.1024+384+delx)) {
  684. p[i].textualise();
  685. }
  686. }
  687. }
  688.  
  689. if (mouseX>10 && mouseX<90 && mouseY>130 && mouseY<=150 && mousePressed==true) {
  690. for (int i=0; i<=9999; i++) {
  691. x_coord[i]=(i-3000)*0.01;
  692. }
  693. for (int i=0; i<=9999; i++) {
  694. tempy[i] = (function(input1, x_coord[i]));
  695. }
  696. for (int i=0; i<=9999; i++) {
  697. y_coord[i] = (sinfunction(tempy[i]));
  698. }
  699. for (int i=0; i<=9999; i++) {
  700. Point[] p = new Point[10000];
  701. p[i] = new Point((x_coord[i]/0.1024+384+delx), dely+512-y_coord[i]/0.1024);
  702. p[i].display();
  703. if (mousePressed ==true && mouseX == (x_coord[i]/0.1024+384+delx)) {
  704. p[i].textualise();
  705. }
  706. }
  707. }
  708. if (mouseX>10 && mouseX<90 && mouseY>180 && mouseY<=200 && mousePressed==true) {
  709. for (int i=0; i<=9999; i++) {
  710. x_coord[i]=(i-3000)*0.01;
  711. }
  712. for (int i=0; i<=9999; i++) {
  713. tempy[i] = (function(input1, x_coord[i]));
  714. }
  715. for (int i=0; i<=9999; i++) {
  716. y_coord[i] = (cosfunction(tempy[i]));
  717. }
  718. for (int i=0; i<=9999; i++) {
  719. Point[] p = new Point[10000];
  720. p[i] = new Point((x_coord[i]/0.1024+384+delx), dely+512-y_coord[i]/0.1024);
  721. p[i].display();
  722. if (mousePressed ==true && mouseX == (x_coord[i]/0.1024+384+delx)) {
  723. p[i].textualise();
  724. }
  725. }
  726. }
  727. text("Reset Graph to Origin", 550, 50);
  728. if (mouseX>520 && mouseX<768 && mouseY>0 && mouseY<=80 && mousePressed==true) {
  729. delx = 0;
  730. dely = 0;
  731. }
  732.  
  733. if (mouseX>10 && mouseX<90 && mouseY>230 && mouseY<=250 && mousePressed==true) {
  734. for (int i=0; i<=9999; i++) {
  735. x_coord[i]=(i-3000)*0.01;
  736. }
  737. for (int i=0; i<=9999; i++) {
  738. tempy[i] = (function(input1, x_coord[i]));
  739. }
  740. for (int i=0; i<=9999; i++) {
  741. y_coord[i] = (tanfunction(tempy[i]));
  742. }
  743. for (int i=0; i<=9999; i++) {
  744. Point[] p = new Point[10000];
  745. p[i] = new Point((x_coord[i]/0.1024+384+delx), dely+512-y_coord[i]/0.1024);
  746. p[i].display();
  747. if (mousePressed ==true && mouseX == (x_coord[i]/0.1024+384+delx)) {
  748. p[i].textualise();
  749. }
  750. }
  751. }
  752. if (key == ENTER && check2==true) {
  753. for (int i=0; i<=9999; i++) {
  754. x_coord[i]=(i-3000)*0.01;
  755. }
  756.  
  757. for (int i=0; i<=9999; i++) {
  758. y_coord[i] = (function(input1, x_coord[i]));
  759. }
  760.  
  761.  
  762. check2=false;
  763. }
  764. for (int i=0; i<=9999; i++) {
  765. Point[] p = new Point[10000];
  766. p[i] = new Point((x_coord[i]/0.1024+384+delx), dely+512-y_coord[i]/0.1024);
  767. p[i].display();
  768. if (mousePressed ==true && mouseX == (x_coord[i]/0.1024+384+delx)) {
  769. p[i].textualise();
  770. }
  771. }
  772. fill(0);
  773. textSize(20);
  774. text(input1, 50, 50);
  775. if (mousePressed && check == true) {
  776. inX = mouseX;
  777. inY = mouseY;
  778. check=false;
  779. }
  780. if (delx<=-234) {
  781. whiteout = 255;
  782. }
  783. if (delx>-234) {
  784. whiteout =0;
  785. }
  786. strokeWeight(5);
  787. stroke(whiteout);
  788. line((width/2)+delx, 0, (width/2)+delx, height);
  789. stroke(0);
  790. line(150, (height/2)+dely, width, (height/2)+dely);
  791. strokeWeight(2);
  792. line(150, 0, 150, height);
  793. }
  794.  
  795. void mouseReleased() {
  796. deltax = mouseXdelta(inX);
  797. deltay = mouseYdelta(inY);
  798. check =true;
  799. delx=delx+deltax;
  800. dely=dely+deltay;
  801. deltax=0;
  802. deltay=0;
  803. }
  804.  
  805. void keyReleased() {
  806. check2=true;
  807. }
  808.  
  809. int mouseXdelta(int x) {
  810. int diff=0;
  811.  
  812. diff = x - mouseX;
  813.  
  814. return diff;
  815. }
  816.  
  817. int mouseYdelta(int y) {
  818. int diff=0;
  819.  
  820. diff = y - mouseY;
  821. return diff;
  822. }
  823.  
  824. float function(String function, float Xcord) {
  825. String func = function;
  826. String func1 = "";
  827. float Fy=0;
  828. if (func == "x" || func == "X") {
  829. func1 = func.replace("x", str(Xcord));
  830. Fy = float(func1);
  831. } else if (func == "" || func == "0" || func == "1" || func == "2" || func == "3" || func == "5" || func == "6"
  832. || func == "7" || func == "8" || func == "9") {
  833. Fy=0;
  834. } else {
  835. func1 = func.replace("x", str(Xcord));
  836. Result func2 = (Solver.evaluate(func1));
  837. Fy = func2.answer.toFloat();
  838. }
  839. return Fy;
  840. }
  841.  
  842. float logfunction(float Ycord) {
  843. float Fy = -1000;
  844. float y = Ycord;
  845. if (y>0) {
  846. Fy = log(y);
  847. }
  848. return Fy;
  849. }
  850.  
  851. float sinfunction(float Ycord) {
  852. float Fy = -1000;
  853. float y = Ycord;
  854. Fy = sin(y);
  855. return Fy;
  856. }
  857.  
  858. float cosfunction(float Ycord) {
  859. float Fy = -1000;
  860. float y = Ycord;
  861. Fy = cos(y);
  862. return Fy;
  863. }
  864.  
  865. float tanfunction(float Ycord) {
  866. float Fy = -1000;
  867. float y = Ycord;
  868. if (Ycord != 3.14/2) {
  869. Fy = tan(y);
  870. }
  871. return Fy;
  872. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement