Orbital Harmony is a simple and visually captivating simulation of the Earth and Moon orbiting the Sun. Built using HTML5 Canvas and JavaScript, this project demonstrates the beauty of celestial mechanics in a responsive and interactive way.
Check out the live of the project here:
Orbital Harmony Live
- Responsive Design: The simulation adjusts to the size of your browser window.
- Realistic Animation: Smooth animation of the Earth orbiting the Sun and the Moon orbiting the Earth.
- Interactive Background: A starry background adds depth and realism to the simulation.
The project uses HTML5 Canvas to render the Sun, Earth, and Moon. The positions of the Earth and Moon are calculated using trigonometric functions (Math.cos
and Math.sin
) to simulate their orbits. The animation is powered by requestAnimationFrame
, ensuring smooth and efficient rendering.
- Sun: A stationary yellow circle at the center of the canvas.
- Earth: A blue circle orbiting the Sun.
- Moon: A gray circle orbiting the Earth.
- Stars: Randomly placed white dots to create a starry background.
The core logic of the project is in the <script>
tag of the HTML file. Here's a breakdown:
- Canvas Setup: The canvas is dynamically resized to fit the browser window.
- Celestial Bodies: The Sun, Earth, and Moon are drawn using the
arc
method. - Animation: The
animate
function updates the positions of the Earth and Moon and redraws the scene for each frame.
To run this project locally, follow these steps:
- Clone the repository:
git clone https://github.com/your-username/orbital-harmony.git
- Navigate to the project directory:
cd orbital-harmony
- Open the index.html file in your browser:
open index.html
- HTML5
- CSS3
- JavaScript (ES6)
Contributions are welcome! If you'd like to improve this project, please follow these steps:
- Fork the repository.
- Create a new branch:
git checkout -b feature/YourFeatureName
- Commit your changes:
git commit -m 'Add some feature'
- Push to the branch:
git push origin feature/YourFeatureName
This project is licensed under the MIT License. See the LICENSE file for details.
Enjoy the beauty of celestial motion with Orbital Harmony! 🌍🌕☀️