xxxxxxxxxx
179
var digit = 3, ans = 0;
var input1, input2, sine, cosine, tangent, cosecant, secant, cotangent, arcsin, arccos, arctan, arccsc, arcsec, arccot, equal;
function setup() {
createCanvas(500, 480);
textFont('Georgia');
textStyle(BOLDITALIC);
input1 = createInput(' Type the angle in degrees');
input1.size(250,30);
input1.position(125,145);
input2 = createInput(' Round to how many decimals places');
input2.size(250,30);
input2.position(125,190);
sine = createButton('sin');
sine.size(50,50);
sine.position(100+50, 120+120);
cosine = createButton('cos');
cosine.size(50,50);
cosine.position(100+50, 170+120);
tangent = createButton('tan');
tangent.size(50,50);
tangent.position(100+50, 220+120);
arcsin = createButton('sin' + '-1'.sup());
arcsin.size(50,50);
arcsin.position(150+50, 120+120);
arccos = createButton('cos' + '-1'.sup());
arccos.size(50,50);
arccos.position(150+50, 170+120);
arctan = createButton('tan' + '-1'.sup());
arctan.size(50,50);
arctan.position(150+50, 220+120);
cosecant = createButton('csc');
cosecant.size(50,50);
cosecant.position(200+50, 120+120);
secant = createButton('sec');
secant.size(50,50);
secant.position(200+50, 170+120);
cotangent = createButton('cot');
cotangent.size(50,50);
cotangent.position(200+50, 220+120);
arccsc = createButton('csc' + '-1'.sup());
arccsc.size(50,50);
arccsc.position(250+50, 120+120);
arcsec = createButton('sec' + '-1'.sup());
arcsec.size(50,50);
arcsec.position(250+50, 170+120);
arccot = createButton('cot' + '-1'.sup());
arccot.size(50,50);
arccot.position(250+50, 220+120);
}
function draw() {
background(255, 204, 229);
textSize(40);
text("Trigonometry" + "\n" + " Calculator", 90+20, 30+20);
if(digit >= 3 && digit <= 8){
noStroke();
rectMode(CENTER);
rect(width/2,415,digit*60,50);
textSize(30);
text("Ans: " + ans, width/2 - digit*29,425);
}
if(mouseIsPressed && mouseX > 150 && mouseX < 350 && mouseY > 225 && mouseY < 375){
if(digit < 3 || digit > 8){
alert("Please enter an integer from 3 to 8 in the second input box");
}
}
if(mouseIsPressed && mouseX > 125 && mouseX < 375 && mouseY > 175 && mouseY < 205 && input2.value() === ' Round to how many decimals places'){
input2.value('');
}
if(mouseIsPressed && mouseX > 125 && mouseX < 375 && mouseY > 145 && mouseY < 175 && input1.value() === ' Type the angle in degrees'){
input1.value('');
}
digit = input2.value();
buttons();
if(ans > 10){
ans = "Undefined";
}
}
function buttons(){
sine.mousePressed(SIN);
cosine.mousePressed(COS);
tangent.mousePressed(TAN);
arcsin.mousePressed(ARCSIN);
arccos.mousePressed(ARCCOS);
arctan.mousePressed(ARCTAN);
cosecant.mousePressed(CSC);
secant.mousePressed(SEC);
cotangent.mousePressed(COT);
arccsc.mousePressed(ARCCSC);
arcsec.mousePressed(ARCSEC);
arccot.mousePressed(ARCCOT);
}
function SIN(){
ans = Math.sin(input1.value() * PI/180);
ans = ans.toFixed(digit-1);
}
function COS(){
ans = Math.cos(input1.value() * PI/180);
ans = ans.toFixed(digit-1);
}
function TAN(){
ans = Math.tan(input1.value() * PI/180);
ans = ans.toFixed(digit-1);
}
function ARCSIN(){
ans = Math.asin(input1.value() * PI/180);
ans = ans.toFixed(digit-1);
}
function ARCCOS(){
ans = Math.acos(input1.value() * PI/180);
ans = ans.toFixed(digit-1);
}
function ARCTAN(){
ans = Math.atan(input1.value() * PI/180);
ans = ans.toFixed(digit-1);
}
function CSC(){
ans = 1/Math.sin(input1.value() * PI/180);
ans = ans.toFixed(digit-1);
}
function SEC(){
ans = 1/Math.cos(input1.value() * PI/180);
ans = ans.toFixed(digit-1);
}
function COT(){
ans = 1/Math.tan(input1.value() * PI/180);
ans = ans.toFixed(digit-1);
}
function ARCCSC(){
ans = 1/Math.asin(input1.value() * PI/180);
ans = ans.toFixed(digit-1);
}
function ARCSEC(){
ans = 1/Math.acos(input1.value() * PI/180);
ans = ans.toFixed(digit-1);
}
function ARCCOT(){
ans = 1/Math.atan(input1.value() * PI/180);
ans = ans.toFixed(digit-1);
}