Modifying text_levitating_animation.c

Modifying FR to EN comments and using variable starsize
This commit is contained in:
RANDRIA Luca 2025-07-31 01:52:37 +03:00 committed by GitHub
parent 0c2cf54b57
commit 6dcbd18fa3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,55 +2,61 @@
#include <math.h> #include <math.h>
int main() { int main() {
// Configuration // Configuration
const int screenWidth = 800; const int screenWidth = 800;
const int screenHeight = 450; const int screenHeight = 450;
const char* text = "Raylib in Space!"; const char* text = "Raylib in Space!";
const int fontSize = 40; const int fontSize = 40;
const Color textColor = WHITE; const Color textColor = WHITE;
// Initialisation de Raylib // Initialize Raylib
InitWindow(screenWidth, screenHeight, "Levitating Text"); InitWindow(screenWidth, screenHeight, "Levitating Text");
SetTargetFPS(60); SetTargetFPS(60);
// Position initiale du texte (au centre de l'écran) // Initial position of the text (centered on the screen)
Vector2 textPosition = { (float)screenWidth / 2 - MeasureText(text, fontSize) / 2, (float)screenHeight / 2 }; Vector2 textPosition = {
(float)screenWidth / 2 - MeasureText(text, fontSize) / 2,
(float)screenHeight / 2
};
// Variables pour l'animation // Animation variables
float time = 0.0f; // Temps écoulé pour le mouvement sinusoïdal float time = 0.0f; // Elapsed time for sinusoidal movement
float amplitude = 30.0f; // Amplitude du mouvement vertical float amplitude = 30.0f; // Amplitude of vertical movement
float frequency = 1.5f; // Fréquence du mouvement vertical float frequency = 1.5f; // Frequency of vertical movement
// Boucle principale du jeu // Main game loop
while (!WindowShouldClose()) { while (!WindowShouldClose()) {
// Mise à jour // Update
time += GetFrameTime(); // Increment elapsed time
time += GetFrameTime(); // Incrémente le temps écoulé // Compute vertical position based on a sine function
textPosition.y = (float)screenHeight / 2 + sinf(time * frequency) * amplitude;
// Calcule la position verticale basée sur une fonction sinusoïdale // Draw
textPosition.y = (float)screenHeight / 2 + sin(time * frequency) * amplitude; BeginDrawing();
// Dessin ClearBackground(BLACK);
BeginDrawing();
ClearBackground(BLACK); // Draw the text at the updated position
DrawText(text, (int)textPosition.x, (int)textPosition.y, fontSize, textColor);
// Dessine le texte à la position mise à jour // Optional: Add stars in the background
DrawText(text, (int)textPosition.x, (int)textPosition.y, fontSize, textColor); for (int i = 0; i < 100; ++i) {
Vector2 starPosition = {
(float)GetRandomValue(0, screenWidth),
(float)GetRandomValue(0, screenHeight)
};
float starSize = (float)GetRandomValue(1, 3);
Color starColor = Fade(WHITE, (float)GetRandomValue(20, 80) / 100.0f);
// Optionnel: Ajoute des étoiles en arrière-plan DrawRectangleV(starPosition, (Vector2){starSize, starSize}, starColor); // Use starSize
for (int i = 0; i < 100; ++i) { }
Vector2 starPosition = {(float)GetRandomValue(0, screenWidth), (float)GetRandomValue(0, screenHeight)};
float starSize = (float)GetRandomValue(1, 3);
Color starColor = Fade(WHITE, (float)GetRandomValue(20, 80) / 100.0f); // Étoiles plus ou moins brillantes
DrawPixelV(starPosition, starColor);
}
EndDrawing(); EndDrawing();
} }
// Libération de la mémoire et fermeture de Raylib // Clean up and close Raylib
CloseWindow(); CloseWindow();
return 0; return 0;
} }