Skip to content

Commit 41cee3b

Browse files
author
Gideon Serfontein
committed
Added shapes_pie_chart example
1 parent 02b3e44 commit 41cee3b

8 files changed

Lines changed: 686 additions & 2 deletions

File tree

examples/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ SHAPES = \
557557
shapes/shapes_lines_bezier \
558558
shapes/shapes_logo_raylib \
559559
shapes/shapes_logo_raylib_anim \
560+
shapes/shapes_pie_chart \
560561
shapes/shapes_rectangle_advanced \
561562
shapes/shapes_rectangle_scaling \
562563
shapes/shapes_ring_drawing \

examples/Makefile.Web

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ SHAPES = \
557557
shapes/shapes_lines_bezier \
558558
shapes/shapes_logo_raylib \
559559
shapes/shapes_logo_raylib_anim \
560+
shapes/shapes_pie_chart \
560561
shapes/shapes_rectangle_advanced \
561562
shapes/shapes_rectangle_scaling \
562563
shapes/shapes_ring_drawing \
@@ -862,6 +863,9 @@ shapes/shapes_logo_raylib: shapes/shapes_logo_raylib.c
862863
shapes/shapes_logo_raylib_anim: shapes/shapes_logo_raylib_anim.c
863864
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
864865

866+
shapes/shapes_pie_chart: shapes/shapes_pie_chart.c
867+
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
868+
865869
shapes/shapes_rectangle_advanced: shapes/shapes_rectangle_advanced.c
866870
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
867871

examples/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ You may find it easier to use than other toolchains, especially when it comes to
1717
- `zig build [module]` to compile all examples for a module (e.g. `zig build core`)
1818
- `zig build [example]` to compile _and run_ a particular example (e.g. `zig build core_basic_window`)
1919

20-
## EXAMPLES COLLECTION [TOTAL: 172]
20+
## EXAMPLES COLLECTION [TOTAL: 173]
2121

2222
### category: core [40]
2323

@@ -66,7 +66,7 @@ Examples using raylib[core](../src/rcore.c) platform functionality like window c
6666
| [core_undo_redo](core/core_undo_redo.c) | <img src="core/core_undo_redo.png" alt="core_undo_redo" width="80"> | ⭐⭐⭐☆ | 5.5 | 5.6 | [Ramon Santamaria](https://github.com/raysan5) |
6767
| [core_input_actions](core/core_input_actions.c) | <img src="core/core_input_actions.png" alt="core_input_actions" width="80"> | ⭐⭐☆☆ | 5.5 | 5.6 | [Jett](https://github.com/JettMonstersGoBoom) |
6868

69-
### category: shapes [23]
69+
### category: shapes [24]
7070

7171
Examples using raylib shapes drawing functionality, provided by raylib [shapes](../src/rshapes.c) module.
7272

@@ -95,6 +95,7 @@ Examples using raylib shapes drawing functionality, provided by raylib [shapes](
9595
| [shapes_double_pendulum](shapes/shapes_double_pendulum.c) | <img src="shapes/shapes_double_pendulum.png" alt="shapes_double_pendulum" width="80"> | ⭐⭐☆☆ | 5.5 | 5.5 | [JoeCheong](https://github.com/Joecheong2006) |
9696
| [shapes_dashed_line](shapes/shapes_dashed_line.c) | <img src="shapes/shapes_dashed_line.png" alt="shapes_dashed_line" width="80"> | ⭐☆☆☆ | 5.5 | 5.5 | [Luís Almeida](https://github.com/luis605) |
9797
| [shapes_vector_angle](shapes/shapes_vector_angle.c) | <img src="shapes/shapes_vector_angle.png" alt="shapes_vector_angle" width="80"> | ⭐⭐☆☆ | 1.0 | 5.0 | [Ramon Santamaria](https://github.com/raysan5) |
98+
| [shapes_pie_chart](shapes/shapes_pie_chart.c) | <img src="shapes/shapes_pie_chart.png" alt="shapes_pie_chart" width="80"> | ⭐☆☆☆ | 5.5 | 5.6 | [Gideon Serfontein](https://github.com/GideonSerf) |
9899

99100
### category: textures [26]
100101

examples/examples_list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ shapes;shapes_digital_clock;★★★★;5.5;5.6;2025;2025;"Hamza RAHAL";@hmz-rh
7070
shapes;shapes_double_pendulum;★★☆☆;5.5;5.5;2025;2025;"JoeCheong";@Joecheong2006
7171
shapes;shapes_dashed_line;★☆☆☆;5.5;5.5;2025;2025;"Luís Almeida";@luis605
7272
shapes;shapes_vector_angle;★★☆☆;1.0;5.0;2023;2025;"Ramon Santamaria";@raysan5
73+
shapes;shapes_pie_chart;★☆☆☆;5.5;5.6;2025;2025;"Gideon Serfontein";@GideonSerf
7374
textures;textures_logo_raylib;★☆☆☆;1.0;1.0;2014;2025;"Ramon Santamaria";@raysan5
7475
textures;textures_srcrec_dstrec;★★★☆;1.3;1.3;2015;2025;"Ramon Santamaria";@raysan5
7576
textures;textures_image_drawing;★★☆☆;1.4;1.4;2016;2025;"Ramon Santamaria";@raysan5

examples/shapes/shapes_pie_chart.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*******************************************************************************************
2+
*
3+
* raylib [shapes] example - pie chart
4+
*
5+
* Example complexity rating: [★☆☆☆] 1/4
6+
*
7+
* Example originally created with raylib 5.5, last time updated with raylib 5.6
8+
*
9+
* Example contributed by Gideon Serfontein (@GideonSerf) and reviewed by Ramon Santamaria (@raysan5)
10+
*
11+
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
12+
* BSD-like license that allows static linking with closed source software
13+
*
14+
* Copyright (c) 2025 Gideon Serfontein (@GideonSerf)
15+
*
16+
********************************************************************************************/
17+
18+
#include "raylib.h"
19+
20+
//------------------------------------------------------------------------------------
21+
// Program main entry point
22+
//------------------------------------------------------------------------------------
23+
int main(void)
24+
{
25+
// Initialization
26+
//--------------------------------------------------------------------------------------
27+
const int screenWidth = 800;
28+
const int screenHeight = 450;
29+
30+
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - pie chart");
31+
32+
// Pie slice angles (must sum to 360)
33+
const int angles[] = { 30, 10, 45, 35, 60, 38, 75, 67 };
34+
const int anglesCount = (int)(sizeof(angles)/sizeof(angles[0]));
35+
36+
const float radius = 150.0f;
37+
const Vector2 center = { screenWidth/2.0f, screenHeight/2.0f };
38+
39+
// Set our game to run at 60 frames-per-second
40+
SetTargetFPS(60);
41+
//--------------------------------------------------------------------------------------
42+
43+
// Main game loop
44+
while (!WindowShouldClose()) // Detect window close button or ESC key
45+
{
46+
// Draw
47+
//----------------------------------------------------------------------------------
48+
BeginDrawing();
49+
50+
ClearBackground(RAYWHITE);
51+
52+
float lastAngleDeg = 0.0f;
53+
54+
// Number of radial segments for sector drawing
55+
const int segments = 100;
56+
57+
for (int i = 0; i < anglesCount; i++)
58+
{
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+
66+
lastAngleDeg += (float)angles[i];
67+
}
68+
69+
DrawText("Pie chart drawing example", 260, 400, 20, LIGHTGRAY);
70+
71+
EndDrawing();
72+
//----------------------------------------------------------------------------------
73+
}
74+
75+
// De-Initialization
76+
//--------------------------------------------------------------------------------------
77+
CloseWindow(); // Close window and OpenGL context
78+
//--------------------------------------------------------------------------------------
79+
80+
return 0;
81+
}
7.55 KB
Loading

0 commit comments

Comments
 (0)