copied master branch

This commit is contained in:
cuqmbr 2021-12-07 17:41:06 +02:00
parent 65401fb0a2
commit 00c8014aeb
19 changed files with 1445 additions and 586 deletions

BIN
Boolean-Algebra/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 613 B

View File

@ -5,8 +5,8 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Boolean Algebra</title>
<link rel="icon" type="image/x-icon" href="favicon.png">
<title>Boolean Algebra Calculator</title>
<link rel="stylesheet" href="../style.css">
@ -18,9 +18,9 @@
<header>
<div class="content">
<h3><a href="">CDM</a></h3>
<h3><a href="..">CDM</a></h3>
<div class="theme">
<h3><a href="../Lab-1/index.html">Set Algebra</a></h3>
<h3><a href="../Set-Algebra">Set Algebra</a></h3>
<h3><a href="">Boolean Algebra</a></h3>
</div>
</div>
@ -34,11 +34,11 @@
<div id="values">
<div class="input-wrap">
<h1 class="text">Value A = </h1>
<div class="input"><input type="value" id="value0" placeholder="e.g. 0 or 1" /></div>
<div class="input"><input type="value" id="value0" onkeydown="return checkInputValue(event.key, this.value)" placeholder="e.g. 0 or 1" /></div>
</div>
<div class="input-wrap">
<h1 class="text">Value B = </h1>
<div class="input"><input type="value" id="value1" placeholder="e.g. 0 or 1" /></div>
<div class="input"><input type="value" id="value1" onkeydown="return checkInputValue(event.key, this.value)" placeholder="e.g. 0 or 1" /></div>
</div>
</div>
<input class="addValue" type="button" value="Add Value" onclick="AddValue()" />
@ -46,11 +46,18 @@
<div class="wrap-side">
<h1>Formulua</h1>
<h2><input type="problem" id="formula" placeholder="e.g. !A*(B+C)" /></h2>
<h2><input type="problem" id="formula" onkeydown="return checkInputProblem(event.key)" placeholder="e.g. !A*(B+C)" /></h2>
<div class="buttons">
<input class="button" type="button" id="calculate" value="Evaluate" onclick="Evaluate()" />
<input class="button" type="button" id="calculate" value="Step by step" onclick="StepByStep()" />
</div>
<div class="buttons">
<input class="button" type="button" id="calculate" value="Build a Truth Table" onclick="BuildTruthTable()" />
</div>
<div class="buttons">
<input class="button" type="button" id="calculate" value="Make PDNF" onclick="BuildPDNF()" />
<input class="button" type="button" id="calculate" value="Make PCNF" onclick="BuildPCNF()" />
</div>
<div class="wrap-result">
<div class="input-wrap">
<h1 class="text">Result </h1>
@ -92,6 +99,33 @@
</div>
</div>
</div>
<div class="wrapper hide" id="truthTableNode">
<div class="step-by-step" id="truthTableWrapper">
<h1>Truth Table</h1>
<div class="input-wrap" id="input-wrap">
<div class="input"><input type="result" readonly/></div>
</div>
</div>
</div>
<div class="wrapper hide" id="pdnfNode">
<div class="step-by-step" id="pdnfWrapper">
<h1>Perfect Disjunctive Normal Form</h1>
<div class="input-wrap" id="input-wrap">
<div class="input"><input type="result" id="step1" readonly/></div>
</div>
</div>
</div>
<div class="wrapper hide" id="pcnfNode">
<div class="step-by-step" id="pcnfWrapper">
<h1>Perfect Conjunctive Normal Form</h1>
<div class="input-wrap" id="input-wrap">
<div class="input"><input type="result" id="step1" readonly/></div>
</div>
</div>
</div>
</div>
<!-- -----------------------------------JS---------------------------- -->

809
Boolean-Algebra/script.js Normal file
View File

@ -0,0 +1,809 @@
//#region Basic Functionallity
let maxNumOfValues = 26;
let currNumOfValues = 2;
function AddValue() {
if (currNumOfValues < 26) {
let charNum = 65 + currNumOfValues;
currNumOfValues++;
let delBtn = document.querySelectorAll('#delBtn');
if (delBtn[delBtn.length - 1]) {
delBtn[delBtn.length - 1].style="display: none;";
}
node = document.getElementById('values');
node.insertAdjacentHTML('beforeend', ` <div class="input-wrap">
<h1 class="text">Value &#${charNum} = </h1>
<div class="input"><input type="value" onkeydown="return checkInputValue(event.key, this.value)" id="value${currNumOfValues - 1}" placeholder="e.g. 0 or 1"/></div>
</div>`);
} else {
alert('You have reached a limint of available values');
}
}
let VALUES = new Set();
let userValues = new Array();
function FetchValues() {
userValues = new Array();
for (let i = 0; i < currNumOfValues; i++) {
let inputField = document.getElementById(`value${i}`);
let currCharStr = String.fromCharCode(65 + i);
if (inputField.value === '1' || inputField.value === 'true' || inputField.value === 'True'|| inputField.value === 'TRUE' || inputField.value === 't' || inputField.value === 'T') {
VALUES.add(currCharStr);
userValues.push([currCharStr, true]);
} else if (inputField.value === '0' || inputField.value === 'false' || inputField.value === 'False' || inputField.value === 'FALSE' || inputField.value === 'f' || inputField.value === 'F') {
VALUES.add(currCharStr);
userValues.push([currCharStr, false]);
}
}
for (const iterator in VALUES) {
console.log(iterator, VALUES[iterator]);
}
}
// Evaluate given formula and display the result
function Evaluate() {
ToggleAll(false);
FetchValues();
let formulaField = document.getElementById('formula');
let formulaChraArray = formulaField.value.split('');
let formulaRPNArray = ConvertToRPNArray(formulaChraArray);
let formulaValuesRPNArray = ConvertCharsToValues(formulaRPNArray);
let result = SolveRPNFormula(formulaValuesRPNArray);
if (result == undefined) return;
let readableResult = ConvertToReadableResult(result);
let resultField = document.getElementById('result');
resultField.value = readableResult;
}
//#endregion
//#region Boolean Operations
function Negation(value) {
if (value != undefined) { return !value; }
}
function Conjunction(firstValue, secondValue) {
if (firstValue === true && secondValue === true) {
return true;
} else if (firstValue === false && secondValue === true || firstValue === true && secondValue === false || firstValue === false && secondValue === false) {
return false;
}
}
function Disjunction(firstValue, secondValue) {
if (firstValue === true || secondValue === true) {
return true;
} else if (firstValue === false && secondValue === false) {
return false;
}
}
function Equivalence(firstValue, secondValue) {
if (firstValue === secondValue) {
return true;
} else if (firstValue !== secondValue) {
return false;
}
}
//#endregion
//#region Essential Functions
function ConvertToRPNArray(chars) {
let _values_stack = new Array();
let _actions_stack = new Array();
for (let i = 0; i < chars.length; i++) {
const element = chars[i];
if (!OPERATORS.has(element) && !BRACKETS.has(element)) {
_values_stack.push(element);
} else if (OPERATORS.has(element)) {
while (GetActionPriority(_actions_stack[_actions_stack.length - 1]) >= GetActionPriority(element)) {
let last = _actions_stack.pop();
if (last != '(') {
_values_stack.push(last);
} else {
break;
}
}
if (_actions_stack[0] == undefined || GetActionPriority(_actions_stack[_actions_stack.length - 1]) < GetActionPriority(element)) {
_actions_stack.push(element);
}
} else if (BRACKETS.has(element)) {
if (element == '(') {
_actions_stack.push(element);
}
if (element == ')') {
let _last = _actions_stack.pop();
while (_last != '(') {
_values_stack.push(_last);
_last = _actions_stack.pop();
}
}
} else {
Error('The programm cant solve given formula. Do you typed everything right? Maybe you forgot to define some value?');
}
}
while (_actions_stack[0] != undefined) {
_values_stack.push(_actions_stack.pop());
}
return _values_stack;
}
function ConvertCharsToValues(RPNArray) {
let valuesRNPArray = new Array();
RPNArray.forEach(element => {
if (VALUES.has(element)) {
valuesRNPArray.push(GetValueFromIndex(element));
} else if (element !== '(' || element !== ')') {
valuesRNPArray.push(element);
}
});
return valuesRNPArray;
}
function SolveRPNFormula(valuesRPNArray) {
let stepByStepResults = new Array();
let _stack = new Array();
for (let i = 0; i < valuesRPNArray.length; i++) {
const element = valuesRPNArray[i];
if (OPERATORS.has(element)) {
if (element == '!') {
let _currValue = _stack.pop();
let _result = Negation(_currValue);
_stack.push(_result);
stepByStepResults.push(ConvertToReadableResult(_result));
} else if (element == '*') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = Conjunction(_firstValue, _secondValue);
_stack.push(_result);
stepByStepResults.push(ConvertToReadableResult(_result));
} else if (element == '+') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = Disjunction(_firstValue, _secondValue);
_stack.push(_result);
stepByStepResults.push(ConvertToReadableResult(_result));
} else if (element == '>') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = Disjunction(Negation(_firstValue), _secondValue);
_stack.push(_result);
stepByStepResults.push(ConvertToReadableResult(_result));
} else if (element == '=') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = Equivalence(_firstValue, _secondValue);
_stack.push(_result);
stepByStepResults.push(ConvertToReadableResult(_result));
}
} else {
_stack.push(element);
}
}
return _stack[0];
}
//#endregion
//#region Step By Step
// Evalutae formula and display steps in the interface
function StepByStep() {
FetchValues();
let formulaField = document.getElementById('formula');
let formulaChraArray = formulaField.value.split('');
let formulaRPNArray = ConvertToRPNArray(formulaChraArray);
let formulaValuesRPNArray = ConvertCharsToValues(formulaRPNArray);
let result = SolveRPNFormula(formulaValuesRPNArray);
if (result == undefined) return;
let readableResult = ConvertToReadableResult(result);
let resultField = document.getElementById('result');
resultField.value = readableResult;
let stepsActionsArray = GetCharSteps(formulaRPNArray);
let stepsResultsArray = GetStepsResults(formulaValuesRPNArray);
// console.log(stepsActionsArray);
// console.log(stepsResultsArray);
if (stepsResultsArray.length > 0) {
ToggleAll(false);
ToggleSteps(true);
for (let i = 0; i < stepsActionsArray.length; i++) {
const action = stepsActionsArray[i];
const result = stepsResultsArray[i];
stepsWrapper.insertAdjacentHTML('beforeend', ` <div class="input-wrap" id="input-wrap">
<h1 class="text">${i+1}. </h1>
<div class="input"><input type="result" value="${action} = ${result}" readonly/></div>
</div>`);
}
}
// Get steps in form of characters
function GetCharSteps(RPNArray) {
let stepsArray = new Array();
let _stack = new Array();
for (let i = 0; i < RPNArray.length; i++) {
const element = RPNArray[i];
if (OPERATORS.has(element)) {
if (element == '!') {
let _currValue = _stack.pop();
let _result;
if (_currValue.length <= 2) {
_result = '!'.concat(_currValue);
} else {
_result = '!'.concat('(').concat(_currValue).concat(')');
}
_stack.push(_result);
stepsArray.push([_result]);
} else if (element == '*') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result;
let _firstHasExclemMark = Boolean(_firstValue.split('').filter(x => x === '!').length);
let _secondHasExclemMark = Boolean(_secondValue.split('').filter(x => x === '!').length);
if (_firstValue.length <= 2 && _secondValue.length <= 2) {
_result = _firstValue.concat('*').concat(_secondValue);
} else if (_firstValue.length <= 2 && _secondValue.length > 2) {
if (_secondHasExclemMark) {
_result = _firstValue.concat('*').concat(_secondValue);
} else {
_result =
_firstValue.concat('*').concat('(').concat(_secondValue).concat(')');
}
} else if (_firstValue.length > 2 && _secondValue.length <= 2) {
if (_firstHasExclemMark) {
_result = _firstValue.concat('*').concat(_secondValue);
} else {
_result = '('.concat(_firstValue).concat(')').concat('*').concat(_secondValue);
}
} else if (_firstValue.length > 2 && _secondValue.length > 2) {
if (_firstHasExclemMark && _secondHasExclemMark) {
_result = _firstValue.concat('*').concat(_secondValue);
} if (_firstHasExclemMark && !_secondHasExclemMark) {
_result = _firstValue.concat('*').concat('(').concat(_secondValue).concat(')');
} else if (!_firstHasExclemMark && _secondHasExclemMark) {
_result = '('.concat(_firstValue).concat(')').concat('*').concat(_secondValue);;
} else {
_result = '('.concat(_firstValue).concat(')').concat('*').concat('(').concat(_secondValue).concat(')');
}
}
_stack.push(_result);
stepsArray.push([_result]);
} else if (element == '+') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = _firstValue.concat('+').concat(_secondValue);
_stack.push(_result);
stepsArray.push([_result]);
} else if (element == '>') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = _firstValue.concat('>').concat(_secondValue);
_stack.push(_result);
stepsArray.push([_result]);
} else if (element == '=') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = _firstValue.concat('=').concat(_secondValue);
_stack.push(_result);
stepsArray.push([_result]);
}
} else {
_stack.push(element);
}
}
return stepsArray;
// return _stack[0];
}
// Get a result of each step
function GetStepsResults(valuesRPNArray) {
let stepByStepResults = new Array();
let _stack = new Array();
for (let i = 0; i < valuesRPNArray.length; i++) {
const element = valuesRPNArray[i];
if (OPERATORS.has(element)) {
if (element == '!') {
let _currValue = _stack.pop();
let _result = Negation(_currValue);
_stack.push(_result);
stepByStepResults.push(ConvertToReadableResult(_result));
} else if (element == '*') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = Conjunction(_firstValue, _secondValue);
_stack.push(_result);
stepByStepResults.push(ConvertToReadableResult(_result));
} else if (element == '+') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = Disjunction(_firstValue, _secondValue);
_stack.push(_result);
stepByStepResults.push(ConvertToReadableResult(_result));
} else if (element == '>') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = Disjunction(Negation(_firstValue), _secondValue);
_stack.push(_result);
stepByStepResults.push(ConvertToReadableResult(_result));
} else if (element == '=') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = Equivalence(_firstValue, _secondValue);
_stack.push(_result);
stepByStepResults.push(ConvertToReadableResult(_result));
}
} else {
_stack.push(element);
}
}
return stepByStepResults;
}
}
//#endregion
//#region Truth Table
// Generate truth table and display it in the interface
function BuildTruthTable() {
let header = document.getElementById('formula').value.match(/[A-Z]/g);
let matrix = GenerateTruthTable();
DisplayTruthTable(matrix, header);
}
// Generate truth table
function GenerateTruthTable() {
let formulaField = document.getElementById('formula');
let numColumns = formulaField.value.match(/[A-Z]/g).length;
let numRows = Math.pow(2, numColumns);
// Initializing the truthTable
let truthTable = new Array();
for (let i = 0; i < numRows; i++) {
truthTable.push(new Array(numColumns + 1));
}
for (let c = 0; c < numColumns; c++) {
let period = Math.pow(2, numColumns) / Math.pow(2, c+1);
let zeros = true;
for (let r = 0; r < numRows; r++) {
if (zeros) {
truthTable[r][c] = false;
}
if (!zeros) {
truthTable[r][c] = true;
}
if ((r+1) % period == 0) {
zeros = !zeros;
}
}
}
//Evaluate the result for each row
for (let r = 0; r < truthTable.length; r++) {
truthTable[r][numColumns] = SolveRPNFormula(ConvertToRPNArray(formulaField.value.split('').map(x => x = ConvertCharsToValues(x, r))));
}
//Additional functions
function ConvertCharsToValues(index, row) {
return formulaField.value.match(/[A-Z]/g).indexOf(index) != -1 ? truthTable[row][formulaField.value.match(/[A-Z]/g).indexOf(index)] : index;
}
return truthTable;
}
// Display truth table in the interface
function DisplayTruthTable(matrix, header) {
//Display the truth table in the interface
ToggleAll(false);
ToggleTruthTable(true);
let truthTableWrapper = document.querySelector('#truthTableWrapper');
truthTableWrapper.insertAdjacentHTML('beforeend', ` <div class="input-wrap" id="input-wrap">
<h1 class="text"></h1>
<div class="input"><input type="result" value="${header.join(' ')} : Result" readonly/></div>
</div>`);
for (let r = 0; r < matrix.length; r++) {
let result = matrix[r].pop();
truthTableWrapper.insertAdjacentHTML('beforeend', ` <div class="input-wrap" id="input-wrap">
<h1 class="text"></h1>
<div class="input"><input type="result" value="${matrix[r].map(x => x = ConvertToReadableResult(x)).join(' ')} : ${ConvertToReadableResult(result)}" readonly/></div>
</div>`);
}
}
//#endregion
//#region PDNF & PCNF
function BuildPDNF() {
DisplayPDNF(GeneratePDNF());
}
function GeneratePDNF() {
let pdnf = '';
let mintermCount = 0;
let header = document.getElementById('formula').value.match(/[A-Z]/g);
let matrix = GenerateTruthTable();
for (let r = 0; r < matrix.length; r++) {
if (matrix[r][matrix[r].length - 1] == 1) {
pdnf += mintermCount != 0 ? '+(' : '(';
for (let c = 0; c < matrix[r].length - 1; c++) {
pdnf += matrix[r][c] == 0 ? '!' + header[c] : header[c];
pdnf += c != matrix[r].length - 2 ? '*' : '';
}
pdnf += ')';
mintermCount++;
}
}
return pdnf;
}
function DisplayPDNF(pdnf) {
ToggleAll(false);
TogglePDNF(true);
let Wrapper = document.querySelector('#pdnfWrapper');
Wrapper.insertAdjacentHTML('beforeend', ` <div class="input-wrap" id="input-wrap">
<h1 class="text"></h1>
<div class="input"><input type="result" value="${pdnf}" readonly/></div>
</div>`);
}
function BuildPCNF() {
DisplayPCNF(GeneratePCNF());
}
function GeneratePCNF() {
let pcnf = '';
let maxtermCount = 0;
let header = document.getElementById('formula').value.match(/[A-Z]/g);
let matrix = GenerateTruthTable();
for (let r = 0; r < matrix.length; r++) {
if (matrix[r][matrix[r].length - 1] == 0) {
pcnf += maxtermCount != 0 ? '*(' : '(';
for (let c = 0; c < matrix[r].length - 1; c++) {
pcnf += matrix[r][c] == 1 ? '!' + header[c] : header[c];
pcnf += c != matrix[r].length - 2 ? '+' : '';
}
pcnf += ')';
maxtermCount++;
}
}
return pcnf;
}
function DisplayPCNF(pcnf) {
ToggleAll(false);
TogglePCNF(true);
let Wrapper = document.querySelector('#pcnfWrapper');
Wrapper.insertAdjacentHTML('beforeend', ` <div class="input-wrap" id="input-wrap">
<h1 class="text"></h1>
<div class="input"><input type="result" value="${pcnf}" readonly/></div>
</div>`);
}
//#endregion
//#region Additional Functions (Essential too)
function ToggleSteps(show) {
let Node = document.querySelector('#stepsNode');
let Wrapper = document.querySelector('#stepsWrapper');
if (show) {
Node.classList.remove('hide');
Wrapper.querySelectorAll('#input-wrap').forEach((element) => {
element.remove();
});
} else {
Node.classList.add('hide');
}
}
function ToggleTruthTable(show) {
let Node = document.querySelector('#truthTableNode');
let Wrapper = document.querySelector('#truthTableWrapper');
if (show) {
Node.classList.remove('hide');
Wrapper.querySelectorAll('#input-wrap').forEach((element) => {
element.remove();
});
} else {
Node.classList.add('hide');
}
}
function TogglePDNF(show) {
let Node = document.querySelector('#pdnfNode');
let Wrapper = document.querySelector('#pdnfWrapper');
if (show) {
Node.classList.remove('hide');
Wrapper.querySelectorAll('#input-wrap').forEach((element) => {
element.remove();
});
} else {
Node.classList.add('hide');
}
}
function TogglePCNF(show) {
let Node = document.querySelector('#pcnfNode');
let Wrapper = document.querySelector('#pcnfWrapper');
if (show) {
Node.classList.remove('hide');
Wrapper.querySelectorAll('#input-wrap').forEach((element) => {
element.remove();
});
} else {
Node.classList.add('hide');
}
}
function ToggleAll(show) {
ToggleSteps(show);
ToggleTruthTable(show);
TogglePDNF(show);
TogglePCNF(show);
}
const OPERATORS = new Set(['!', '*', '+', '>', '=']);
const BRACKETS = new Set(['(', ')']);
function GetActionPriority(action) {
if (action == '!') {
return 5;
} else if (action == '*') {
return 4;
} else if (action == '+' || action == '>' || action == '=') {
return 3;
} else if (action == '(') {
return 2;
} else {
return 0;
}
}
function GetValueFromIndex(valueIndex) {
for (let i = 0; i < userValues.length; i++) {
const element = userValues[i];
if (element[0] == valueIndex) {
return element[1];
}
}
}
function ConvertToReadableResult(unconverted) {
return unconverted === true ? '1' : '0';
}
function Error(errMsg) {
console.log(` [ERROR] ${errMsg}`);
}
//#endregion
//#region Check Input
const symbols = ['0', '1'];
const specialSymbols = ['Backspace', 'ArrowLeft', 'ArrowRight', 'Delete'];
function checkInputValue(key, value) {
if (value.length < 1 && symbols.indexOf(key) !== -1) {
return true;
} else if (value.length == 1 && specialSymbols.indexOf(key) !== -1) {
return true;
}
else {
return false;
}
}
const symbols2 = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X', 'Y', 'Z', 'Backspace', 'ArrowLeft', 'ArrowRight', 'Delete',
'>', '=', '+', '*', '!', '(', ')'
];
function checkInputProblem(key) {
return (symbols2.indexOf(key) != -1) ? true : false;
}
//#endregion

View File

@ -1,570 +0,0 @@
let maxNumOfValues = 26;
let currNumOfValues = 2;
function AddValue() {
if (currNumOfValues < 26) {
let charNum = 65 + currNumOfValues;
currNumOfValues++;
let delBtn = document.querySelectorAll('#delBtn');
if (delBtn[delBtn.length - 1]) {
delBtn[delBtn.length - 1].style="display: none;";
}
node = document.getElementById('values');
node.insertAdjacentHTML('beforeend', ` <div class="input-wrap">
<h1 class="text">Value &#${charNum} = </h1>
<div class="input"><input type="value" id="value${currNumOfValues - 1}" placeholder="e.g. 0 or 1"/></div>
</div>`);
} else {
alert('You have reached a limint of available values');
}
}
function DeleteValue(valNum) {
let valueField = document.querySelector(`#valueField${valNum}`);
valueField.remove();
currNumOfValues--;
let delBtn = document.querySelectorAll('#delBtn');
if (delBtn[delBtn.length - 1]) {
delBtn[delBtn.length - 1].style="display: inline-block;";
}
}
let VALUES = new Set();
let userValues = new Array();
function FetchValues() {
userValues = new Array();
for (let i = 0; i < currNumOfValues; i++) {
let inputField = document.getElementById(`value${i}`);
let currCharStr = String.fromCharCode(65 + i);
if (inputField.value === '1' || inputField.value === 'true' || inputField.value === 'True'|| inputField.value === 'TRUE' || inputField.value === 't' || inputField.value === 'T') {
VALUES.add(currCharStr);
userValues.push([currCharStr, true]);
} else if (inputField.value === '0' || inputField.value === 'false' || inputField.value === 'False' || inputField.value === 'FALSE' || inputField.value === 'f' || inputField.value === 'F') {
VALUES.add(currCharStr);
userValues.push([currCharStr, false]);
}
}
for (const iterator in VALUES) {
console.log(iterator, VALUES[iterator]);
}
}
let stepByStep = false;
function Evaluate() {
FetchValues();
let formulaField = document.getElementById('formula');
let formulaChraArray = formulaField.value.split('');
let formulaRPNArray = ConvertCharArrayToRPNArray(formulaChraArray);
let formulaValuesRPNArray = ConvertLettersToValues(formulaRPNArray);
let result = SolveRPNFormula(formulaValuesRPNArray);
let readableResult = convertToReadableResult(result[0]);
let resultField = document.getElementById('result');
resultField.value = readableResult;
let stepsNode = document.querySelector('#stepsNode');
let stepsWrapper = document.querySelector('#stepsWrapper');
stepsNode.classList.add('hide');
stepsWrapper.querySelectorAll('#input-wrap').forEach((element) => {
element.remove();
});
if (stepByStep) {
stepsNode.classList.remove('hide');
let stepsActionsArray = StepByStepRPNFormula(formulaRPNArray);
let stepsResultsArray = result[1];
for (let i = 0; i < stepsActionsArray.length; i++) {
const action = stepsActionsArray[i];
const result = stepsResultsArray[i];
stepsWrapper.insertAdjacentHTML('beforeend', ` <div class="input-wrap" id="input-wrap">
<h1 class="text">${i+1}. </h1>
<div class="input"><input type="result" id="step1" value="${action} = ${result}" readonly/></div>
</div>`);
}
stepByStep = false;
}
}
function StepByStep() {
stepByStep = true;
Evaluate();
}
function Negation(value) {
if (value != undefined) { return !value; }
}
function Conjunction(firstValue, secondValue) {
if (firstValue === true && secondValue === true) {
return true;
} else if (firstValue === false && secondValue === true || firstValue === true && secondValue === false || firstValue === false && secondValue === false) {
return false;
}
}
function Disjunction(firstValue, secondValue) {
if (firstValue === true || secondValue === true) {
return true;
} else if (firstValue === false && secondValue === false) {
return false;
}
}
function Equivalence(firstValue, secondValue) {
if (firstValue === secondValue) {
return true;
} else if (firstValue !== secondValue) {
return false;
}
}
function ConvertCharArrayToRPNArray(chars) {
let _values_stack = new Array();
let _actions_stack = new Array();
for (let i = 0; i < chars.length; i++) {
const element = chars[i];
if (VALUES.has(element)) {
_values_stack.push(element);
} else if (OPERATORS.has(element)) {
while (GetActionPriority(_actions_stack[_actions_stack.length - 1]) >= GetActionPriority(element)) {
let last = _actions_stack.pop();
if (last != '(') {
_values_stack.push(last);
} else {
break;
}
}
if (_actions_stack[0] == undefined || GetActionPriority(_actions_stack[_actions_stack.length - 1]) < GetActionPriority(element)) {
_actions_stack.push(element);
}
} else if (BRACKETS.has(element)) {
if (element == '(') {
_actions_stack.push(element);
}
if (element == ')') {
let _last = _actions_stack.pop();
while (_last != '(') {
_values_stack.push(_last);
_last = _actions_stack.pop();
}
}
} else {
Error('The programm cant solve given formula. Do you typed everything right? Maybe you forgot to define some value?');
}
}
while (_actions_stack[0] != undefined) {
_values_stack.push(_actions_stack.pop());
}
return _values_stack;
}
function ConvertLettersToValues(RPNArray) {
let valuesRNPArray = new Array();
RPNArray.forEach(element => {
if (VALUES.has(element)) {
valuesRNPArray.push(GetValueFromIndex(element));
} else if (element !== '(' || element !== ')') {
valuesRNPArray.push(element);
}
});
return valuesRNPArray;
}
function SolveRPNFormula(valuesRPNArray) {
let stepByStepResults = new Array();
let _stack = new Array();
for (let i = 0; i < valuesRPNArray.length; i++) {
const element = valuesRPNArray[i];
if (OPERATORS.has(element)) {
if (element == '!') {
let _currValue = _stack.pop();
let _result = Negation(_currValue);
_stack.push(_result);
stepByStepResults.push(convertToReadableResult(_result));
} else if (element == '*') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = Conjunction(_firstValue, _secondValue);
_stack.push(_result);
stepByStepResults.push(convertToReadableResult(_result));
} else if (element == '+') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = Disjunction(_firstValue, _secondValue);
_stack.push(_result);
stepByStepResults.push(convertToReadableResult(_result));
} else if (element == '>') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = Disjunction(Negation(_firstValue), _secondValue);
_stack.push(_result);
stepByStepResults.push(convertToReadableResult(_result));
} else if (element == '=') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = Equivalence(_firstValue, _secondValue);
_stack.push(_result);
stepByStepResults.push(convertToReadableResult(_result));
}
} else {
_stack.push(element);
}
}
return [_stack[0], stepByStepResults];
}
function StepByStepRPNFormula(RPNArray) {
let stepsArray = new Array();
let _stack = new Array();
for (let i = 0; i < RPNArray.length; i++) {
const element = RPNArray[i];
if (OPERATORS.has(element)) {
if (element == '!') {
let _currValue = _stack.pop();
let _result;
if (_currValue.length <= 2) {
_result = '!'.concat(_currValue);
} else {
_result = '!'.concat('(').concat(_currValue).concat(')');
}
_stack.push(_result);
stepsArray.push([_result]);
} else if (element == '*') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result;
let _firstHasExclemMark = Boolean(_firstValue.split('').filter(x => x === '!').length);
let _secondHasExclemMark = Boolean(_secondValue.split('').filter(x => x === '!').length);
if (_firstValue.length <= 2 && _secondValue.length <= 2) {
_result = _firstValue.concat('*').concat(_secondValue);
} else if (_firstValue.length <= 2 && _secondValue.length > 2) {
if (_secondHasExclemMark) {
_result = _firstValue.concat('*').concat(_secondValue);
} else {
_result =
_firstValue.concat('*').concat('(').concat(_secondValue).concat(')');
}
} else if (_firstValue.length > 2 && _secondValue.length <= 2) {
if (_firstHasExclemMark) {
_result = _firstValue.concat('*').concat(_secondValue);
} else {
_result = '('.concat(_firstValue).concat(')').concat('*').concat(_secondValue);
}
} else if (_firstValue.length > 2 && _secondValue.length > 2) {
if (_firstHasExclemMark && _secondHasExclemMark) {
_result = _firstValue.concat('*').concat(_secondValue);
} if (_firstHasExclemMark && !_secondHasExclemMark) {
_result = _firstValue.concat('*').concat('(').concat(_secondValue).concat(')');
} else if (!_firstHasExclemMark && _secondHasExclemMark) {
_result = '('.concat(_firstValue).concat(')').concat('*').concat(_secondValue);;
} else {
_result = '('.concat(_firstValue).concat(')').concat('*').concat('(').concat(_secondValue).concat(')');
}
}
_stack.push(_result);
stepsArray.push([_result]);
} else if (element == '+') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = _firstValue.concat('+').concat(_secondValue);
_stack.push(_result);
stepsArray.push([_result]);
} else if (element == '>') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = _firstValue.concat('>').concat(_secondValue);
_stack.push(_result);
stepsArray.push([_result]);
} else if (element == '=') {
let _secondValue = _stack.pop();
let _firstValue = _stack.pop();
let _result = _firstValue.concat('=').concat(_secondValue);
_stack.push(_result);
stepsArray.push([_result]);
}
} else {
_stack.push(element);
}
}
return stepsArray;
// return _stack[0];
}
function InputFormulaFotTruthTable() {
let _formulaString = prompt('>>> ');
if (_formulaString.search('[!,*,+,>,=]') == -1) {
Error('The programm cant solve given formula. Do you typed everything right?');
}
if (_formulaString.match(/[a-z]/g) != null) {
_formulaString.match(/[a-z]/g).forEach (element => {
TTVALUESNAMES.add(element);
})
} else {
Error('The programm cant solve given formula. Do you typed everything right?');
}
TTVALUESNAMES.forEach(element => {
TTVALUESCONTENTS.push([element]);
})
let _numColumns = TTVALUESNAMES.size;
let _numRows = Math.pow(2, _numColumns);
let _rowsContent = new Array();
for (let r = 0; r < _numRows; r++) {
_rowsContent.push(new Array());
for (let c = 0; c < _numColumns; c++) {
_rowsContent[r].push(false);
}
}
for (let c = 0; c < _numColumns; c++) {
let _period = Math.pow(2, _numColumns) / Math.pow(2, c+1);
let _zeros = true;
for (let r = 0; r < _numRows; r++) {
if (_zeros) {
_rowsContent[r][c] = false;
TTVALUESCONTENTS[c].push(false);
}
if (!_zeros) {
_rowsContent[r][c] = true;
TTVALUESCONTENTS[c].push(true);
}
if ((r + 1) % _period == 0) {
_zeros = !_zeros;
}
}
}
// console.log(_rowsContent);
// console.log(TTVALUESCONTENTS);
let _formulaCharArray = ConvertFormulaToCharArray(_formulaString);
let _result = new Array();
for (let i = 0; i < _numRows; i++) {
let _formula_RPN_Array = ConvertCharArrayToRPNArray(_formulaCharArray, i + 1);
_result.push(SolveRPNFormula(_formula_RPN_Array));
}
// console.log(_result);
_result.forEach(element => {
if (element == undefined) {
Error('The programm cant solve given formula. Do you typed everything right?');
}
});
ttformula = _formulaString;
numRows = _numRows;
rowsContent = _rowsContent;
truthTable = _result;
console.log('');
for (let r = 0; r < _numRows; r++) {
console.log(` ${_rowsContent[r].join(', ')} : ${_result[r]}`);
}
console.log('');
ClearTruthTableData();
ReturnToMenu();
}
const OPERATORS = new Set(['!', '*', '+', '>', '=']);
const BRACKETS = new Set(['(', ')']);
function GetActionPriority(action) {
if (action == '!') {
return 5;
} else if (action == '*') {
return 4;
} else if (action == '+' || action == '>' || action == '=') {
return 3;
} else if (action == '(') {
return 2;
} else {
return 0;
}
}
function GetValueFromIndex(valueIndex) {
for (let i = 0; i < userValues.length; i++) {
const element = userValues[i];
if (element[0] == valueIndex) {
return element[1];
}
}
}
function convertToReadableResult(unconverted) {
return unconverted === true ? '1' : '0';
}
function Error(errMsg) {
console.log(` [ERROR] ${errMsg}`);
}

BIN
Set-Algebra/Complement.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
Set-Algebra/Union.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
Set-Algebra/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 795 B

94
Set-Algebra/index.html Normal file
View File

@ -0,0 +1,94 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="favicon.png">
<title>Set Algebra Calculator</title>
<link rel="stylesheet" href="../style.css">
</head>
<body>
<div class="container">
<header>
<div class="content">
<h3><a href="..">CDM</a></h3>
<div class="theme">
<h3><a href="">Set Algebra</a></h3>
<h3><a href="../Boolean-Algebra">Boolean Algebra</a></h3>
</div>
</div>
</header>
<div class="wrapper">
<div class="wrap-side">
<h1>Sets</h1>
<div id="sets">
<div class="input-wrap">
<h1 class="text">Set A = </h1>
<div class="input"><input type="set" onkeydown="return checkInputSet(event.key, this.value)" id="set0" placeholder="1,2,3" /></div>
</div>
<div class="input-wrap">
<h1 class="text">Set B = </h1>
<div class="input"><input type="set" onkeydown="return checkInputSet(event.key, this.value)" id="set1" placeholder="Define set" /></div>
</div>
</div>
<input class="addSet" type="button" value="Add Set" onclick="AddSet()" />
</div>
<div class="wrap-side">
<h1>Problem</h1>
<h2><input type="problem" id="formula" onkeydown="return checkInputProblem(event.key)" placeholder="!A-C+B/U" /></h2>
<div class="buttons">
<input class="button" type="button" id="calculate" value="Evaluate" onclick="Evaluate(true)" />
<input class="button" type="button" id="calculate" value="Step by step" onclick="stepByStep()" />
</div>
<div class="wrap-result">
<div class="input-wrap">
<h1 class="text">Result </h1>
<div class="input"><input type="result" id="result" readonly/></div>
</div>
</div>
<h6 class="description">Define sets: A, B, C, and Universal set. Then write the problem you need to solve. </h6>
<h6 class="operations">
<div class="operation">
<div class="operation-bg">!</div>
<h6>Complement</h6>
</div>
<div class="operation">
<div class="operation-bg">/</div>
<h6>Intersection</h6>
</div>
<div class="operation">
<div class="operation-bg">+</div>
<h6>Union</h6>
</div>
<div class="operation">
<div class="operation-bg">-</div>
<h6>Substraction</h6>
</div>
</h6>
</div>
</div>
<div class="wrapper hide" id="stepByStep">
<div class="step-by-step" id="steps">
<h1>Step by step</h1>
</div>
</div>
</div>
<!-- -----------------------------------JS---------------------------- -->
<script src="script.js"></script>
</body>
</html>

377
Set-Algebra/script.js Normal file
View File

@ -0,0 +1,377 @@
let maxNum = 26;
let currNum = 2;
function AddSet() {
if (currNum < 26) {
let charNum = 65 + currNum;
currNum++;
node = document.getElementById('sets');
node.insertAdjacentHTML('beforeend', ` <div class="input-wrap">
<h1 class="text">Set &#${charNum} = </h1>
<div class="input"><input type="set" onkeydown="return checkInputSet(event.key, this.value)" id="set${charNum - 65}" placeholder="Define set"/></div>
</div>`);
} else {
alert('You have reached a limint of available sets');
}
}
let universalSet = new Set();
function Complement(set) {
return (checkEmpty(set)) ? universalSet : Difference(universalSet, set);
}
function Intersection(set1, set2) {
let _intersection = new Set();
set1.forEach(element => {
if (set2.has(element)) {
_intersection.add(element);
}
});
return sortSet(_intersection);
}
function Union(set1, set2) {
let _union = new Set(set1);
set2.forEach(element => {
_union.add(element);
});
return sortSet(_union);
}
function Difference(set1, set2) {
let _difference = new Set(set1);
set2.forEach(element => {
if (_difference.has(element)) {
_difference.delete(element);
}
});
return sortSet(_difference);
}
function sortSet(set) {
let entries = [];
for (let member of set) {
entries.push(+member);
}
set.clear();
for (let entry of entries.sort((a, b) => a - b)) {
set.add(entry);
}
return set;
};
const OPERATORS = new Set(['~', '!', '∩', '/', '', '+', '-']);
const BRACKETS = new Set(['(', ')']);
let SETSNAMES = new Set();
let SETS = new Array();
function Evaluate(hide = false) {
if (hide == true) {
let stepByStep = document.getElementById('stepByStep');
stepByStep.classList.add('hide');
}
FetchSets();
let formulaString = document.getElementById('formula').value;
let charArray = formulaString.split('');
let RPN_Array = ConvertFormulaCharArrayToRPN(charArray);
let result = SolveRPNFormula(RPN_Array);
let readableResult = ConvertToReadableResult(result);
let resultField = document.getElementById('result');
resultField.value = readableResult;
SETSNAMES.clear();
SETS = new Array();
universalSet = new Set();
}
function ConvertFormulaCharArrayToRPN(chars) {
let setsStack = new Array();
let actionsStack = new Array();
chars.forEach(element => {
if (SETSNAMES.has(element)) {
setsStack.push(GetSetFromIndex(element));
}
if (OPERATORS.has(element)) {
while (GetActionPriority(actionsStack[actionsStack.length - 1]) >= GetActionPriority(element)) {
let last = actionsStack.pop();
if (last != '(') {
setsStack.push(last);
} else {
break;
}
}
if (actionsStack[0] == undefined || GetActionPriority(actionsStack[actionsStack.length - 1]) < GetActionPriority(element)) {
actionsStack.push(element);
}
}
if (BRACKETS.has(element)) {
if (element == '(') {
actionsStack.push(element);
}
if (element == ')') {
let last = actionsStack.pop();
while (last != '(') {
setsStack.push(last);
last = actionsStack.pop();
}
}
}
});
while (actionsStack[0] != undefined) {
setsStack.push(actionsStack.pop());
}
return setsStack;
}
function SolveRPNFormula(RPN_Array) {
let stack = new Array();
for (let i = 0; i < RPN_Array.length; i++) {
const element = RPN_Array[i];
if (OPERATORS.has(element)) {
if (element == '~' || element == '!') {
let currSet = stack.pop();
let result = Complement(currSet);
printStep('!', currSet, '', result);
stack.push(result);
} else if (element == '∩' || element == '/') {
let secondSet = stack.pop();
let firstSet = stack.pop();
let result = Intersection(firstSet, secondSet);
printStep('/', firstSet, secondSet, result);
stack.push(result);
} else if (element == '' || element == '+') {
let secondSet = stack.pop();
let firstSet = stack.pop();
let result = Union(firstSet, secondSet);
printStep('+', firstSet, secondSet, result);
stack.push(result);
} else if (element == '-') {
let secondSet = stack.pop();
let firstSet = stack.pop();
let result = Difference(firstSet, secondSet);
printStep('-', firstSet, secondSet, result);
stack.push(result);
}
} else {
stack.push(element);
}
}
return stack[0];
}
function FetchSets() {
let universalArray = new Array();
for (let i = 0; i < currNum; i++) {
let inputField = document.getElementById(`set${i}`);
let numArray;
if (inputField != undefined && inputField.value.length != 0) {
numArray = inputField.value.split(',');
numArray.sort();
let newSet = new Set();
numArray.forEach(element => {
newSet.add(+element);
universalArray.push(+element);
});
SETSNAMES.add(String.fromCharCode(65 + i));
SETS.push(sortSet(newSet));
} else {
SETS.push(new Set());
}
}
universalSet = sortSet(new Set(universalArray));
}
function GetSetFromIndex(index) {
let unicode = index.charCodeAt(0);
let num = unicode - 65;
return SETS[num];
}
function GetActionPriority(action) {
if (action == '~' || action == '!') {
return 5;
} else if (action == '∩' || action == '/') {
return 4;
} else if (action == '' || action == '+') {
return 3;
} else if (action == '-') {
return 2;
} else if (action == '(') {
return 1;
} else {
return 0;
}
}
function ConvertToReadableResult(unconverted) {
return (checkEmpty(unconverted)) ? "Empty Set" : Array.from(unconverted).sort((a, b) => a - b).join(', ');
}
function checkEmpty(set) {
return (set == undefined || set.size == 0) ? true : false;
}
//----------------------------- Step by Step ---------------------------
function stepByStep() {
let stepByStep = document.getElementById('stepByStep');
let clear = document.getElementById('steps');
clear.remove();
step = 0;
stepByStep.classList.remove('hide');
stepByStep.insertAdjacentHTML('beforeend', ` <div class="step-by-step" id="steps">
<h1>Step by step</h1>
</div>`);
Evaluate();
}
let step = 0;
function printStep(operation, firstSet, secondSet, result) {
step++;
let str = '';
let img = "";
switch (operation) {
case '!':
str = `!${setToString(firstSet)} = ${setToString(result)}`;
img = "Complement.png";
break;
case '/':
str = `${setToString(firstSet)} / ${setToString(secondSet)} = ${setToString(result)}`;
img = "Intersection.png";
break;
case '+':
str = `${setToString(firstSet)} + ${setToString(secondSet)} = ${setToString(result)}`;
img = "Union.png";
break;
case '-':
str = `${setToString(firstSet)} - ${setToString(secondSet)} = ${setToString(result)}`;
img = "Substraction.png";
break;
default:
break;
}
let steps = document.getElementById('steps');
steps.insertAdjacentHTML('beforeend', ` <div class="input-wrap">
<h1 class="text">${step}. </h1>
<div class="input"><input type="result" value="${str}" readonly/></div>
<img src="${img}">
</div>`);
}
function setToString(set) {
let str = '';
if (checkEmpty(set)) {
return '{ Empty Set }'
} else {
for (let num of set) {
str += ', ' + num;
}
}
return '{ ' + str.slice(2, str.length) + ' }';
}
//----------------------------- Check Input ---------------------------
const symbols = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'Backspace', 'ArrowLeft', 'ArrowRight', 'Delete'];
function checkInputSet(key, value) {
if (value[value.length - 1] == ',' && symbols.indexOf(key) !== -1) {
return true;
} else if (symbols.indexOf(value[value.length - 1]) !== -1 && key == ',') {
return true;
} else if (symbols.indexOf(key) !== -1) {
return true;
} else {
return false;
}
}
const symbols2 = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X', 'Y', 'Z', 'Backspace', 'ArrowLeft', 'ArrowRight', 'Delete',
'-', '+', '/', '!', '(', ')'
];
function checkInputProblem(key) {
return (symbols2.indexOf(key) != -1) ? true : false;
}

BIN
fonts/MyriadPro-Light.ttf Normal file

Binary file not shown.

BIN
fonts/MyriadPro-Light.woff Normal file

Binary file not shown.

Binary file not shown.

BIN
img/Boolean-Algebra.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
img/Set-Algebra.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
img/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

48
index.html Normal file
View File

@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="img/favicon.png">
<title>CDM Calculator</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<header>
<div class="content">
<h3><a href="">CDM</a></h3>
<div class="theme">
<h3><a href="Set-Algebra">Set Algebra</a></h3>
<h3><a href="Boolean-Algebra">Boolean Algebra</a></h3>
</div>
</div>
</header>
<div class="wrapper">
<div class="wrap-side">
<a href="Set-Algebra" class="calculator">
<img src="img/Set-Algebra.png">
<h1>Set Algebra Calculator</h1>
</a>
</div>
<div class="wrap-side">
<a href="Boolean-Algebra" class="calculator">
<img src="img/Boolean-Algebra.png">
<h1>Boolean Algebra Calculator</h1>
</a>
</div>
</body>
</html>

View File

@ -83,8 +83,7 @@ h4,
h5,
h6 {
font-size: 18px;
font-weight: 400;
font-family: Roboto, sans-serif;
font-family: Myriad-L, sans-serif;
color: #fff;
line-height: 1.2;
}
@ -93,7 +92,16 @@ a {
color: #fff;
}
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap');
@font-face {
font-family: Myriad-L;
src: url(fonts/MyriadPro-Light.ttf);
}
@font-face {
font-family: Myriad-R;
src: url(fonts/MyriadPro-Regular.woff);
}
/* ------------------------------------------------------------------ */
@ -101,6 +109,7 @@ h1 {
color: #fff;
margin: 0 auto;
margin-bottom: 10px;
letter-spacing: 0.75px;
}
h6 {
@ -109,6 +118,10 @@ h6 {
text-align: center;
}
h3 {
letter-spacing: 0.5px;
}
h2 {
font-weight: 300;
}
@ -171,13 +184,15 @@ body {
width: 50%;
}
.set {
.set,
.value {
width: 90%;
margin: 0 auto;
padding: 5px;
}
#sets, #values {
#sets,
#values {
display: flex;
flex-direction: column;
}
@ -191,6 +206,7 @@ body {
.text {
margin: auto 0;
white-space: pre;
letter-spacing: 0.75px;
}
.input {
@ -205,7 +221,7 @@ input[type=value] {
border: 3px solid rgba(255, 255, 255, 0.2);
border-radius: 8px;
font-size: 18px;
font-family: Roboto;
font-family: Myriad-R;
color: #fff;
margin: 5px auto;
padding: 0px 0px 0px 10px;
@ -231,7 +247,13 @@ input[type=button] {
border-radius: 22px;
cursor: pointer;
font-size: 18px;
font-family: Roboto;
font-family: Myriad-R;
transition: 1s;
}
input[type=button]:hover {
background-color: rgba(255, 255, 255, 0.7);
transition: 1s;
}
input[type=result] {
@ -242,7 +264,7 @@ input[type=result] {
color: white;
border-radius: 8px;
font-size: 18px;
font-family: Roboto;
font-family: Myriad-R;
cursor: default;
padding: 0px 0px 0px 10px;
}
@ -255,7 +277,7 @@ input[type=result] {
::placeholder {
color: rgba(255, 255, 255, 0.35);
font-size: 18px;
font-family: Roboto;
font-family: Myriad-R;
}
.addSet,
@ -265,6 +287,7 @@ input[type=result] {
.buttons {
margin: 0 auto;
display: flex;
}
.button {
@ -306,6 +329,43 @@ input[type=result] {
display: none;
}
.input-wrap img {
margin: auto 10px;
height: 50px;
}
/* ------------------Main-------------- */
.calculator {
display: flex;
flex-direction: column;
margin: 20px auto;
width: 90%;
max-width: 250px;
background-color: rgba(255, 255, 255, 0.3);
border-radius: 20px;
padding: 20px;
transition: 1s;
}
.calculator img {
height: 100px;
margin: 20px auto;
}
.calculator:hover {
background-color: rgba(255, 255, 255, 0.5);
transition: 1s;
}
.calculator h1 {
margin: 0 auto;
text-align: center;
font-size: 23px;
max-width: 200px;
}
@media screen and (max-device-width: 650px) and (min-device-width: 0px) {
.wrapper {
flex-direction: column;
@ -315,4 +375,11 @@ input[type=result] {
width: 85%;
margin: 20px auto;
}
.buttons {
flex-direction: column;
margin-top: 15px;
}
.button {
margin: 10px auto;
}
}