Update 'Analog Clock'
parent
9067104a51
commit
cd4bdb09e9
52
Analog-Clock.md
Normal file
52
Analog-Clock.md
Normal file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user