This repository contains the code for a video tutorial on creating a fully functional analog clock using Raylib and C++.
🎥 Watch the Video Tutorial on YouTube
In this tutorial, we build a visually appealing analog clock from scratch using C++ and Raylib. The tutorial guides you through every step of the process, from setting up the environment to designing the clock's components and implementing real-time updates.
- Customizable Clock Face: Learn how to design a polished clock face with an outer rim, hour markers, and inner details.
- Real-Time Clock Hands: Create dynamic hour, minute, and second hands that update based on the current time.
- Object-Oriented Design: The project is structured using OOP principles for clean and modular code.
- Efficient Graphics Rendering: Use Raylib’s simple and powerful API for smooth and efficient rendering.
- AnalogClock.hpp / AnalogClock.cpp: Contains the
AnalogClock
class, which handles drawing the clock face, hands, and real-time updates. - main.cpp: The main entry point that initializes the Raylib window, updates the clock, and renders it on the screen.
-
Clone this repository:
git clone https://github.com/yourusername/analog-clock-raylib.git cd analog-clock-raylib
-
Install Raylib (if not already installed). Refer to the Raylib installation guide for platform-specific instructions.
-
Compile the project:
g++ main.cpp AnalogClock.cpp -o AnalogClock -lraylib -std=c++17
-
Run the compiled program:
./AnalogClock
This project is divided into the following steps:
- Set Up Raylib - Install Raylib and configure your development environment.
- Create the Window & Main Loop - Initialize the Raylib window and set up the main game loop.
- Draw the Clock Face - Design the clock's outer rim, inner rim, and clean clock face.
- Add Hour Markers - Create and position 12 evenly spaced hour markers around the clock.
- Draw the Minute Hand - Implement a dynamic minute hand that rotates in real time.
- Draw the Hour Hand - Build the hour hand with proportional movement based on the minute value.
- Draw the Seconds Hand - Add the seconds hand with an adjusted pivot point for smooth rotation.
- Fetch Real-Time Data - Use C++’s
<ctime>
library to fetch the current time and update the clock dynamically.
- C++17 or later
- Raylib
Contributions are welcome! If you have ideas for improvements, additional features, or bug fixes, 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! 🚀