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
+ }
0 commit comments