raylib/examples/shapes/shapes_draw_circle_sector.c

88 lines
3.9 KiB
C
Raw Normal View History

/*******************************************************************************************
*
* raylib [shapes] example - draw circle sector (with gui options)
*
2022-07-20 02:28:37 +03:00
* Example originally created with raylib 2.5, last time updated with raylib 2.5
*
* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
*
2022-07-20 02:28:37 +03:00
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
2024-01-02 22:58:12 +03:00
* Copyright (c) 2018-2024 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include <raylib.h>
#define RAYGUI_IMPLEMENTATION
#include "raygui.h" // Required for GUI controls
2022-06-21 20:53:18 +03:00
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
2019-05-20 17:36:42 +03:00
int main(void)
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - draw circle sector");
2021-10-25 11:21:16 +03:00
Vector2 center = {(GetScreenWidth() - 300)/2.0f, GetScreenHeight()/2.0f };
2020-10-05 21:19:18 +03:00
float outerRadius = 180.0f;
float startAngle = 0.0f;
float endAngle = 180.0f;
2023-06-09 19:07:25 +03:00
float segments = 10.0f;
float minSegments = 4;
2019-05-20 17:36:42 +03:00
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// NOTE: All variables update happens inside GUI control functions
//----------------------------------------------------------------------------------
2021-04-22 19:55:24 +03:00
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
2021-04-22 19:55:24 +03:00
ClearBackground(RAYWHITE);
2021-04-22 19:55:24 +03:00
DrawLine(500, 0, 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.6f));
DrawRectangle(500, 0, GetScreenWidth() - 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.3f));
2023-06-09 19:07:25 +03:00
DrawCircleSector(center, outerRadius, startAngle, endAngle, (int)segments, Fade(MAROON, 0.3f));
DrawCircleSectorLines(center, outerRadius, startAngle, endAngle, (int)segments, Fade(MAROON, 0.6f));
2021-04-22 19:55:24 +03:00
// Draw GUI controls
//------------------------------------------------------------------------------
GuiSliderBar((Rectangle){ 600, 40, 120, 20}, "StartAngle", TextFormat("%.2f", startAngle), &startAngle, 0, 720);
GuiSliderBar((Rectangle){ 600, 70, 120, 20}, "EndAngle", TextFormat("%.2f", endAngle), &endAngle, 0, 720);
2021-04-22 19:55:24 +03:00
GuiSliderBar((Rectangle){ 600, 140, 120, 20}, "Radius", TextFormat("%.2f", outerRadius), &outerRadius, 0, 200);
GuiSliderBar((Rectangle){ 600, 170, 120, 20}, "Segments", TextFormat("%.2f", segments), &segments, 0, 100);
//------------------------------------------------------------------------------
2021-04-22 19:55:24 +03:00
2023-11-06 22:31:07 +03:00
minSegments = truncf(ceilf((endAngle - startAngle) / 90));
DrawText(TextFormat("MODE: %s", (segments >= minSegments)? "MANUAL" : "AUTO"), 600, 200, 10, (segments >= minSegments)? MAROON : DARKGRAY);
2021-04-22 19:55:24 +03:00
DrawFPS(10, 10);
2021-04-22 19:55:24 +03:00
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
2021-04-22 19:55:24 +03:00
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}