SHARE
TWEET

John code

a guest Feb 26th, 2020 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String input = "";  //<>//
  2. int main_calc_state = 1;
  3. float num1;
  4. float num2;
  5. float temp_num;
  6. float ans;
  7. float trig_ans = 0;
  8. boolean showAns = false;
  9.  
  10. int calc_state = 0;
  11. int trig_calc_state = 0;
  12.  
  13. String trig_ans_error = "Side is less than zero.";
  14.  
  15. boolean flag = false;
  16. boolean calc_flag = false;
  17.  
  18. int x = width/10;
  19. int y = height/10;
  20.  
  21. int input_a = 0;
  22. String a = "";
  23. String b = "";
  24. int c = 0;
  25.  
  26. String[] pres1 = match(input, "\\*");
  27. String[] pres2 = match(input, "/");
  28. String[] pres3 = match(input, "-");
  29. String[] pres4 = match(input, "\\+");
  30. String[] pres5 = match(input, "^");
  31.  
  32. void setup() {
  33.   size(768, 1024);
  34.   background(255);
  35.   frameRate(20);
  36.   fill(0);
  37. }
  38.  
  39. void draw() {
  40.   if (main_calc_state == 1) {
  41.     main_operation_draw();
  42.     number_draw();
  43.     fill(150);
  44.     rect(0, 900, 768, 74);
  45.     fill(0);
  46.     if (showAns) {
  47.       text(ans, 50, 945);
  48.     } else {
  49.       text(input, 300, 945);
  50.       text(num1, 50, 945);
  51.     }
  52.   }
  53.   if (main_calc_state == 2) {
  54.     println(mouseX, mouseY, trig_calc_state, a, b, flag, calc_flag, c);
  55.   }
  56.   if (main_calc_state == 3) {
  57.   }
  58.  
  59.   fill(0);
  60.   rect(0, 974, 768/4, 50);
  61.   rect(192, 974, 768/4, 50);
  62.   rect(192*2, 974, 768/4, 50);
  63.   rect(192*3, 974, 768/4, 50);
  64.   fill(255);
  65.   textSize(20);
  66.   text("Standard Calculator", 10, 1000);
  67.   text("Trig Calculator", 307, 1000);
  68.   text("Graphing Calculator", 560, 1000);
  69.   if (mouseX >= 0 && mouseX < 270 && mouseY >= 974) {
  70.     main_calc_state = 1;
  71.   }
  72.   if (mouseX >= 270 && mouseX < 520 && mouseY >= 974) {
  73.     main_calc_state = 2;
  74.   }
  75.   if (mouseX >= 520 && mouseX <= 768 && mouseY >= 974) {
  76.     main_calc_state = 3;
  77.   }
  78. }
  79.  
  80. void mousePressed() {
  81.   if (main_calc_state == 1) {
  82.     standard_calc_draw();
  83.   }
  84.   if (main_calc_state == 2) {
  85.     trig_operation_draw();
  86.   }
  87.   if (main_calc_state == 3) {
  88.     graph_operation_draw();
  89.   }
  90. }
  91.  
  92. void main_operation_draw() {
  93.   int x = width/10;
  94.   int y = height/10;
  95.   background(255);
  96.   fill(0);
  97.   textSize(25);
  98.   text("n^2", 3*x + 30, y + 40);
  99.   text("sqrt", 4*x + 30, y +40);
  100.   textSize(40);
  101.   text("C", 8*x + 30, y*0 + 40);
  102.   text("Ans", 8*x + 30, y*2 + 40);
  103.   text("=", 8*x + 30, y*3 + 40);
  104.   text("+", 3*x + 30, y*0 + 40);
  105.   text("-", 4*x + 30, y*0 + 40);
  106.   text("*", 5*x + 30, y*0 + 40);
  107.   text("/", 6*x + 30, y*0 + 40);
  108. }
  109.  
  110. void number_draw() {
  111.   int x = width/10;
  112.   int y = height/10;
  113.   text("1", 0*x + 30, y*0 + 40);
  114.   text("2", 0*x + 30, y + 40);
  115.   text("3", 0*x + 30, y*2 + 40);
  116.   text("4", 0*x + 30, y*3 + 40);
  117.   text("5", 0*x + 30, y*4 + 40);
  118.   text("6", x + 30, y*0 + 40);
  119.   text("7", x + 30, y + 40);
  120.   text("8", x + 30, y*2 + 40);
  121.   text("9", x + 30, y*3 + 40);
  122.   text("0", x + 30, y*4 + 40);
  123. }
  124.  
  125. void trig_operation_draw() {
  126.   background(255);
  127.   textSize(30);
  128.   fill(0);
  129.   text("What type of trig question do you need help with?", 20, 60);
  130.   text("Pythagoras", 30, 200);
  131.   text("Sine Rule", 30, 300);
  132.   text("Cosine Rule", 30, 400);
  133.   if (mouseX > 20 && mouseX <= 280 && mouseY > 850 && mouseY <= 950) {
  134.     trig_calc_state = 0;
  135.   }
  136.   if (trig_calc_state == 0) {
  137.     if (mouseX > 20 && mouseX < 220) {
  138.       if (mouseY > 150 && mouseY <= 250) {
  139.         trig_calc_state = 1;
  140.       }
  141.       if (mouseY > 250 && mouseY <= 350) {
  142.         trig_calc_state = 2;
  143.       }
  144.       if (mouseY > 350 && mouseY <= 450) {
  145.         trig_calc_state = 3;
  146.       }
  147.     }
  148.     a = "";
  149.     b = "";
  150.     c = 0;
  151.     flag = false;
  152.     calc_flag = false;
  153.   }
  154.   if (trig_calc_state == 1) {
  155.     background(255);
  156.     fill(0);
  157.     text("Which side are you attempting to find?", 110, 60);
  158.     text("Hypotnuse", 170, 200);
  159.     text("Shorter Side", 420, 200);
  160.     if (mouseY > 150 && mouseY <= 250) {
  161.       if (mouseX > 120 && mouseX <= 270) {
  162.         trig_calc_state = 4;
  163.       }
  164.       if (mouseX > 370 && mouseX <= 520) {
  165.         trig_calc_state = 5;
  166.       }
  167.       if (mouseY > 850 && mouseY <= 950) {
  168.         trig_calc_state = 0;
  169.       }
  170.     }
  171.   }
  172.   if (trig_calc_state == 4) {
  173.     background(255);
  174.     fill(0);
  175.     text("Press Enter after you type your number.", 90, 600);
  176.     number_draw();
  177.     text("Enter your known sides:", 200, 60);
  178.     text("Side A:", 200, 150);
  179.     text("Side B:", 200, 200);
  180.     number_operation();
  181.     c = parseInt(a) * parseInt(a) + parseInt(b) * parseInt(b);
  182.     trig_ans = sqrt(c);
  183.     if (a != "" && b != "") {
  184.       text("Missing Side is:", 200, 280);
  185.       text(trig_ans, 420, 280);
  186.     }
  187.     text(a, 350, 150);
  188.     text(b, 350, 200);
  189.     text("BACK TO MENU", 30, 900);
  190.   }
  191.   if (trig_calc_state == 5) {
  192.     background(255);
  193.     fill(0);
  194.     text("Press Enter after you type your number.", 90, 600);
  195.     number_draw();
  196.     text("Enter your known sides:", 200, 60);
  197.     text("Hypotnuse:", 200, 150);
  198.     text("Side B:", 200, 200);
  199.     number_operation();
  200.     c = parseInt(a) * parseInt(a) - parseInt(b) * parseInt(b);
  201.     trig_ans = sqrt(c);
  202.     if (a != "" && b != "") {
  203.       text("Missing Side is:", 200, 280);
  204.       if (c <= 0) {  
  205.         text(trig_ans_error, 430, 280);
  206.       } else {
  207.         text(trig_ans, 430, 280);
  208.       }
  209.     }
  210.     text(a, 400, 150);
  211.     text(b, 350, 200);
  212.     text("BACK TO MENU", 30, 900);
  213.   }
  214. }
  215.  
  216. void standard_calc_draw() {
  217.   if (mouseX >= 0 && mouseX < 78) {
  218.     if (mouseY >= 0 && mouseY <  70) {
  219.       input = input + 1;
  220.       showAns = false;
  221.     } else if (mouseY >=  70 && mouseY < 102 + 70) {
  222.       input = input + 2;
  223.       showAns = false;
  224.     } else if (mouseY >=  70 + 102 && mouseY < 102*2 + 70) {
  225.       input = input + 3;
  226.       showAns = false;
  227.     } else if (mouseY >=  70 + 102*2 && mouseY < 102*3 + 70) {
  228.       input = input + 4;
  229.       showAns = false;
  230.     } else if (mouseY >=  70 + 102*3 && mouseY < 102*4 + 70) {
  231.       input = input + 5;
  232.       showAns = false;
  233.     }
  234.   } else if (mouseX >= 78 && mouseX < 78*2) {
  235.     if (mouseY >= 0 && mouseY <  70) {
  236.       input = input + 6;
  237.       showAns = false;
  238.     } else if (mouseY >=  70 && mouseY < 102 + 70) {
  239.       input = input + 7;
  240.       showAns = false;
  241.     } else if (mouseY >=  70 + 102 && mouseY < 102*2 + 70) {
  242.       input = input + 8;
  243.       showAns = false;
  244.     } else if (mouseY >=  70 + 102*2 && mouseY < 102*3 + 70) {
  245.       input = input + 9;
  246.       showAns = false;
  247.     } else if (mouseY >=  70 + 102*3 && mouseY < 102*4 + 70) {
  248.       input = input + 0;
  249.       showAns = false;
  250.     }
  251.   } else if (mouseX >= 78*3 && mouseX < 78*4) {
  252.     if (mouseY >= 0 && mouseY < 70) {
  253.       if (num1 == 0) {
  254.         num1 = parseInt(input);
  255.       } else if (calc_state == 5) {
  256.         num1 = num1;
  257.       } else if (input != "") {
  258.         temp_num = parseInt(input.substring(1));
  259.       } else {
  260.  
  261.         if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null) {
  262.           num1 = temp_num + num1;
  263.         } else {
  264.           operation_input_result();
  265.         }
  266.       }
  267.       input = "+";
  268.       calc_state = 1;
  269.       showAns = false;
  270.     } else if (mouseY >= 70 && mouseY < 70 + 102) {
  271.       if (num1 == 0) {
  272.         if (ans == 0) {
  273.           num1 = parseInt(input) * parseInt(input);
  274.         } else {
  275.           num1 = ans * ans;
  276.         }
  277.       } else {
  278.         if (input != "") {
  279.           temp_num = parseInt(input.substring(1));
  280.         }
  281.         if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null) {
  282.           num1 = num1 * num1;
  283.         } else {
  284.           operation_input_result();
  285.         }
  286.       }
  287.       if (num1 < 0) {
  288.         num1 = abs(num1);
  289.       }
  290.       input = "";
  291.       ans = 0;
  292.       text(num1, 50, 995);
  293.     }
  294.   } else if (mouseX >= 78*4 && mouseX < 78*5) {
  295.     if (mouseY >= 0 && mouseY < 70) {
  296.       if (num1 == 0) {
  297.         num1 = parseInt(input);
  298.       } else {
  299.         temp_num = parseInt(input.substring(1));
  300.         if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null) {
  301.           num1 = temp_num * num1;
  302.         } else if (calc_state == 5) {
  303.           num1 = num1;
  304.         } else {
  305.           operation_input_result();
  306.         }
  307.       }
  308.       input = "-";
  309.       calc_state = 2;
  310.       showAns = false;
  311.     } else if (mouseY >= 70 && mouseY < 70 + 102) {
  312.       if (num1 == 0) {
  313.         if (ans == 0) {
  314.           num1 = sqrt(parseInt(input));
  315.         } else {
  316.           num1 = sqrt(ans);
  317.         }
  318.       } else {
  319.         if (input != "") {
  320.           temp_num = parseInt(input.substring(1));
  321.         }
  322.         if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null && num1 >=0) {
  323.           num1 = sqrt(num1);
  324.         } else {
  325.           if (num1 < 0) {
  326.             num1 = abs(num1);
  327.             num1 = sqrt(num1);
  328.           } else {
  329.             operation_input_result();
  330.           }
  331.         }
  332.       }
  333.  
  334.       input = "";
  335.       showAns = false;
  336.       ans = 0;
  337.       text(num1, 50, 995);
  338.     }
  339.   } else if (mouseX >= 78*5 && mouseX < 78*6) {
  340.     if (mouseY >= 0 && mouseY < 70) {
  341.       if (num1 == 0) {
  342.         num1 = parseInt(input);
  343.       } else {
  344.         temp_num = parseInt(input.substring(1));  
  345.         if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null) {
  346.           num1 = temp_num * num1;
  347.         } else if (calc_state == 5) {
  348.           num1 = num1;
  349.         } else {
  350.           operation_input_result();
  351.         }
  352.       }
  353.       input = "*";
  354.       calc_state = 3;
  355.       showAns = false;
  356.     }
  357.   } else if (mouseX >= 78*6 && mouseX < 78*7) {
  358.     if (mouseY >= 0 && mouseY < 70) {
  359.       if (num1 == 0) {
  360.         num1 = parseInt(input);
  361.       } else {
  362.         temp_num = parseInt(input.substring(1));
  363.         if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null) {
  364.           num1 = num1 / temp_num;
  365.         } else if (calc_state == 5) {
  366.           num1 = num1;
  367.         } else {
  368.           operation_input_result();
  369.         }
  370.       }
  371.       input = "/";
  372.       calc_state = 4;
  373.       showAns = false;
  374.     }
  375.   } else if (mouseX >= 77*8 && mouseX < 77*9) {
  376.     if (mouseY >= 70 + 102*2 && mouseY < 70 + 102*3) {
  377.       if (num1 == 0) {
  378.         ans = parseInt(input);
  379.         showAns = true;
  380.       } else if (input != "") {
  381.         num2 = parseInt(input.substring(1));
  382.         input = input + "=";
  383.         if (calc_state == 1) {
  384.           ans = num1 + num2;
  385.         }
  386.         if (calc_state == 2) {
  387.           ans = num1 - num2;
  388.         }
  389.         if (calc_state == 3) {
  390.           ans = num1 * num2;
  391.         }
  392.         if (calc_state == 4) {
  393.           ans = num1 / num2;
  394.         }
  395.         showAns = true;
  396.         input = "";
  397.         num1 = 0;
  398.         num2 = 0;
  399.         calc_state = 0;
  400.       } else {
  401.         ans = num1;
  402.       }
  403.     }
  404.     if (mouseY >= 0 && mouseY < 70) {
  405.       input = "";
  406.       num1 = 0;
  407.       num2 = 0;
  408.       temp_num = 0;
  409.       ans = 0;
  410.     }
  411.     if (mouseY >= 70 + 102 && mouseY < 70 + 102*2) {
  412.       num1 = ans;
  413.       showAns = false;
  414.       ans = 0;
  415.       calc_state = 5;
  416.     }
  417.   }
  418. }
  419.  
  420. void number_operation() {
  421.   if (flag == false) {
  422.     text("Enter numbers:", 420, 150);
  423.     if (mouseX >= 0 && mouseX < 78) {
  424.       if (mouseY >= 0 && mouseY <  70) {
  425.         a = a + 1;
  426.       } else if (mouseY >=  70 && mouseY < 102 + 70) {
  427.         a = a + 2;
  428.       } else if (mouseY >=  70 + 102 && mouseY < 102*2 + 70) {
  429.         a = a + 3;
  430.       } else if (mouseY >=  70 + 102*2 && mouseY < 102*3 + 70) {
  431.         a = a + 4;
  432.       } else if (mouseY >=  70 + 102*3 && mouseY < 102*4 + 70) {
  433.         a = a + 5;
  434.       }
  435.     } else if (mouseX >= 78 && mouseX < 78*2) {
  436.       if (mouseY >= 0 && mouseY <  70) {
  437.         a = a + 6;
  438.       } else if (mouseY >=  70 && mouseY < 102 + 70) {
  439.         a = a + 7;
  440.       } else if (mouseY >=  70 + 102 && mouseY < 102*2 + 70) {
  441.         a = a + 8;
  442.       } else if (mouseY >=  70 + 102*2 && mouseY < 102*3 + 70) {
  443.         a = a + 9;
  444.       } else if (mouseY >=  70 + 102*3 && mouseY < 102*4 + 70) {
  445.         a = a + 0;
  446.       }
  447.     }
  448.   }
  449.   if (flag == true) {
  450.     if (mouseX >= 0 && mouseX < 78) {
  451.       if (mouseY >= 0 && mouseY <  70) {
  452.         b = b + 1;
  453.       } else if (mouseY >=  70 && mouseY < 102 + 70) {
  454.         b = b + 2;
  455.       } else if (mouseY >=  70 + 102 && mouseY < 102*2 + 70) {
  456.         b = b + 3;
  457.       } else if (mouseY >=  70 + 102*2 && mouseY < 102*3 + 70) {
  458.         b = b + 4;
  459.       } else if (mouseY >=  70 + 102*3 && mouseY < 102*4 + 70) {
  460.         b = b + 5;
  461.       }
  462.     } else if (mouseX >= 78 && mouseX < 78*2) {
  463.       if (mouseY >= 0 && mouseY <  70) {
  464.         b = b + 6;
  465.       } else if (mouseY >=  70 && mouseY < 102 + 70) {
  466.         b = b + 7;
  467.       } else if (mouseY >=  70 + 102 && mouseY < 102*2 + 70) {
  468.         b = b + 8;
  469.       } else if (mouseY >=  70 + 102*2 && mouseY < 102*3 + 70) {
  470.         b = b + 9;
  471.       } else if (mouseY >=  70 + 102*3 && mouseY < 102*4 + 70) {
  472.         b = b + 0;
  473.       }
  474.     }
  475.     keyPressed();
  476.   }
  477. }
  478.  
  479. void keyPressed() {
  480.   if (keyCode == ENTER) {
  481.     if (b == "") {
  482.       flag = true;
  483.     } else {
  484.       calc_flag = true;
  485.     }
  486.   }
  487. }
  488.  
  489. void operation_input_result() {
  490.   if (pres1 != null) {
  491.     num1 = temp_num * num1;
  492.   } else if (pres2 != null) {
  493.     num1 = num1 / temp_num;
  494.   } else if (pres3 != null) {
  495.     num1 = num1 - temp_num;
  496.   } else if (pres4 != null) {
  497.     num1 = num1 + temp_num;
  498.   } else {
  499.     num1 = num1 * num1;
  500.   }
  501. }
  502.  
  503. void graph_operation_draw() {
  504.   background(255);
  505. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top