Spaces:
Running
Running
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>TasoCalcIO - Scientific Calculator</title> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <style> | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; | |
| font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | |
| } | |
| :root { | |
| --primary-color: #2c3e50; | |
| --secondary-color: #34495e; | |
| --accent-color: #3498db; | |
| --text-color: #ecf0f1; | |
| --button-color: #34495e; | |
| --button-hover: #2c3e50; | |
| --shadow: 0 10px 30px rgba(0, 0, 0, 0.3); | |
| --transition: all 0.3s ease; | |
| } | |
| body { | |
| background: linear-gradient(135deg, #1a2a3a, #2c3e50); | |
| color: var(--text-color); | |
| min-height: 100vh; | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| padding: 20px; | |
| } | |
| .container { | |
| width: 100%; | |
| max-width: 400px; | |
| display: flex; | |
| flex-direction: column; | |
| gap: 15px; | |
| } | |
| .header { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| padding: 10px 15px; | |
| background: rgba(52, 73, 94, 0.8); | |
| border-radius: 15px; | |
| box-shadow: var(--shadow); | |
| } | |
| .logo { | |
| font-size: 1.8rem; | |
| font-weight: 700; | |
| color: var(--accent-color); | |
| display: flex; | |
| align-items: center; | |
| gap: 10px; | |
| } | |
| .logo i { | |
| font-size: 2rem; | |
| } | |
| .theme-switch { | |
| display: flex; | |
| align-items: center; | |
| gap: 10px; | |
| } | |
| .theme-btn { | |
| background: var(--secondary-color); | |
| border: none; | |
| color: var(--text-color); | |
| padding: 8px 15px; | |
| border-radius: 20px; | |
| cursor: pointer; | |
| transition: var(--transition); | |
| display: flex; | |
| align-items: center; | |
| gap: 5px; | |
| font-weight: 500; | |
| } | |
| .theme-btn:hover { | |
| background: var(--accent-color); | |
| } | |
| .calculator { | |
| background: var(--primary-color); | |
| border-radius: 20px; | |
| padding: 20px; | |
| box-shadow: var(--shadow); | |
| } | |
| .display { | |
| background: rgba(236, 240, 241, 0.1); | |
| border-radius: 15px; | |
| padding: 20px; | |
| margin-bottom: 20px; | |
| text-align: right; | |
| min-height: 120px; | |
| display: flex; | |
| flex-direction: column; | |
| justify-content: space-between; | |
| } | |
| .expression { | |
| font-size: 1.2rem; | |
| color: rgba(236, 240, 241, 0.7); | |
| min-height: 30px; | |
| word-wrap: break-word; | |
| overflow-wrap: break-word; | |
| } | |
| .result { | |
| font-size: 2.5rem; | |
| font-weight: 600; | |
| word-wrap: break-word; | |
| overflow-wrap: break-word; | |
| } | |
| .buttons { | |
| display: grid; | |
| grid-template-columns: repeat(5, 1fr); | |
| gap: 12px; | |
| } | |
| .btn { | |
| background: var(--button-color); | |
| border: none; | |
| color: var(--text-color); | |
| padding: 15px 0; | |
| border-radius: 12px; | |
| font-size: 1.2rem; | |
| cursor: pointer; | |
| transition: var(--transition); | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); | |
| } | |
| .btn:hover { | |
| background: var(--button-hover); | |
| transform: translateY(-2px); | |
| } | |
| .btn:active { | |
| transform: translateY(0); | |
| } | |
| .btn.operator { | |
| background: var(--accent-color); | |
| } | |
| .btn.operator:hover { | |
| background: #2980b9; | |
| } | |
| .btn.equals { | |
| background: #e74c3c; | |
| grid-column: span 2; | |
| } | |
| .btn.equals:hover { | |
| background: #c0392b; | |
| } | |
| .btn.function { | |
| background: #9b59b6; | |
| } | |
| .btn.function:hover { | |
| background: #8e44ad; | |
| } | |
| .btn.clear { | |
| background: #e67e22; | |
| } | |
| .btn.clear:hover { | |
| background: #d35400; | |
| } | |
| .footer { | |
| text-align: center; | |
| padding: 10px; | |
| font-size: 0.9rem; | |
| color: rgba(236, 240, 241, 0.7); | |
| } | |
| .footer a { | |
| color: var(--accent-color); | |
| text-decoration: none; | |
| transition: var(--transition); | |
| } | |
| .footer a:hover { | |
| text-decoration: underline; | |
| } | |
| /* Light Theme */ | |
| .light-theme { | |
| --primary-color: #ffffff; | |
| --secondary-color: #f5f5f5; | |
| --accent-color: #3498db; | |
| --text-color: #2c3e50; | |
| --button-color: #f0f0f0; | |
| --button-hover: #e0e0e0; | |
| --shadow: 0 10px 30px rgba(0, 0, 0, 0.1); | |
| } | |
| .light-theme body { | |
| background: linear-gradient(135deg, #e0e0e0, #f5f5f5); | |
| } | |
| .light-theme .display { | |
| background: rgba(44, 62, 80, 0.05); | |
| } | |
| /* Responsive Design */ | |
| @media (max-width: 480px) { | |
| .container { | |
| max-width: 100%; | |
| } | |
| .buttons { | |
| gap: 8px; | |
| } | |
| .btn { | |
| padding: 12px 0; | |
| font-size: 1rem; | |
| } | |
| .result { | |
| font-size: 2rem; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <div class="header"> | |
| <div class="logo"> | |
| <i class="fas fa-calculator"></i> | |
| TasoCalcIO | |
| </div> | |
| <div class="theme-switch"> | |
| <button class="theme-btn" id="themeToggle"> | |
| <i class="fas fa-moon"></i> Dark | |
| </button> | |
| </div> | |
| </div> | |
| <div class="calculator"> | |
| <div class="display"> | |
| <div class="expression" id="expression"></div> | |
| <div class="result" id="result">0</div> | |
| </div> | |
| <div class="buttons"> | |
| <!-- First Row --> | |
| <button class="btn function" data-action="sin">sin</button> | |
| <button class="btn function" data-action="cos">cos</button> | |
| <button class="btn function" data-action="tan">tan</button> | |
| <button class="btn function" data-action="log">log</button> | |
| <button class="btn clear" data-action="clear">C</button> | |
| <!-- Second Row --> | |
| <button class="btn function" data-action="asin">sin⁻¹</button> | |
| <button class="btn function" data-action="acos">cos⁻¹</button> | |
| <button class="btn function" data-action="atan">tan⁻¹</button> | |
| <button class="btn function" data-action="ln">ln</button> | |
| <button class="btn function" data-action="sqrt">√</button> | |
| <!-- Third Row --> | |
| <button class="btn" data-value="7">7</button> | |
| <button class="btn" data-value="8">8</button> | |
| <button class="btn" data-value="9">9</button> | |
| <button class="btn operator" data-action="divide">/</button> | |
| <button class="btn operator" data-action="power">xʸ</button> | |
| <!-- Fourth Row --> | |
| <button class="btn" data-value="4">4</button> | |
| <button class="btn" data-value="5">5</button> | |
| <button class="btn" data-value="6">6</button> | |
| <button class="btn operator" data-action="multiply">×</button> | |
| <button class="btn operator" data-action="pi">π</button> | |
| <!-- Fifth Row --> | |
| <button class="btn" data-value="1">1</button> | |
| <button class="btn" data-value="2">2</button> | |
| <button class="btn" data-value="3">3</button> | |
| <button class="btn operator" data-action="subtract">-</button> | |
| <button class="btn operator" data-action="e">e</button> | |
| <!-- Sixth Row --> | |
| <button class="btn" data-value="0">0</button> | |
| <button class="btn" data-value=".">.</button> | |
| <button class="btn operator" data-action="add">+</button> | |
| <button class="btn equals" data-action="equals">=</button> | |
| </div> | |
| </div> | |
| <div class="footer"> | |
| <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">Built with anycoder</a> | |
| </div> | |
| </div> | |
| <script> | |
| document.addEventListener('DOMContentLoaded', function() { | |
| const resultDisplay = document.getElementById('result'); | |
| const expressionDisplay = document.getElementById('expression'); | |
| const themeToggle = document.getElementById('themeToggle'); | |
| const buttons = document.querySelectorAll('.btn'); | |
| let currentInput = '0'; | |
| let previousInput = ''; | |
| let operation = null; | |
| let resetInput = false; | |
| // Theme Toggle | |
| themeToggle.addEventListener('click', function() { | |
| document.body.classList.toggle('light-theme'); | |
| if (document.body.classList.contains('light-theme')) { | |
| themeToggle.innerHTML = '<i class="fas fa-sun"></i> Light'; | |
| } else { | |
| themeToggle.innerHTML = '<i class="fas fa-moon"></i> Dark'; | |
| } | |
| }); | |
| // Button Click Handler | |
| buttons.forEach(button => { | |
| button.addEventListener('click', function() { | |
| const action = this.dataset.action; | |
| const value = this.dataset.value; | |
| if (value) { | |
| inputNumber(value); | |
| } else if (action) { | |
| handleAction(action); | |
| } | |
| updateDisplay(); | |
| }); | |
| }); | |
| // Keyboard Support | |
| document.addEventListener('keydown', function(event) { | |
| const key = event.key; | |
| if (/[0-9]/.test(key)) { | |
| inputNumber(key); | |
| } else if (key === '.') { | |
| inputNumber(key); | |
| } else if (key === '+') { | |
| handleAction('add'); | |
| } else if (key === '-') { | |
| handleAction('subtract'); | |
| } else if (key === '*') { | |
| handleAction('multiply'); | |
| } else if (key === '/') { | |
| event.preventDefault(); | |
| handleAction('divide'); | |
| } else if (key === 'Enter' || key === '=') { | |
| event.preventDefault(); | |
| handleAction('equals'); | |
| } else if (key === 'Escape' || key === 'Delete') { | |
| handleAction('clear'); | |
| } else if (key === 'Backspace') { | |
| handleAction('backspace'); | |
| } | |
| updateDisplay(); | |
| }); | |
| function inputNumber(num) { | |
| if (currentInput === '0' || resetInput) { | |
| currentInput = num; | |
| resetInput = false; | |
| } else { | |
| currentInput += num; | |
| } | |
| } | |
| function handleAction(action) { | |
| switch (action) { | |
| case 'add': | |
| case 'subtract': | |
| case 'multiply': | |
| case 'divide': | |
| case 'power': | |
| if (operation !== null && !resetInput) { | |
| calculate(); | |
| } | |
| previousInput = currentInput; | |
| operation = action; | |
| resetInput = true; | |
| break; | |
| case 'equals': | |
| if (operation !== null) { | |
| calculate(); | |
| operation = null; | |
| previousInput = ''; | |
| } | |
| break; | |
| case 'clear': | |
| currentInput = '0'; | |
| previousInput = ''; | |
| operation = null; | |
| break; | |
| case 'sin': | |
| currentInput = Math.sin(parseFloat(currentInput) * Math.PI / 180).toString(); | |
| resetInput = true; | |
| break; | |
| case 'cos': | |
| currentInput = Math.cos(parseFloat(currentInput) * Math.PI / 180).toString(); | |
| resetInput = true; | |
| break; | |
| case 'tan': | |
| currentInput = Math.tan(parseFloat(currentInput) * Math.PI / 180).toString(); | |
| resetInput = true; | |
| break; | |
| case 'asin': | |
| currentInput = (Math.asin(parseFloat(currentInput)) * 180 / Math.PI).toString(); | |
| resetInput = true; | |
| break; | |
| case 'acos': | |
| currentInput = (Math.acos(parseFloat(currentInput)) * 180 / Math.PI).toString(); | |
| resetInput = true; | |
| break; | |
| case 'atan': | |
| currentInput = (Math.atan(parseFloat(currentInput)) * 180 / Math.PI).toString(); | |
| resetInput = true; | |
| break; | |
| case 'log': | |
| currentInput = Math.log10(parseFloat(currentInput)).toString(); | |
| resetInput = true; | |
| break; | |
| case 'ln': | |
| currentInput = Math.log(parseFloat(currentInput)).toString(); | |
| resetInput = true; | |
| break; | |
| case 'sqrt': | |
| currentInput = Math.sqrt(parseFloat(currentInput)).toString(); | |
| resetInput = true; | |
| break; | |
| case 'pi': | |
| currentInput = Math.PI.toString(); | |
| resetInput = true; | |
| break; | |
| case 'e': | |
| currentInput = Math.E.toString(); | |
| resetInput = true; | |
| break; | |
| } | |
| } | |
| function calculate() { | |
| let result; | |
| const prev = parseFloat(previousInput); | |
| const current = parseFloat(currentInput); | |
| if (isNaN(prev) || isNaN(current)) return; | |
| switch (operation) { | |
| case 'add': | |
| result = prev + current; | |
| break; | |
| case 'subtract': | |
| result = prev - current; | |
| break; | |
| case 'multiply': | |
| result = prev * current; | |
| break; | |
| case 'divide': | |
| if (current === 0) { | |
| result = 'Error'; | |
| } else { | |
| result = prev / current; | |
| } | |
| break; | |
| case 'power': | |
| result = Math.pow(prev, current); | |
| break; | |
| default: | |
| return; | |
| } | |
| currentInput = result.toString(); | |
| resetInput = true; | |
| } | |
| function updateDisplay() { | |
| resultDisplay.textContent = currentInput; | |
| if (operation !== null) { | |
| let operatorSymbol; | |
| switch (operation) { | |
| case 'add': operatorSymbol = '+'; break; | |
| case 'subtract': operatorSymbol = '-'; break; | |
| case 'multiply': operatorSymbol = '×'; break; | |
| case 'divide': operatorSymbol = '÷'; break; | |
| case 'power': operatorSymbol = '^'; break; | |
| default: operatorSymbol = ''; | |
| } | |
| expressionDisplay.textContent = `${previousInput} ${operatorSymbol}`; | |
| } else { | |
| expressionDisplay.textContent = ''; | |
| } | |
| } | |
| }); | |
| </script> | |
| </body> | |
| </html> |