2
0

Function_-_float_random.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "raylib.h"
  2. // For rand_float
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. float float_rand( float min, float max );
  6. int main(void)
  7. {
  8. // Initialization
  9. //--------------------------------------------------------------------------------------
  10. const int screenWidth = 800;
  11. const int screenHeight = 450;
  12. InitWindow(screenWidth, screenHeight, "raylib example.");
  13. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  14. //--------------------------------------------------------------------------------------
  15. float set[5][19] = {0.0f};
  16. for(int x=0;x<5;x++){
  17. for(int y=0;y<19;y++){
  18. set[x][y] = float_rand(-1,1);
  19. }}
  20. // Main game loop
  21. while (!WindowShouldClose()) // Detect window close button or ESC key
  22. {
  23. // Update
  24. //----------------------------------------------------------------------------------
  25. //----------------------------------------------------------------------------------
  26. // Draw
  27. //----------------------------------------------------------------------------------
  28. BeginDrawing();
  29. ClearBackground(RAYWHITE);
  30. DrawText("rand_float(min, max) function.",0,0,20,BLACK);
  31. for(int x=0;x<5;x++){
  32. for(int y=0;y<19;y++){
  33. DrawText(FormatText("%f",set[x][y]),x*150,y*20+40,20,BLACK);
  34. }}
  35. EndDrawing();
  36. //----------------------------------------------------------------------------------
  37. }
  38. // De-Initialization
  39. //--------------------------------------------------------------------------------------
  40. CloseWindow(); // Close window and OpenGL context
  41. //--------------------------------------------------------------------------------------
  42. return 0;
  43. }
  44. float float_rand( float min, float max ){
  45. float scale = rand() / (float) RAND_MAX; /* [0, 1.0] */
  46. return min + scale * ( max - min ); /* [min, max] */
  47. }