Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

99 rader
4.6 KiB

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