Skip to content

Commit 4cfae99

Browse files
authored
[examples] Added shapes_triangle_strip (#5240)
* [examples] Add shapes_triangle_strip * Remove functions
1 parent 5dd97ec commit 4cfae99

File tree

6 files changed

+115
-2
lines changed

6 files changed

+115
-2
lines changed

examples/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ SHAPES = \
564564
shapes/shapes_rounded_rectangle_drawing \
565565
shapes/shapes_splines_drawing \
566566
shapes/shapes_top_down_lights \
567+
shapes/shapes_triangle_strip \
567568
shapes/shapes_vector_angle
568569

569570
TEXTURES = \

examples/Makefile.Web

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ SHAPES = \
564564
shapes/shapes_rounded_rectangle_drawing \
565565
shapes/shapes_splines_drawing \
566566
shapes/shapes_top_down_lights \
567+
shapes/shapes_triangle_strip \
567568
shapes/shapes_vector_angle
568569

569570
TEXTURES = \
@@ -884,6 +885,9 @@ shapes/shapes_splines_drawing: shapes/shapes_splines_drawing.c
884885
shapes/shapes_top_down_lights: shapes/shapes_top_down_lights.c
885886
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
886887

888+
shapes/shapes_triangle_strip: shapes/shapes_triangle_strip.c
889+
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
890+
887891
shapes/shapes_vector_angle: shapes/shapes_vector_angle.c
888892
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
889893

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: 173]
20+
## EXAMPLES COLLECTION [TOTAL: 174]
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 [24]
69+
### category: shapes [25]
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_digital_clock](shapes/shapes_digital_clock.c) | <img src="shapes/shapes_digital_clock.png" alt="shapes_digital_clock" width="80"> | ⭐⭐⭐⭐️ | 5.5 | 5.6 | [Hamza RAHAL](https://github.com/hmz-rhl) |
9696
| [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) |
9797
| [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) |
98+
| [shapes_triangle_strip](shapes/shapes_triangle_strip.c) | <img src="shapes/shapes_triangle_strip.png" alt="shapes_triangle_strip" width="80"> | ⭐⭐☆☆ | 5.6-dev | 5.6-dev | [Jopestpe](https://github.com/jopestpe) |
9899
| [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) |
99100

100101
### category: textures [26]

examples/examples_list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ shapes;shapes_splines_drawing;★★★☆;5.0;5.0;2023;2025;"Ramon Santamaria";
7070
shapes;shapes_digital_clock;★★★★;5.5;5.6;2025;2025;"Hamza RAHAL";@hmz-rhl
7171
shapes;shapes_double_pendulum;★★☆☆;5.5;5.5;2025;2025;"JoeCheong";@Joecheong2006
7272
shapes;shapes_dashed_line;★☆☆☆;5.5;5.5;2025;2025;"Luís Almeida";@luis605
73+
shapes;shapes_triangle_strip;★★☆☆;5.6-dev;5.6-dev;2025;2025;"Jopestpe";@jopestpe
7374
shapes;shapes_vector_angle;★★☆☆;1.0;5.0;2023;2025;"Ramon Santamaria";@raysan5
7475
textures;textures_logo_raylib;★☆☆☆;1.0;1.0;2014;2025;"Ramon Santamaria";@raysan5
7576
textures;textures_srcrec_dstrec;★★★☆;1.3;1.3;2015;2025;"Ramon Santamaria";@raysan5
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*******************************************************************************************
2+
*
3+
* raylib [shapes] example - triangle strip
4+
*
5+
* Example complexity rating: [★★☆☆] 2/4
6+
*
7+
* Example originally created with raylib 5.6-dev, last time updated with raylib 5.6-dev
8+
*
9+
* Example contributed by Jopestpe (@jopestpe)
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) 2018-2025 Jopestpe (@jopestpe)
15+
*
16+
********************************************************************************************/
17+
18+
#include "raylib.h"
19+
#include <math.h>
20+
21+
#define RAYGUI_IMPLEMENTATION
22+
#include "raygui.h" // Required for GUI controls
23+
24+
//------------------------------------------------------------------------------------
25+
// Program main entry point
26+
//------------------------------------------------------------------------------------
27+
int main(void)
28+
{
29+
// Initialization
30+
//--------------------------------------------------------------------------------------
31+
const int screenWidth = 800;
32+
const int screenHeight = 450;
33+
34+
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - triangle strip");
35+
36+
Vector2 points[120] = { 0 };
37+
Vector2 center = { (screenWidth/2.0f) - 125.f, screenHeight/2.0f };
38+
float segments = 6.0f;
39+
float insideRadius = 100.0f;
40+
float outsideRadius = 150.0f;
41+
bool outline = true;
42+
43+
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
44+
//--------------------------------------------------------------------------------------
45+
46+
// Main game loop
47+
while (!WindowShouldClose()) // Detect window close button or ESC key
48+
{
49+
// Update
50+
//----------------------------------------------------------------------------------
51+
int pointCount = (int)(segments);
52+
float angleStep = (360.0f/pointCount)*DEG2RAD;
53+
54+
for (int i = 0, i2 = 0; i < pointCount; i++, i2 += 2)
55+
{
56+
float angle1 = i*angleStep;
57+
points[i2] = (Vector2){ center.x + cosf(angle1)*insideRadius, center.y + sinf(angle1)*insideRadius };
58+
float angle2 = angle1 + angleStep/2.0f;
59+
points[i2 + 1] = (Vector2){ center.x + cosf(angle2)*outsideRadius, center.y + sinf(angle2)*outsideRadius };
60+
}
61+
62+
points[pointCount*2] = points[0];
63+
points[pointCount*2 + 1] = points[1];
64+
//----------------------------------------------------------------------------------
65+
66+
// Draw
67+
//----------------------------------------------------------------------------------
68+
BeginDrawing();
69+
70+
ClearBackground(RAYWHITE);
71+
72+
for (int i = 0, i2 = 0; i < pointCount; i++, i2 += 2)
73+
{
74+
float angle1 = i*angleStep;
75+
Color color = ColorFromHSV(angle1*RAD2DEG, 1.0f, 1.0f);
76+
DrawTriangle(points[i2 + 2], points[i2 + 1], points[i2], color);
77+
if (outline) DrawTriangleLines(points[i2], points[i2 + 1], points[i2 + 2], BLACK);
78+
79+
float angle2 = angle1 + angleStep/2.0f;
80+
color = ColorFromHSV(angle2*RAD2DEG, 1.0f, 1.0f);
81+
DrawTriangle(points[i2 + 3], points[i2 + 1], points[i2 + 2], color);
82+
if (outline) DrawTriangleLines(points[i2 + 2], points[i2 + 1], points[i2 + 3], BLACK);
83+
}
84+
85+
DrawLine(580, 0, 580, GetScreenHeight(), (Color){ 218, 218, 218, 255 });
86+
DrawRectangle(580, 0, GetScreenWidth(), GetScreenHeight(), (Color){ 232, 232, 232, 255 });
87+
88+
// Draw GUI controls
89+
//------------------------------------------------------------------------------
90+
GuiSliderBar((Rectangle){ 640, 40, 120, 20}, "Segments", TextFormat("%.0f", segments), &segments, 6.0f, 60.f);
91+
GuiCheckBox((Rectangle){ 640, 70, 20, 20 }, "Outline", &outline);
92+
//------------------------------------------------------------------------------
93+
94+
DrawFPS(10, 10);
95+
96+
EndDrawing();
97+
//----------------------------------------------------------------------------------
98+
}
99+
100+
// De-Initialization
101+
//--------------------------------------------------------------------------------------
102+
CloseWindow(); // Close window and OpenGL context
103+
//--------------------------------------------------------------------------------------
104+
105+
return 0;
106+
}
12.4 KB
Loading

0 commit comments

Comments
 (0)