shapes_draw_ring.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*******************************************************************************************
  2. *
  3. * raylib [shapes] example - draw ring (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-2022 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 ring");
  28. Vector2 center = {(GetScreenWidth() - 300)/2.0f, GetScreenHeight()/2.0f };
  29. float innerRadius = 80.0f;
  30. float outerRadius = 190.0f;
  31. float startAngle = 0.0f;
  32. float endAngle = 360.0f;
  33. int segments = 0;
  34. int minSegments = 4;
  35. bool drawRing = true;
  36. bool drawRingLines = false;
  37. bool drawCircleLines = false;
  38. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  39. //--------------------------------------------------------------------------------------
  40. // Main game loop
  41. while (!WindowShouldClose()) // Detect window close button or ESC key
  42. {
  43. // Update
  44. //----------------------------------------------------------------------------------
  45. // NOTE: All variables update happens inside GUI control functions
  46. //----------------------------------------------------------------------------------
  47. // Draw
  48. //----------------------------------------------------------------------------------
  49. BeginDrawing();
  50. ClearBackground(RAYWHITE);
  51. DrawLine(500, 0, 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.6f));
  52. DrawRectangle(500, 0, GetScreenWidth() - 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.3f));
  53. if (drawRing) DrawRing(center, innerRadius, outerRadius, startAngle, endAngle, segments, Fade(MAROON, 0.3f));
  54. if (drawRingLines) DrawRingLines(center, innerRadius, outerRadius, startAngle, endAngle, segments, Fade(BLACK, 0.4f));
  55. if (drawCircleLines) DrawCircleSectorLines(center, outerRadius, startAngle, endAngle, segments, Fade(BLACK, 0.4f));
  56. // Draw GUI controls
  57. //------------------------------------------------------------------------------
  58. startAngle = GuiSliderBar((Rectangle){ 600, 40, 120, 20 }, "StartAngle", NULL, startAngle, -450, 450);
  59. endAngle = GuiSliderBar((Rectangle){ 600, 70, 120, 20 }, "EndAngle", NULL, endAngle, -450, 450);
  60. innerRadius = GuiSliderBar((Rectangle){ 600, 140, 120, 20 }, "InnerRadius", NULL, innerRadius, 0, 100);
  61. outerRadius = GuiSliderBar((Rectangle){ 600, 170, 120, 20 }, "OuterRadius", NULL, outerRadius, 0, 200);
  62. segments = (int)GuiSliderBar((Rectangle){ 600, 240, 120, 20 }, "Segments", NULL, (float)segments, 0, 100);
  63. drawRing = GuiCheckBox((Rectangle){ 600, 320, 20, 20 }, "Draw Ring", drawRing);
  64. drawRingLines = GuiCheckBox((Rectangle){ 600, 350, 20, 20 }, "Draw RingLines", drawRingLines);
  65. drawCircleLines = GuiCheckBox((Rectangle){ 600, 380, 20, 20 }, "Draw CircleLines", drawCircleLines);
  66. //------------------------------------------------------------------------------
  67. int minSegments = (int)ceilf((endAngle - startAngle) / 90);
  68. DrawText(TextFormat("MODE: %s", (segments >= minSegments)? "MANUAL" : "AUTO"), 600, 270, 10, (segments >= minSegments)? MAROON : DARKGRAY);
  69. DrawFPS(10, 10);
  70. EndDrawing();
  71. //----------------------------------------------------------------------------------
  72. }
  73. // De-Initialization
  74. //--------------------------------------------------------------------------------------
  75. CloseWindow(); // Close window and OpenGL context
  76. //--------------------------------------------------------------------------------------
  77. return 0;
  78. }