An interactive web-based projectile motion simulator built with vanilla HTML, CSS (Tailwind CSS), and modular JavaScript. This project allows users to visualize and explore the physics of projectile motion by adjusting various parameters and observing the resulting trajectory in real-time.
F_drag = -c * v
).localStorage
.vector.js
, projectile.js
, simulation.js
, ui.js
) for better maintainability.import
/export
). Opening index.html
directly from the file system will likely cause errors.Serve the files: Use a simple local web server.
# If you have Python 3 installed
python -m http.server
# Or if the above doesn't work, try:
# python -m SimpleHTTPServer # (Python 2)
npm
):# Install 'serve' globally if you haven't already
npm install -g serve
# Run the server
serve .
index.html
in the VS Code explorer, and select "Open with Live Server".Open in Browser: Navigate to the local address provided by your server (usually http://localhost:8000
, http://localhost:3000
, or http://127.0.0.1:5500
for Live Server).
interactive-projectile-simulator/├── index.html # Main HTML structure├── vector.js # Vector class for 2D math├── projectile.js # Projectile class and physics logic├── simulation.js # Core simulation loop, canvas drawing, state management├── ui.js # UI interactions, event handling, theme switching└── README.md # This file
ui.js
): Handles user input from sliders and buttons, updates value displays, manages theme switching, and calls functions in simulation.js
to start/reset the simulation.simulation.js
): Initializes the canvas, manages the main animation loop (requestAnimationFrame
), creates Projectile
instances, updates their state each frame, handles coordinate conversions (worldToCanvas
), draws the ground, target, and projectile path, and checks for target hits.projectile.js
): Defines the Projectile
object, calculates forces (gravity, air resistance), updates position and velocity using Semi-Implicit Euler integration, and handles ground collisions/bouncing.vector.js
): Provides a simple class for 2D vector operations (add, subtract, multiply, magnitude, normalize).index.html
provides the structure, and Tailwind CSS (loaded via CDN) handles the styling and layout, including responsiveness and dark mode.Contributions are welcome! If you have suggestions or find bugs, please open an issue or submit a pull request.