Repository navigation
Expand file tree
/
Copy pathphysics-calc.html
More file actions
252 lines (227 loc) · 8.37 KB
/
Copy pathphysics-calc.html
File metadata and controls
252 lines (227 loc) · 8.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Physics Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #f5f5f5;
}
.container {
display: flex;
flex-wrap: wrap;
gap: 40px;
max-width: 1200px;
width: 100%;
margin: 20px;
justify-content: space-between;
}
.column {
background-color: #fff;
padding: 20px;
border: 1px solid #ddd;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
width: 48%;
box-sizing: border-box;
}
@media (max-width: 768px) {
.column {
width: 100%;
margin-bottom: 20px;
}
}
h2 {
font-size: 1.5rem;
margin-bottom: 20px;
color: #333;
}
label, input, select, button {
display: block;
margin-bottom: 10px;
width: 100%;
}
input, select {
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
background-color: white;
color: #333;
}
button {
background-color: black;
border: none;
color: white;
padding: 10px;
text-align: center;
font-size: 16px;
cursor: pointer;
border-radius: 5px;
margin-top: 10px;
}
button:hover {
background-color: grey;
}
#result {
font-weight: bold;
margin-top: 20px;
text-align: center;
}
#embed-code {
width: 100%;
height: 100px;
font-size: 14px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
resize: none;
background-color: white;
color: #333;
}
#toast {
visibility: hidden;
min-width: 250px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 2px;
padding: 16px;
position: fixed;
z-index: 1;
left: 50%;
bottom: 30px;
transform: translateX(-50%);
}
#toast.show {
visibility: visible;
animation: fadein 0.5s, fadeout 0.5s 2.5s;
}
@keyframes fadein {
from { bottom: 0; opacity: 0; }
to { bottom: 30px; opacity: 1; }
}
@keyframes fadeout {
from { bottom: 30px; opacity: 1; }
to { bottom: 0; opacity: 0; }
}
</style>
</head>
<body>
<div class="container">
<div class="column">
<h2>Physics Calculator</h2>
<form id="physicsForm">
<label for="calculation">Select Calculation:</label>
<select id="calculation" name="calculation" onchange="updateForm()">
<option value="force">Force (F = m * a)</option>
<option value="energy">Energy (E = m * c^2)</option>
<option value="pressure">Pressure (P = F / A)</option>
</select>
<div id="parameters"></div>
<button type="button" onclick="calculate()">Calculate</button>
<button type="reset" onclick="resetForm()">Reset</button>
</form>
<div id="result" style="display:none;">Result: <span id="calcResult">0</span></div>
</div>
<div class="column">
<h2>Embed Code</h2>
<textarea id="embed-code" readonly>
<iframe src="https://cbemstar.github.io/physics-calc.html" width="100%" height="600" frameborder="0"></iframe>
</textarea>
<button onclick="copyEmbedCode()">Copy Embed Code</button>
</div>
</div>
<div id="toast">Embed code copied to clipboard!</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
updateForm(); // Initialize form with default selection
function updateForm() {
const calculation = document.getElementById('calculation').value;
const parametersDiv = document.getElementById('parameters');
parametersDiv.innerHTML = ''; // Clear previous parameters
switch (calculation) {
case 'force':
addParameter('Mass (m):', 'mass');
addParameter('Acceleration (a):', 'acceleration');
break;
case 'energy':
addParameter('Mass (m):', 'mass');
addParameter('Speed of light (c):', 'speed_of_light', '299792458', true); // Constant value
break;
case 'pressure':
addParameter('Force (F):', 'force');
addParameter('Area (A):', 'area');
break;
}
}
function addParameter(labelText, id, defaultValue = '', readonly = false) {
const label = document.createElement('label');
label.textContent = labelText;
const input = document.createElement('input');
input.type = 'number';
input.id = id;
input.value = defaultValue;
if (readonly) input.readOnly = true;
const parametersDiv = document.getElementById('parameters');
parametersDiv.appendChild(label);
parametersDiv.appendChild(input);
}
window.calculate = function() {
const calculation = document.getElementById('calculation').value;
let result = 0;
switch (calculation) {
case 'force':
const mass = parseFloat(document.getElementById('mass').value);
const acceleration = parseFloat(document.getElementById('acceleration').value);
if (!isNaN(mass) && !isNaN(acceleration)) {
result = mass * acceleration;
}
break;
case 'energy':
const massEnergy = parseFloat(document.getElementById('mass').value);
const speed_of_light = parseFloat(document.getElementById('speed_of_light').value);
if (!isNaN(massEnergy) && !isNaN(speed_of_light)) {
result = massEnergy * Math.pow(speed_of_light, 2);
}
break;
case 'pressure':
const force = parseFloat(document.getElementById('force').value);
const area = parseFloat(document.getElementById('area').value);
if (!isNaN(force) && !isNaN(area)) {
result = force / area;
}
break;
}
document.getElementById('calcResult').textContent = result.toFixed(2);
document.getElementById('result').style.display = 'block';
}
window.resetForm = function() {
document.getElementById('result').style.display = 'none';
updateForm();
}
window.copyEmbedCode = function() {
const embedCode = document.getElementById('embed-code');
embedCode.select();
document.execCommand('copy');
showToast();
}
function showToast() {
const toast = document.getElementById('toast');
toast.className = 'show';
setTimeout(() => {
toast.className = toast.className.replace('show', '');
}, 3000);
}
});
</script>
</body>
</html>