From 67f19e99e3c66a0573aa5898fc82fe219919f52e Mon Sep 17 00:00:00 2001 From: k00lagin Date: Fri, 10 May 2024 16:43:48 +0500 Subject: [PATCH 1/2] Random implementation and example --- examples/core_random_colors.c | 47 +++++++++++++++++++++++++++++++++++ index.html | 2 +- nob.c | 5 ++++ raylib.js | 12 +++++++++ 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 examples/core_random_colors.c diff --git a/examples/core_random_colors.c b/examples/core_random_colors.c new file mode 100644 index 0000000..4483baf --- /dev/null +++ b/examples/core_random_colors.c @@ -0,0 +1,47 @@ +#include "raylib.h" + +void raylib_js_set_entry(void (*entry)(void)); + +unsigned int framesCounter = 0; +int r = 150; +int g = 150; +int b = 150; + +void GameFrame() +{ + BeginDrawing(); + ClearBackground(CLITERAL(Color){r, g, b, 255}); + framesCounter++; + + if (((framesCounter / 120) % 2) == 1) + { + r = GetRandomValue(50, 255); + g = GetRandomValue(50, 255); + b = GetRandomValue(50, 255); + framesCounter = 0; + } + + ClearBackground(CLITERAL(Color){r, g, b, 255}); + DrawText("Every 2 seconds a new random color is generated", 130, 100, 20, BLACK); + EndDrawing(); +} + +int main(void) +{ + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "Random colors"); + + SetTargetFPS(60); +#ifdef PLATFORM_WEB + raylib_js_set_entry(GameFrame); +#else + while (!WindowShouldClose()) + { + GameFrame(); + } + CloseWindow(); +#endif + return 0; +} \ No newline at end of file diff --git a/index.html b/index.html index 960a2cd..dd61088 100644 --- a/index.html +++ b/index.html @@ -68,7 +68,7 @@