Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sarry7045 committed Nov 20, 2024
1 parent 63f4a42 commit 5c10738
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions check.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Select the input elements and the launch button
//check the value
const massInput = document.getElementById("mass");
const velocityInput = document.getElementById("velocity");
const angleInput = document.getElementById("angle");
const heightInput = document.getElementById("height");
const launchButton = document.getElementById("launch");

// Function to validate inputs

function validateInputs() {
const mass = parseFloat(massInput.value);
const velocity = parseFloat(velocityInput.value);
Expand All @@ -14,7 +14,7 @@ function validateInputs() {

let errors = [];

// Check each condition and add messages for any errors found

if (mass <= 0) {
errors.push("Mass must be greater than 0.");
}
Expand All @@ -28,18 +28,17 @@ function validateInputs() {
errors.push("Initial Height must not be more than 100 meters.");
}

// Display errors or proceed with simulation
if (errors.length > 0) {
alert(errors.join("\n"));
return false;
}
return true;
}

// Event listener for the launch button

launchButton.addEventListener("click", (e) => {
if (validateInputs()) {
// If inputs are valid, proceed with the simulation in `script.js`

import('./script.js').then(module => {
module.launchSimulation();
});
Expand Down
6 changes: 3 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const g = 9.81; // Acceleration due to gravity (m/s²)
const g = 9.81;

let animationId = null;
let trajectory = [];
Expand All @@ -11,7 +11,7 @@ class Projectile {
constructor(mass, velocity, angle, height) {
this.mass = mass;
this.v0 = velocity;
this.angle = angle * Math.PI / 180; // Convert to radians
this.angle = angle * Math.PI / 180;
this.h0 = height;
this.x = 0;
this.y = height;
Expand Down Expand Up @@ -95,7 +95,7 @@ function animate() {
const dt = 0.016; // 60 FPS
projectile.update(dt);

// Scale factors for drawing
// Scale
const scaleX = canvas.width / (projectile.range + 10);
const scaleY = canvas.height / (projectile.maxHeight + 10);
const scale = Math.min(scaleX, scaleY);
Expand Down

0 comments on commit 5c10738

Please sign in to comment.