You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.8 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [shapes] example - draw circle sector (with gui options)
  4. *
  5. * Example originally created with raylib 2.5, last time updated with raylib 2.5
  6. *
  7. * Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
  8. *
  9. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  10. * BSD-like license that allows static linking with closed source software
  11. *
  12. * Copyright (c) 2018-2023 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
  13. *
  14. ********************************************************************************************/
  15. #include <raylib.h>
  16. #define RAYGUI_IMPLEMENTATION
  17. #include "raygui.h" // Required for GUI controls
  18. //------------------------------------------------------------------------------------
  19. // Program main entry point
  20. //------------------------------------------------------------------------------------
  21. int main(void)
  22. {
  23. // Initialization
  24. //--------------------------------------------------------------------------------------
  25. const int screenWidth = 800;
  26. const int screenHeight = 450;
  27. InitWindow(screenWidth, screenHeight, "raylib [shapes] example - draw circle sector");
  28. Vector2 center = {(GetScreenWidth() - 300)/2.0f, GetScreenHeight()/2.0f };
  29. float outerRadius = 180.0f;
  30. float startAngle = 0.0f;
  31. float endAngle = 180.0f;
  32. float segments = 10.0f;
  33. float minSegments = 4;
  34. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  35. //--------------------------------------------------------------------------------------
  36. // Main game loop
  37. while (!WindowShouldClose()) // Detect window close button or ESC key
  38. {
  39. // Update
  40. //----------------------------------------------------------------------------------
  41. // NOTE: All variables update happens inside GUI control functions
  42. //----------------------------------------------------------------------------------
  43. // Draw
  44. //----------------------------------------------------------------------------------
  45. BeginDrawing();
  46. ClearBackground(RAYWHITE);
  47. DrawLine(500, 0, 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.6f));
  48. DrawRectangle(500, 0, GetScreenWidth() - 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.3f));
  49. DrawCircleSector(center, outerRadius, startAngle, endAngle, (int)segments, Fade(MAROON, 0.3f));
  50. DrawCircleSectorLines(center, outerRadius, startAngle, endAngle, (int)segments, Fade(MAROON, 0.6f));
  51. // Draw GUI controls
  52. //------------------------------------------------------------------------------
  53. GuiSliderBar((Rectangle){ 600, 40, 120, 20}, "StartAngle", NULL, &startAngle, 0, 720);
  54. GuiSliderBar((Rectangle){ 600, 70, 120, 20}, "EndAngle", NULL, &endAngle, 0, 720);
  55. GuiSliderBar((Rectangle){ 600, 140, 120, 20}, "Radius", NULL, &outerRadius, 0, 200);
  56. GuiSliderBar((Rectangle){ 600, 170, 120, 20}, "Segments", NULL, &segments, 0, 100);
  57. //------------------------------------------------------------------------------
  58. minSegments = (int)ceilf((endAngle - startAngle) / 90);
  59. DrawText(TextFormat("MODE: %s", (segments >= minSegments)? "MANUAL" : "AUTO"), 600, 200, 10, (segments >= minSegments)? MAROON : DARKGRAY);
  60. DrawFPS(10, 10);
  61. EndDrawing();
  62. //----------------------------------------------------------------------------------
  63. }
  64. // De-Initialization
  65. //--------------------------------------------------------------------------------------
  66. CloseWindow(); // Close window and OpenGL context
  67. //--------------------------------------------------------------------------------------
  68. return 0;
  69. }