diff --git a/Analog-Clock.md b/Analog-Clock.md new file mode 100644 index 0000000..f0bfe99 --- /dev/null +++ b/Analog-Clock.md @@ -0,0 +1,52 @@ +Let's build an analog clock that shows three hands: A second, minute, and hour hand that dynamically update! + +Most analog clocks are circles, so we will use the `DrawCircle()` function to render one. Let's start with a basic OLC project template: + +```cpp +#define OLC_PGE_APPLICATION +#include "olcPixelGameEngine.h" + +// Override base class with your custom functionality +class AnalogClock : public olc::PixelGameEngine +{ +public: + AnalogClock() + { + // Name your application + sAppName = "Analog Clock"; + } + +public: + bool OnUserCreate() override + { + return true; + } + + bool OnUserUpdate(float fElapsedTime) override + { + return true; + } +}; + +int main() +{ + AnalogClock demo; + if (demo.Construct(256, 240, 2, 2)) + demo.Start(); + return 0; +} +``` + +Start by clearing the screen each frame and then drawing a circle with a white outline in the center of the screen. Position defines the center of the circle. Let's make the radius of the circle `100` pixels. + +We will do this in `OnUserUpdate()`: +```cpp + bool OnUserUpdate(float fElapsedTime) override + { + Clear(olc::VERY_DARK_GREEN); + + DrawCircle(GetScreenSize()/2,100); + return true; + } +``` +[[***Try it out!***]](https://pgetinker.com/s/9PzMu2bRS6b)