This repository contains the code for a video tutorial on creating a fully functional analog clock using Python and Pygame.
🎥 Watch the Video Tutorial on YouTube
In this tutorial, we build a beautiful analog clock from scratch using Python and Pygame. The tutorial walks you through each step of the process, from setting up the project to creating clock components and implementing real-time updates.
- Customizable Clock Face: Learn how to create a professional-looking clock face with an outer rim, hour markers, and a polished design.
- Dynamic Clock Hands: Build hour, minute, and second hands that rotate in real time.
- Object-Oriented Programming (OOP): The project is structured using OOP principles to keep the code modular and organized.
- Smooth Graphics: Utilize anti-aliasing to create visually appealing components without jagged edges.
- clock.py: Contains the
AnalogClock
class, which handles drawing the clock face, hands, and updates based on the current time. - main.py: The main script that initializes the Pygame window, updates the clock, and renders it on the screen.
-
Clone this repository:
git clone https://github.com/educ8s/analog-clock-pygame.git cd analog-clock-pygame
-
Ensure you have Python and Pygame installed. Install Pygame using pip:
pip install pygame
-
Run the
main.py
script:python main.py
This project is divided into 8 steps:
- Install Pygame - Set up your environment and install the Pygame library.
- Create the Window & Main Loop - Set up the Pygame window and its main loop.
- Draw the Clock Face - Create the clock's outer rim, inner rim, and face.
- Add Hour Markers - Design and position 12 evenly spaced hour markers.
- Create the Minute Hand - Draw and rotate the minute hand based on the current time.
- Create the Hour Hand - Build the hour hand with proportional rotation.
- Create the Seconds Hand - Add the seconds hand with accurate offset and smooth rotation.
- Fetch Real Time - Use Python's
datetime
module to fetch the current time and update the clock.
- Python 3.x
- Pygame
Contributions are welcome! If you have ideas for improvements or additional features, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
Enjoy coding your analog clock and don't forget to share your project! 🚀