Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String input = ""; //<>//
- int main_calc_state = 1;
- float num1;
- float num2;
- float temp_num;
- float ans;
- float trig_ans = 0;
- boolean showAns = false;
- int calc_state = 0;
- int trig_calc_state = 0;
- String trig_ans_error = "Side is less than zero.";
- boolean flag = false;
- boolean calc_flag = false;
- int x = width/10;
- int y = height/10;
- int input_a = 0;
- String a = "";
- String b = "";
- int c = 0;
- String[] pres1 = match(input, "\\*");
- String[] pres2 = match(input, "/");
- String[] pres3 = match(input, "-");
- String[] pres4 = match(input, "\\+");
- String[] pres5 = match(input, "^");
- void setup() {
- size(768, 1024);
- background(255);
- frameRate(20);
- fill(0);
- }
- void draw() {
- if (main_calc_state == 1) {
- main_operation_draw();
- number_draw();
- fill(150);
- rect(0, 900, 768, 74);
- fill(0);
- if (showAns) {
- text(ans, 50, 945);
- } else {
- text(input, 300, 945);
- text(num1, 50, 945);
- }
- }
- if (main_calc_state == 2) {
- println(mouseX, mouseY, trig_calc_state, a, b, flag, calc_flag, c);
- }
- if (main_calc_state == 3) {
- }
- fill(0);
- rect(0, 974, 768/4, 50);
- rect(192, 974, 768/4, 50);
- rect(192*2, 974, 768/4, 50);
- rect(192*3, 974, 768/4, 50);
- fill(255);
- textSize(20);
- text("Standard Calculator", 10, 1000);
- text("Trig Calculator", 307, 1000);
- text("Graphing Calculator", 560, 1000);
- if (mouseX >= 0 && mouseX < 270 && mouseY >= 974) {
- main_calc_state = 1;
- }
- if (mouseX >= 270 && mouseX < 520 && mouseY >= 974) {
- main_calc_state = 2;
- }
- if (mouseX >= 520 && mouseX <= 768 && mouseY >= 974) {
- main_calc_state = 3;
- }
- }
- void mousePressed() {
- if (main_calc_state == 1) {
- standard_calc_draw();
- }
- if (main_calc_state == 2) {
- trig_operation_draw();
- }
- if (main_calc_state == 3) {
- graph_operation_draw();
- }
- }
- void main_operation_draw() {
- int x = width/10;
- int y = height/10;
- background(255);
- fill(0);
- textSize(25);
- text("n^2", 3*x + 30, y + 40);
- text("sqrt", 4*x + 30, y +40);
- textSize(40);
- text("C", 8*x + 30, y*0 + 40);
- text("Ans", 8*x + 30, y*2 + 40);
- text("=", 8*x + 30, y*3 + 40);
- text("+", 3*x + 30, y*0 + 40);
- text("-", 4*x + 30, y*0 + 40);
- text("*", 5*x + 30, y*0 + 40);
- text("/", 6*x + 30, y*0 + 40);
- }
- void number_draw() {
- int x = width/10;
- int y = height/10;
- text("1", 0*x + 30, y*0 + 40);
- text("2", 0*x + 30, y + 40);
- text("3", 0*x + 30, y*2 + 40);
- text("4", 0*x + 30, y*3 + 40);
- text("5", 0*x + 30, y*4 + 40);
- text("6", x + 30, y*0 + 40);
- text("7", x + 30, y + 40);
- text("8", x + 30, y*2 + 40);
- text("9", x + 30, y*3 + 40);
- text("0", x + 30, y*4 + 40);
- }
- void trig_operation_draw() {
- background(255);
- textSize(30);
- fill(0);
- text("What type of trig question do you need help with?", 20, 60);
- text("Pythagoras", 30, 200);
- text("Sine Rule", 30, 300);
- text("Cosine Rule", 30, 400);
- if (mouseX > 20 && mouseX <= 280 && mouseY > 850 && mouseY <= 950) {
- trig_calc_state = 0;
- }
- if (trig_calc_state == 0) {
- if (mouseX > 20 && mouseX < 220) {
- if (mouseY > 150 && mouseY <= 250) {
- trig_calc_state = 1;
- }
- if (mouseY > 250 && mouseY <= 350) {
- trig_calc_state = 2;
- }
- if (mouseY > 350 && mouseY <= 450) {
- trig_calc_state = 3;
- }
- }
- a = "";
- b = "";
- c = 0;
- flag = false;
- calc_flag = false;
- }
- if (trig_calc_state == 1) {
- background(255);
- fill(0);
- text("Which side are you attempting to find?", 110, 60);
- text("Hypotnuse", 170, 200);
- text("Shorter Side", 420, 200);
- if (mouseY > 150 && mouseY <= 250) {
- if (mouseX > 120 && mouseX <= 270) {
- trig_calc_state = 4;
- }
- if (mouseX > 370 && mouseX <= 520) {
- trig_calc_state = 5;
- }
- if (mouseY > 850 && mouseY <= 950) {
- trig_calc_state = 0;
- }
- }
- }
- if (trig_calc_state == 4) {
- background(255);
- fill(0);
- text("Press Enter after you type your number.", 90, 600);
- number_draw();
- text("Enter your known sides:", 200, 60);
- text("Side A:", 200, 150);
- text("Side B:", 200, 200);
- number_operation();
- c = parseInt(a) * parseInt(a) + parseInt(b) * parseInt(b);
- trig_ans = sqrt(c);
- if (a != "" && b != "") {
- text("Missing Side is:", 200, 280);
- text(trig_ans, 420, 280);
- }
- text(a, 350, 150);
- text(b, 350, 200);
- text("BACK TO MENU", 30, 900);
- }
- if (trig_calc_state == 5) {
- background(255);
- fill(0);
- text("Press Enter after you type your number.", 90, 600);
- number_draw();
- text("Enter your known sides:", 200, 60);
- text("Hypotnuse:", 200, 150);
- text("Side B:", 200, 200);
- number_operation();
- c = parseInt(a) * parseInt(a) - parseInt(b) * parseInt(b);
- trig_ans = sqrt(c);
- if (a != "" && b != "") {
- text("Missing Side is:", 200, 280);
- if (c <= 0) {
- text(trig_ans_error, 430, 280);
- } else {
- text(trig_ans, 430, 280);
- }
- }
- text(a, 400, 150);
- text(b, 350, 200);
- text("BACK TO MENU", 30, 900);
- }
- }
- void standard_calc_draw() {
- if (mouseX >= 0 && mouseX < 78) {
- if (mouseY >= 0 && mouseY < 70) {
- input = input + 1;
- showAns = false;
- } else if (mouseY >= 70 && mouseY < 102 + 70) {
- input = input + 2;
- showAns = false;
- } else if (mouseY >= 70 + 102 && mouseY < 102*2 + 70) {
- input = input + 3;
- showAns = false;
- } else if (mouseY >= 70 + 102*2 && mouseY < 102*3 + 70) {
- input = input + 4;
- showAns = false;
- } else if (mouseY >= 70 + 102*3 && mouseY < 102*4 + 70) {
- input = input + 5;
- showAns = false;
- }
- } else if (mouseX >= 78 && mouseX < 78*2) {
- if (mouseY >= 0 && mouseY < 70) {
- input = input + 6;
- showAns = false;
- } else if (mouseY >= 70 && mouseY < 102 + 70) {
- input = input + 7;
- showAns = false;
- } else if (mouseY >= 70 + 102 && mouseY < 102*2 + 70) {
- input = input + 8;
- showAns = false;
- } else if (mouseY >= 70 + 102*2 && mouseY < 102*3 + 70) {
- input = input + 9;
- showAns = false;
- } else if (mouseY >= 70 + 102*3 && mouseY < 102*4 + 70) {
- input = input + 0;
- showAns = false;
- }
- } else if (mouseX >= 78*3 && mouseX < 78*4) {
- if (mouseY >= 0 && mouseY < 70) {
- if (num1 == 0) {
- num1 = parseInt(input);
- } else if (calc_state == 5) {
- num1 = num1;
- } else if (input != "") {
- temp_num = parseInt(input.substring(1));
- } else {
- if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null) {
- num1 = temp_num + num1;
- } else {
- operation_input_result();
- }
- }
- input = "+";
- calc_state = 1;
- showAns = false;
- } else if (mouseY >= 70 && mouseY < 70 + 102) {
- if (num1 == 0) {
- if (ans == 0) {
- num1 = parseInt(input) * parseInt(input);
- } else {
- num1 = ans * ans;
- }
- } else {
- if (input != "") {
- temp_num = parseInt(input.substring(1));
- }
- if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null) {
- num1 = num1 * num1;
- } else {
- operation_input_result();
- }
- }
- if (num1 < 0) {
- num1 = abs(num1);
- }
- input = "";
- ans = 0;
- text(num1, 50, 995);
- }
- } else if (mouseX >= 78*4 && mouseX < 78*5) {
- if (mouseY >= 0 && mouseY < 70) {
- if (num1 == 0) {
- num1 = parseInt(input);
- } else {
- temp_num = parseInt(input.substring(1));
- if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null) {
- num1 = temp_num * num1;
- } else if (calc_state == 5) {
- num1 = num1;
- } else {
- operation_input_result();
- }
- }
- input = "-";
- calc_state = 2;
- showAns = false;
- } else if (mouseY >= 70 && mouseY < 70 + 102) {
- if (num1 == 0) {
- if (ans == 0) {
- num1 = sqrt(parseInt(input));
- } else {
- num1 = sqrt(ans);
- }
- } else {
- if (input != "") {
- temp_num = parseInt(input.substring(1));
- }
- if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null && num1 >=0) {
- num1 = sqrt(num1);
- } else {
- if (num1 < 0) {
- num1 = abs(num1);
- num1 = sqrt(num1);
- } else {
- operation_input_result();
- }
- }
- }
- input = "";
- showAns = false;
- ans = 0;
- text(num1, 50, 995);
- }
- } else if (mouseX >= 78*5 && mouseX < 78*6) {
- if (mouseY >= 0 && mouseY < 70) {
- if (num1 == 0) {
- num1 = parseInt(input);
- } else {
- temp_num = parseInt(input.substring(1));
- if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null) {
- num1 = temp_num * num1;
- } else if (calc_state == 5) {
- num1 = num1;
- } else {
- operation_input_result();
- }
- }
- input = "*";
- calc_state = 3;
- showAns = false;
- }
- } else if (mouseX >= 78*6 && mouseX < 78*7) {
- if (mouseY >= 0 && mouseY < 70) {
- if (num1 == 0) {
- num1 = parseInt(input);
- } else {
- temp_num = parseInt(input.substring(1));
- if (pres1 == null && pres2 == null && pres3 == null && pres4 == null && pres5 == null) {
- num1 = num1 / temp_num;
- } else if (calc_state == 5) {
- num1 = num1;
- } else {
- operation_input_result();
- }
- }
- input = "/";
- calc_state = 4;
- showAns = false;
- }
- } else if (mouseX >= 77*8 && mouseX < 77*9) {
- if (mouseY >= 70 + 102*2 && mouseY < 70 + 102*3) {
- if (num1 == 0) {
- ans = parseInt(input);
- showAns = true;
- } else if (input != "") {
- num2 = parseInt(input.substring(1));
- input = input + "=";
- if (calc_state == 1) {
- ans = num1 + num2;
- }
- if (calc_state == 2) {
- ans = num1 - num2;
- }
- if (calc_state == 3) {
- ans = num1 * num2;
- }
- if (calc_state == 4) {
- ans = num1 / num2;
- }
- showAns = true;
- input = "";
- num1 = 0;
- num2 = 0;
- calc_state = 0;
- } else {
- ans = num1;
- }
- }
- if (mouseY >= 0 && mouseY < 70) {
- input = "";
- num1 = 0;
- num2 = 0;
- temp_num = 0;
- ans = 0;
- }
- if (mouseY >= 70 + 102 && mouseY < 70 + 102*2) {
- num1 = ans;
- showAns = false;
- ans = 0;
- calc_state = 5;
- }
- }
- }
- void number_operation() {
- if (flag == false) {
- text("Enter numbers:", 420, 150);
- if (mouseX >= 0 && mouseX < 78) {
- if (mouseY >= 0 && mouseY < 70) {
- a = a + 1;
- } else if (mouseY >= 70 && mouseY < 102 + 70) {
- a = a + 2;
- } else if (mouseY >= 70 + 102 && mouseY < 102*2 + 70) {
- a = a + 3;
- } else if (mouseY >= 70 + 102*2 && mouseY < 102*3 + 70) {
- a = a + 4;
- } else if (mouseY >= 70 + 102*3 && mouseY < 102*4 + 70) {
- a = a + 5;
- }
- } else if (mouseX >= 78 && mouseX < 78*2) {
- if (mouseY >= 0 && mouseY < 70) {
- a = a + 6;
- } else if (mouseY >= 70 && mouseY < 102 + 70) {
- a = a + 7;
- } else if (mouseY >= 70 + 102 && mouseY < 102*2 + 70) {
- a = a + 8;
- } else if (mouseY >= 70 + 102*2 && mouseY < 102*3 + 70) {
- a = a + 9;
- } else if (mouseY >= 70 + 102*3 && mouseY < 102*4 + 70) {
- a = a + 0;
- }
- }
- }
- if (flag == true) {
- if (mouseX >= 0 && mouseX < 78) {
- if (mouseY >= 0 && mouseY < 70) {
- b = b + 1;
- } else if (mouseY >= 70 && mouseY < 102 + 70) {
- b = b + 2;
- } else if (mouseY >= 70 + 102 && mouseY < 102*2 + 70) {
- b = b + 3;
- } else if (mouseY >= 70 + 102*2 && mouseY < 102*3 + 70) {
- b = b + 4;
- } else if (mouseY >= 70 + 102*3 && mouseY < 102*4 + 70) {
- b = b + 5;
- }
- } else if (mouseX >= 78 && mouseX < 78*2) {
- if (mouseY >= 0 && mouseY < 70) {
- b = b + 6;
- } else if (mouseY >= 70 && mouseY < 102 + 70) {
- b = b + 7;
- } else if (mouseY >= 70 + 102 && mouseY < 102*2 + 70) {
- b = b + 8;
- } else if (mouseY >= 70 + 102*2 && mouseY < 102*3 + 70) {
- b = b + 9;
- } else if (mouseY >= 70 + 102*3 && mouseY < 102*4 + 70) {
- b = b + 0;
- }
- }
- keyPressed();
- }
- }
- void keyPressed() {
- if (keyCode == ENTER) {
- if (b == "") {
- flag = true;
- } else {
- calc_flag = true;
- }
- }
- }
- void operation_input_result() {
- if (pres1 != null) {
- num1 = temp_num * num1;
- } else if (pres2 != null) {
- num1 = num1 / temp_num;
- } else if (pres3 != null) {
- num1 = num1 - temp_num;
- } else if (pres4 != null) {
- num1 = num1 + temp_num;
- } else {
- num1 = num1 * num1;
- }
- }
- void graph_operation_draw() {
- background(255);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement