xxxxxxxxxx
75
var MOP = 1;
var CAD = MOPtoCAD(MOP);
var CAD2 = 1;
var MOP2 = CAD2toMOP2(CAD2);
function setup() {
createCanvas(400, 400);
convertToCAD();
convertToMOP();
}
function draw() {
background(23, 83, 156);
//MOP to CAD title
fill(240, 242, 80);
textSize(50);
textFont('Impact');
text('MOP to CAD', 35, 90);
//CAD to MOP title
fill(240, 242, 80);
textSize(50);
textFont('Impact');
text('CAD to MOP', 130, 270);
}
function convertToCAD() {
//insert MOP value (replace 1 with the value you want to convert to CAD)
// display MOP
inputMOP = createInput(MOP + ' MOP');
inputMOP.position(35, 110);
//inputMOP.input(updateCAD);
//display CAD
inputCAD = createInput(CAD + ' CAD');
inputCAD.position(35, 150);
inputCAD.input(updateCAD);
}
function updateCAD() {
console.log(inputMOP.value);
MOP = parseInt(inputMOP.value, 10);
console.log(MOP);
inputCAD.value = MOPtoCAD(MOP);
}
function convertToMOP() {
//insert CAD value (replace 1 with the value you want to convert to MOP)
//display CAD
inputCAD2 = createInput(CAD2 + ' CAD');
inputCAD2.position(225, 290);
//display MOP
inputMOP2 = createInput(MOP2 + ' MOP');
inputMOP2.position(225, 330);
}
function MOPtoCAD(MOP) {
// multiply MOP value with conversion rate for CAD value
return MOP * 0.17;
}
function CAD2toMOP2(CAD2) {
// multiply CAD value with conversion rate for MOP value
var MOP2 = CAD2 * 5.67;
return MOP2;
}