Skip to content

Commit 77a42c3

Browse files
author
Gideon Serfontein
committed
Minor style updates
1 parent 2ce88e7 commit 77a42c3

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

examples/shapes/shapes_pie_chart.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Example originally created with raylib 5.5, last time updated with raylib 5.6
88
*
9-
* Example contributed by <Gideon Serfontein> (@GideonSerf) and reviewed by Ramon Santamaria (@raysan5)
9+
* Example contributed by Gideon Serfontein (@GideonSerf) and reviewed by Ramon Santamaria (@raysan5)
1010
*
1111
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
1212
* BSD-like license that allows static linking with closed source software
@@ -29,12 +29,15 @@ int main(void)
2929

3030
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - pie chart");
3131

32+
// Pie slice angles (must sum to 360)
3233
const int angles[] = { 30, 10, 45, 35, 60, 38, 75, 67 };
33-
const int anglesCount = sizeof(angles)/sizeof(angles[0]);
34+
const int anglesCount = (int)(sizeof(angles)/sizeof(angles[0]));
35+
3436
const float radius = 150.0f;
35-
const Vector2 center = { screenWidth/2.0f, screenHeight/2.0f};
37+
const Vector2 center = { screenWidth/2.0f, screenHeight/2.0f };
3638

37-
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
39+
// Set our game to run at 60 frames-per-second
40+
SetTargetFPS(60);
3841
//--------------------------------------------------------------------------------------
3942

4043
// Main game loop
@@ -47,11 +50,19 @@ int main(void)
4750
ClearBackground(RAYWHITE);
4851

4952
float lastAngleDeg = 0.0f;
53+
54+
// Number of radial segments for sector drawing
55+
const int segments = 100;
56+
5057
for (int i = 0; i < anglesCount; i++)
5158
{
52-
unsigned char gray = (unsigned char) ((i / (float)anglesCount) * 255.0f); // Gradient gray colors
53-
// Draw pie piece using the DrawCircleSector() function
54-
DrawCircleSector(center, radius, lastAngleDeg, lastAngleDeg + angles[i], 100, (Color){gray, gray, gray, 255});
59+
// Gradient gray color per slice
60+
unsigned char gray = (unsigned char)((i/(float)anglesCount)*255.0f);
61+
62+
// Draw pie piece using DrawCircleSector()
63+
DrawCircleSector(center, radius, lastAngleDeg, lastAngleDeg + (float)angles[i],
64+
segments, (Color){ gray, gray, gray, 255 });
65+
5566
lastAngleDeg += (float)angles[i];
5667
}
5768

0 commit comments

Comments
 (0)