Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Buoyancy Calculator #1823

Merged
merged 4 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Calculators/Buoyancy calc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Buoyancy Calculator

## Description
The Buoyancy Calculator is a simple web-based tool that computes the buoyant force exerted on an object submerged in a fluid. The calculation is based on Archimedes' principle, which states that the buoyant force is equal to the weight of the fluid displaced by the object.

## Features
- Calculates buoyant force using user-provided values for fluid density, object volume, and gravity.
- Displays the result directly on the web page.
- Simple and user-friendly interface.

## How to Use
1. Enter the density of the fluid in kilograms per cubic meter (kg/m³).
2. Enter the volume of the object in cubic meters (m³).
3. Enter the acceleration due to gravity in meters per second squared (m/s²), or use the default value of 9.81 m/s².
4. Click the "Calculate Buoyant Force" button to see the result.

## Files
- `index.html`: The HTML file that sets up the structure of the calculator.
- `script.js`: The JavaScript file that contains the logic for calculating the buoyant force.
- `style.css`: The CSS file for styling the calculator.

## Installation
To run the Buoyancy Calculator locally:
1. Clone the repository:
```bash
git clone <repository-url>
29 changes: 29 additions & 0 deletions Calculators/Buoyancy calc/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Buoyancy Calculator</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>Buoyancy Calculator</h1>
<div class="calculator">
<label for="density">Density of Fluid (kg/m³):</label>
<input type="number" id="density" placeholder="Enter density of fluid">

<label for="volume">Volume of Object (m³):</label>
<input type="number" id="volume" placeholder="Enter volume of object">

<label for="gravity">Gravity (m/s²):</label>
<input type="number" id="gravity" value="9.81">

<button onclick="calculateBuoyantForce()">Calculate Buoyant Force</button>

<div id="result"></div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
14 changes: 14 additions & 0 deletions Calculators/Buoyancy calc/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function calculateBuoyantForce() {
const density = parseFloat(document.getElementById('density').value);
const volume = parseFloat(document.getElementById('volume').value);
const gravity = parseFloat(document.getElementById('gravity').value) || 9.81;

if (isNaN(density) || isNaN(volume) || isNaN(gravity)) {
document.getElementById('result').innerText = "Please enter valid numbers for all fields.";
return;
}

const buoyantForce = density * volume * gravity;

document.getElementById('result').innerText = `Buoyant Force: ${buoyantForce.toFixed(2)} N`;
}
62 changes: 62 additions & 0 deletions Calculators/Buoyancy calc/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
body {
font-family: Arial, sans-serif;
background: linear-gradient(135deg, #263daf, #15e334); /* Add gradient background */
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

.container {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
max-width: 400px;
width: 100%;
}

h1 {
text-align: center;
margin-bottom: 20px;
}

.calculator {
display: flex;
flex-direction: column;
}

label {
margin-bottom: 8px;
font-weight: bold;
}

input {
margin-bottom: 16px;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 16px;
}

button {
padding: 10px;
border: none;
background-color: #007bff;
color: #fff;
font-size: 16px;
cursor: pointer;
border-radius: 4px;
}

button:hover {
background-color: #0056b3;
}

#result {
margin-top: 20px;
font-size: 18px;
font-weight: bold;
text-align: center;
}