Area of Cylinder Calculator

Area of Cylinder Calculator

📏 Input Parameters

Enter the radius of the cylinder
Enter the height of the cylinder
3
Set decimal places for results

📊 Results

📐 Formulas

Base Area: π × r²
Lateral Surface Area: 2 × π × r × h
Total Surface Area: 2 × π × r × (r + h)

🔢 Step-by-Step Calculation

Enter radius and height values to see calculations…

✨ Final Results

Results will appear here after calculation…

🎯 Interactive Cylinder Diagram

h r

📚 Calculation History

No calculations yet. Start by entering radius and height values!

💡 Calculation Tips

  • Keyboard Shortcuts: Press Enter to calculate, Esc to reset
  • Units: All measurements will be converted to consistent units automatically
  • Precision: Adjust decimal places using the slider for your preferred accuracy
  • Real-time Validation: Invalid inputs are highlighted instantly
  • History: Your last 10 calculations are automatically saved
  • Sharing: Export results as PDF or share directly via social media
`; const blob = new Blob([pdfContent], { type: 'text/html' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `cylinder-calculation-${new Date().toISOString().split('T')[0]}.html`; a.click(); URL.revokeObjectURL(url); showToast('Report downloaded successfully!'); }function shareWhatsApp() { if (!hasValidInputs()) { showToast('Please calculate first before sharing!', 'error'); return; } const radius = document.getElementById('radius').value; const height = document.getElementById('height').value; const radiusUnit = document.getElementById('radiusUnit').value; const heightUnit = document.getElementById('heightUnit').value; const message = `🧮 *Cylinder Area Calculation*\n\n` + `📏 *Input:*\n` + `• Radius: ${radius} ${radiusUnit}\n` + `• Height: ${height} ${heightUnit}\n\n` + `📊 *Results:*\n` + `${document.getElementById('resultsContent').textContent.replace(/\s+/g, ' ').trim()}\n\n` + `📱 Calculated using Cylinder Area Calculator`; const whatsappUrl = `https://wa.me/?text=${encodeURIComponent(message)}`; window.open(whatsappUrl, '_blank'); showToast('Sharing via WhatsApp...'); }function downloadDiagram() { const svg = document.getElementById('cylinderSVG'); const svgData = new XMLSerializer().serializeToString(svg); const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); const img = new Image(); canvas.width = 400; canvas.height = 300; img.onload = function() { ctx.fillStyle = 'white'; ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.drawImage(img, 0, 0); const link = document.createElement('a'); link.download = `cylinder-diagram-${new Date().toISOString().split('T')[0]}.png`; link.href = canvas.toDataURL(); link.click(); showToast('Diagram downloaded successfully!'); }; img.src = 'data:image/svg+xml;base64,' + btoa(svgData); }function showToast(message, type = 'success') { // Remove existing toast const existingToast = document.querySelector('.toast'); if (existingToast) { existingToast.remove(); } const toast = document.createElement('div'); toast.className = `toast ${type}`; toast.textContent = message; document.body.appendChild(toast); // Show toast setTimeout(() => toast.classList.add('show'), 100); // Hide toast after 3 seconds setTimeout(() => { toast.classList.remove('show'); setTimeout(() => toast.remove(), 300); }, 3000); }function saveHistory() { // In a real WordPress environment, this could save to localStorage // For now, we'll just keep it in memory }function loadHistory() { // In a real WordPress environment, this could load from localStorage displayHistory(); }function debounce(func, wait) { let timeout; return function executedFunction(...args) { const later = () => { clearTimeout(timeout); func(...args); }; clearTimeout(timeout); timeout = setTimeout(later, wait); }; }// Auto-calculate on page load if there are values window.addEventListener('load', function() { if (hasValidInputs()) { calculate(); } });