mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-15 10:55:37 +00:00
REVIEWED: Formatting to follow raylib conventions
This commit is contained in:
@@ -14,9 +14,6 @@
|
||||
* Copyright (c) 2025 JP Mortiboys (@themushroompirates)
|
||||
*
|
||||
********************************************************************************************/
|
||||
#if defined(WIN32)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
@@ -63,24 +60,16 @@ int main(void)
|
||||
/* 8 */ { TL,HH,HH,TR, /* */ VV,TL,TR,VV,/* */ VV,BL,BR,VV,/* */ VV,TL,TR,VV,/* */ VV,BL,BR,VV,/* */ BL,HH,HH,BR },
|
||||
/* 9 */ { TL,HH,HH,TR, /* */ VV,TL,TR,VV,/* */ VV,BL,BR,VV,/* */ BL,HH,TR,VV,/* */ TL,HH,BR,VV,/* */ BL,HH,HH,BR },
|
||||
};
|
||||
|
||||
// Time for the hands to move to the new position (in seconds); this must be <1s
|
||||
const float handsMoveDuration = .5f;
|
||||
const float handsMoveDuration = 0.5f;
|
||||
|
||||
// We store the previous seconds value so we can see if the time has changed
|
||||
int prevSeconds = -1;
|
||||
|
||||
// This represents the real position where the hands are right now
|
||||
Vector2 currentAngles[6][24] = { 0 };
|
||||
|
||||
// This is the position where the hands were moving from
|
||||
Vector2 srcAngles[6][24] = { 0 };
|
||||
// This is the position where the hands are moving to
|
||||
Vector2 dstAngles[6][24] = { 0 };
|
||||
|
||||
// Current animation timer
|
||||
float handsMoveTimer = 0.0f;
|
||||
|
||||
// 12 or 24 hour mode
|
||||
int hourMode = 24;
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
@@ -91,7 +80,6 @@ int main(void)
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Get the current time
|
||||
time_t rawtime;
|
||||
struct tm *timeinfo;
|
||||
@@ -99,30 +87,26 @@ int main(void)
|
||||
time(&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
|
||||
if (timeinfo->tm_sec != prevSeconds) {
|
||||
if (timeinfo->tm_sec != prevSeconds)
|
||||
{
|
||||
// The time has changed, so we need to move the hands to the new positions
|
||||
prevSeconds = timeinfo->tm_sec;
|
||||
|
||||
// Format the current time so we can access the individual digits
|
||||
const char *clockDigits = TextFormat("%02d%02d%02d", timeinfo->tm_hour % hourMode, timeinfo->tm_min, timeinfo->tm_sec);
|
||||
const char *clockDigits = TextFormat("%02d%02d%02d", timeinfo->tm_hour%hourMode, timeinfo->tm_min, timeinfo->tm_sec);
|
||||
|
||||
// Fetch where we want all the hands to be
|
||||
for (int digit = 0; digit < 6; digit++) {
|
||||
for (int cell = 0; cell < 24; cell++) {
|
||||
for (int digit = 0; digit < 6; digit++)
|
||||
{
|
||||
for (int cell = 0; cell < 24; cell++)
|
||||
{
|
||||
srcAngles[digit][cell] = currentAngles[digit][cell];
|
||||
dstAngles[digit][cell] = digitAngles[ clockDigits[digit] - '0' ][cell];
|
||||
dstAngles[digit][cell] = digitAngles[clockDigits[digit] - '0'][cell];
|
||||
|
||||
// Quick exception for 12h mode
|
||||
if (digit == 0 && hourMode == 12 && clockDigits[0] == '0') {
|
||||
dstAngles[digit][cell] = ZZ;
|
||||
}
|
||||
|
||||
if (srcAngles[digit][cell].x > dstAngles[digit][cell].x) {
|
||||
srcAngles[digit][cell].x -= 360.0f;
|
||||
}
|
||||
if (srcAngles[digit][cell].y > dstAngles[digit][cell].y) {
|
||||
srcAngles[digit][cell].y -= 360.0f;
|
||||
}
|
||||
if ((digit == 0) && (hourMode == 12) && (clockDigits[0] == '0')) dstAngles[digit][cell] = ZZ;
|
||||
if (srcAngles[digit][cell].x > dstAngles[digit][cell].x) srcAngles[digit][cell].x -= 360.0f;
|
||||
if (srcAngles[digit][cell].y > dstAngles[digit][cell].y) srcAngles[digit][cell].y -= 360.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,37 +115,29 @@ int main(void)
|
||||
}
|
||||
|
||||
// Now let's animate all the hands if we need to
|
||||
if (handsMoveTimer < handsMoveDuration) {
|
||||
if (handsMoveTimer < handsMoveDuration)
|
||||
{
|
||||
// Increase the timer but don't go above the maximum
|
||||
handsMoveTimer = Clamp(handsMoveTimer + GetFrameTime(), 0, handsMoveDuration);
|
||||
|
||||
// Calculate the % completion of the animation
|
||||
float t = handsMoveTimer / handsMoveDuration;
|
||||
// Calculate the%completion of the animation
|
||||
float t = handsMoveTimer/handsMoveDuration;
|
||||
|
||||
// A little cheeky smoothstep
|
||||
t = t * t * (3.0f - 2.0f * t);
|
||||
t = t*t*(3.0f - 2.0f*t);
|
||||
|
||||
for (int digit = 0; digit < 6; digit++) {
|
||||
for (int cell = 0; cell < 24; cell++) {
|
||||
for (int digit = 0; digit < 6; digit++)
|
||||
{
|
||||
for (int cell = 0; cell < 24; cell++)
|
||||
{
|
||||
currentAngles[digit][cell].x = Lerp(srcAngles[digit][cell].x, dstAngles[digit][cell].x, t);
|
||||
currentAngles[digit][cell].y = Lerp(srcAngles[digit][cell].y, dstAngles[digit][cell].y, t);
|
||||
}
|
||||
}
|
||||
|
||||
if (handsMoveTimer == handsMoveDuration) {
|
||||
// The animation has now finished
|
||||
}
|
||||
}
|
||||
|
||||
// Handle input
|
||||
|
||||
// Toggle between 12 and 24 hour mode with space
|
||||
if (IsKeyPressed(KEY_SPACE)) {
|
||||
hourMode = 36 - hourMode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (IsKeyPressed(KEY_SPACE)) hourMode = 36 - hourMode; // Toggle between 12 and 24 hour mode with space
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
@@ -174,19 +150,22 @@ int main(void)
|
||||
|
||||
float xOffset = 4.0f;
|
||||
|
||||
for (int digit = 0; digit < 6; digit++) {
|
||||
|
||||
for (int row = 0; row < 6; row++) {
|
||||
for (int col = 0; col < 4; col++) {
|
||||
for (int digit = 0; digit < 6; digit++)
|
||||
{
|
||||
for (int row = 0; row < 6; row++)
|
||||
{
|
||||
for (int col = 0; col < 4; col++)
|
||||
{
|
||||
Vector2 centre = (Vector2){
|
||||
xOffset + col*(clockFaceSize+clockFaceSpacing) + clockFaceSize * .5f,
|
||||
100 + row*(clockFaceSize+clockFaceSpacing) + clockFaceSize * .5f
|
||||
xOffset + col*(clockFaceSize+clockFaceSpacing) + clockFaceSize*0.5f,
|
||||
100 + row*(clockFaceSize+clockFaceSpacing) + clockFaceSize*0.5f
|
||||
};
|
||||
DrawRing(centre, clockFaceSize * 0.5f - 2.0f, clockFaceSize * 0.5f, 0, 360, 24, DARKGRAY);
|
||||
|
||||
DrawRing(centre, clockFaceSize*0.5f - 2.0f, clockFaceSize*0.5f, 0, 360, 24, DARKGRAY);
|
||||
|
||||
// Big hand
|
||||
DrawRectanglePro(
|
||||
(Rectangle){centre.x, centre.y, clockFaceSize*.5f+4.0f, 4.0f},
|
||||
(Rectangle){centre.x, centre.y, clockFaceSize*0.5f+4.0f, 4.0f},
|
||||
(Vector2){ 2.0f, 2.0f },
|
||||
currentAngles[digit][row*4+col].x,
|
||||
handsColor
|
||||
@@ -194,7 +173,7 @@ int main(void)
|
||||
|
||||
// Little hand
|
||||
DrawRectanglePro(
|
||||
(Rectangle){centre.x, centre.y, clockFaceSize*.5f+2.0f, 4.0f},
|
||||
(Rectangle){centre.x, centre.y, clockFaceSize*0.5f+2.0f, 4.0f},
|
||||
(Vector2){ 2.0f, 2.0f },
|
||||
currentAngles[digit][row*4+col].y,
|
||||
handsColor
|
||||
@@ -202,27 +181,23 @@ int main(void)
|
||||
}
|
||||
}
|
||||
|
||||
xOffset += (clockFaceSize+clockFaceSpacing) * 4;
|
||||
if (digit % 2 == 1) {
|
||||
|
||||
xOffset += (clockFaceSize+clockFaceSpacing)*4;
|
||||
if (digit%2 == 1)
|
||||
{
|
||||
DrawRing((Vector2){xOffset + 4.0f, 160.0f}, 6.0f, 8.0f, 0.0f, 360.0f, 24, handsColor);
|
||||
DrawRing((Vector2){xOffset + 4.0f, 225.0f}, 6.0f, 8.0f, 0.0f, 360.0f, 24, handsColor);
|
||||
|
||||
xOffset += sectionSpacing;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
DrawFPS(10, 10);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user