Skip to content

Commit

Permalink
Enhanced Carbon Footprint Calculator (#1211)
Browse files Browse the repository at this point in the history
  • Loading branch information
Antiquely3059 authored Jun 10, 2024
1 parent 310767b commit d66d209
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 134 deletions.
30 changes: 16 additions & 14 deletions Calculators/Carbon-Footprint-Calculator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Description :-

The Carbon Footprint Calculator is a web application that estimates an individual's carbon footprint based on the miles driven per year, per month, and per week. Users can input the miles driven for each period, and the calculator provides an estimate of the carbon footprint in kilograms of CO2.
The Carbon Footprint Calculator is a web application that helps users estimate their monthly carbon footprint based on their electricity usage, gas usage, kilometers driven, and flights taken per year.

## Tech Stacks :-

Expand All @@ -12,21 +12,23 @@ The Carbon Footprint Calculator is a web application that estimates an individua

## Features :-

- Estimate carbon footprint based on miles driven per year, month, and week.
- Responsive design for various screen sizes.
- User-friendly interface with modern styling.
- Calculate the carbon footprint based on:
- Electricity usage (kWh per month)
- Gas usage (kg per month)
- Kilometers driven (per month)
- Flights taken (per year)
- Clear and intuitive UI
- Responsive design for various screen sizes

## How It Works :-
## Usage :-

1. **Enter Miles Driven:**
- Input the number of miles driven for the desired time period (year, month, or week).

2. **Calculate Carbon Footprint:**
- Click the "Calculate" button to obtain estimates for the carbon footprint.

3. **View Results:**
- The application displays the estimated carbon footprint in kilograms of CO2 for each time period.
1. Enter your monthly electricity usage in kWh.
2. Enter your monthly gas usage in kg.
3. Enter the kilometers you drive per month.
4. Enter the number of flights you take per year.
5. Click the "Calculate" button to see your estimated carbon footprint in kg CO2e per month.
6. Click the "Reset" button to clear all inputs.

## Screenshots :-

![image](https://github.com/Rakesh9100/CalcDiverse/assets/142514166/1dcf17fc-fe45-4264-866f-9fb42d0454b6)
![image](https://github.com/Rakesh9100/CalcDiverse/assets/73993775/333f5a99-935d-422c-a57f-c33e89fcdb3e)
45 changes: 28 additions & 17 deletions Calculators/Carbon-Footprint-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Carbon Footprint Calculator</title>
</head>

<body>
<div class="calculator-container">
<h1>Carbon Footprint Calculator</h1>
<label for="milesDrivenYear">Enter Miles Driven per Year:</label>
<input type="number" id="milesDrivenYear" placeholder="Enter miles driven per year">

<label for="milesDrivenMonth">Enter Miles Driven per Month:</label>
<input type="number" id="milesDrivenMonth" placeholder="Enter miles driven per month">

<label for="milesDrivenWeek">Enter Miles Driven per Week:</label>
<input type="number" id="milesDrivenWeek" placeholder="Enter miles driven per week">

<button onclick="calculateCarbonFootprint()">Calculate</button>

<div id="result" class="result-container"></div>
<h1 class="waviy"><span style="--i:1">C</span><span style="--i:2">a</span><span style="--i:3">r</span><span style="--i:4">b</span><span style="--i:5">o</span><span style="--i:6">n</span> <span style="--i:7">F</span><span style="--i:8">o</span><span style="--i:9">o</span><span style="--i:10">t</span><span style="--i:11">p</span><span style="--i:12">r</span><span style="--i:13">i</span><span style="--i:14">n</span><span style="--i:15">t</span> <span style="--i:16">C</span><span style="--i:17">a</span><span style="--i:18">l</span><span style="--i:19">c</span><span style="--i:20">u</span><span style="--i:21">l</span><span style="--i:22">a</span><span style="--i:23">t</span><span style="--i:24">o</span><span style="--i:25">r</span></h1>
<div class="card">
<div class="input">
<label for="electricity">Electricity Usage (kWh per month):</label>
<input type="number" id="electricity" name="electricity">
</div>
<div class="input">
<label for="gas">Gas Usage (kg per month):</label>
<input type="number" id="gas" name="gas">
</div>
<div class="input">
<label for="kilometers">Kilometers Driven (per month):</label>
<input type="number" id="kilometers" name="kilometers">
</div>
<div class="input">
<label for="flights">Flights Taken (per year):</label>
<input type="number" id="flights" name="flights">
</div>
<div class="button">
<button id="convert" onclick="calculateCarbonFootprint()">Calculate</button>
</div>
<div class="result">
<input type="text" id="result" readonly>
</div>
<div class="button">
<button id="reset" onclick="resetForm()">Reset</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>

</html>
36 changes: 21 additions & 15 deletions Calculators/Carbon-Footprint-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
function calculateCarbonFootprint() {
// Get the input values
var milesDrivenYear = parseFloat(document.getElementById("milesDrivenYear").value);
var milesDrivenMonth = parseFloat(document.getElementById("milesDrivenMonth").value);
var milesDrivenWeek = parseFloat(document.getElementById("milesDrivenWeek").value);
let electricity = document.getElementById('electricity').value || 0;
let gas = document.getElementById('gas').value || 0;
let kilometers = document.getElementById('kilometers').value || 0;
let flights = document.getElementById('flights').value || 0;

// Validate inputs
if (isNaN(milesDrivenYear) || isNaN(milesDrivenMonth) || isNaN(milesDrivenWeek)) {
alert("Please enter valid numbers for miles driven.");
return;
}
let electricityEmissionFactor = 0.233; // kg CO2 per kWh
let gasEmissionFactor = 2.204; // kg CO2 per kg
let carEmissionFactor = 0.12; // kg CO2 per km
let flightEmissionFactor = 250; // kg CO2 per flight

// Calculate carbon footprints
var carbonFootprintYear = calculateCO2Emissions(milesDrivenYear);
var carbonFootprintMonth = calculateCO2Emissions(milesDrivenMonth);
var carbonFootprintWeek = calculateCO2Emissions(milesDrivenWeek);
let totalEmissions = (electricity * electricityEmissionFactor) +
(gas * gasEmissionFactor) +
(kilometers * carEmissionFactor) +
(flights * flightEmissionFactor / 12);

// Display the results
displayResults(carbonFootprintYear, carbonFootprintMonth, carbonFootprintWeek);
document.getElementById('result').value = totalEmissions.toFixed(2) + ' kg CO2 per month';
}

function resetForm() {
document.getElementById('electricity').value = '';
document.getElementById('gas').value = '';
document.getElementById('kilometers').value = '';
document.getElementById('flights').value = '';
document.getElementById('result').value = '';
}

// Function to calculate CO2 emissions based on miles driven
Expand Down
168 changes: 81 additions & 87 deletions Calculators/Carbon-Footprint-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -1,113 +1,107 @@
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(to bottom right, #3494e6, #ec6ead);
@import url('https://fonts.googleapis.com/css2?family=Alfa+Slab+One&display=swap');

* {
padding: 0;
margin: 0;
box-sizing: border-box;
}

.waviy {
position: relative;
font-size: 2.2rem;
}

.waviy span {
font-family: 'Alfa Slab One', cursive;
position: relative;
display: inline-block;
color: #fff;
text-transform: uppercase;
animation: waviy 1s infinite;
animation-delay: calc(.1s * var(--i));
}

@keyframes waviy {
0%, 40%, 100% {
transform: translateY(0)
}
20% {
transform: translateY(-20px)
}
}

body {
font-family: 'Inconsolata', monospace;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
background: linear-gradient(to right bottom, #7ed0e7, #77c1ee, #87afee, #a399e1, #bf80c6);
height: 100vh;
margin: 0;
}

h1 {
color: #fff;
font-weight: 100;
margin-bottom: 50px;
margin-top: 20px;
font-size: 40px;
}

.calculator-container {
background-color: #fff;
.card {
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 20px;
border-radius: 12px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
text-align: center;
animation: fadeInUp 0.8s ease-out;
max-width: 400px;
width: 100%;
max-width: 550px;
width: 90%;
margin-bottom: 20px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

button {
background-color: #4caf50;
color: #fff;
padding: 12px 20px;
/* Smaller button padding */
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 16px;
/* Slightly smaller font size */
margin-top: 15px;
transition: background-color 0.3s ease, transform 0.2s ease-out;
.input {
margin-bottom: 15px;
}

button:hover {
background-color: #45a049;
transform: scale(1.05);
.input label {
display: block;
margin-bottom: 5px;
color: #fff;
}

input {
.input input {
width: 100%;
padding: 10px;
/* Smaller input padding */
margin: 10px 0;
/* Reduced margin */
width: 90%;
/* Adjusted width for responsiveness */
box-sizing: border-box;
font-size: 14px;
/* Slightly smaller font size */
border-radius: 5px;
border: 1px solid #ccc;
border-radius: 6px;
transition: border-color 0.3s ease, transform 0.2s ease-out;
}

input:focus {
outline: none;
border-color: #4caf50;
transform: scale(1.02);
.button {
margin-top: 20px;
}

.result-container {
font-size: 18px;
/* Slightly larger font size for result */
font-weight: bold;
color: #333;
margin-top: 15px;
animation: fadeIn 1s ease-out;
.button button {
padding: 10px 20px;
background-color: #1e90ff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}

/* Media queries for responsiveness */
@media screen and (max-width: 600px) {
.calculator-container {
padding: 15px;
}

button {
padding: 10px 15px;
font-size: 14px;
}

input {
padding: 8px;
font-size: 12px;
}

.result-container {
font-size: 16px;
}
.button button:hover {
background-color: #4682b4;
}

/* Animations */
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(20px);
}

to {
opacity: 1;
transform: translateY(0);
}
.result input {
width: 100%;
padding: 10px;
box-sizing: border-box;
border-radius: 5px;
border: 1px solid #ccc;
margin-top: 20px;
}

@keyframes fadeIn {
from {
opacity: 0;
}

to {
opacity: 1;
}
}
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ <h3>Converts capacitor values between different units.</h3>
<div class="box">
<div class="content">
<h2>Carbon Footprint Calculator</h2>
<h3>Calculates an individual's carbon footprint based on the miles driven per year, per month, and per week.</h3>
<h3>Calculates an individual's carbon footprint based on some input parameters.</h3>
<div class="card-footer">
<a href="./Calculators/Carbon-Footprint-Calculator/index.html" target="_blank">
<button>Try Now</button>
Expand Down

0 comments on commit d66d209

Please sign in to comment.