diff --git a/examples/Makefile b/examples/Makefile index a36b9e447..d5fb730ec 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -564,6 +564,7 @@ SHAPES = \ shapes/shapes_rounded_rectangle_drawing \ shapes/shapes_splines_drawing \ shapes/shapes_top_down_lights \ + shapes/shapes_triangle_strip \ shapes/shapes_vector_angle TEXTURES = \ diff --git a/examples/Makefile.Web b/examples/Makefile.Web index 2d3018abf..c053528b6 100644 --- a/examples/Makefile.Web +++ b/examples/Makefile.Web @@ -564,6 +564,7 @@ SHAPES = \ shapes/shapes_rounded_rectangle_drawing \ shapes/shapes_splines_drawing \ shapes/shapes_top_down_lights \ + shapes/shapes_triangle_strip \ shapes/shapes_vector_angle TEXTURES = \ @@ -884,6 +885,9 @@ shapes/shapes_splines_drawing: shapes/shapes_splines_drawing.c shapes/shapes_top_down_lights: shapes/shapes_top_down_lights.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) +shapes/shapes_triangle_strip: shapes/shapes_triangle_strip.c + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) + shapes/shapes_vector_angle: shapes/shapes_vector_angle.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) diff --git a/examples/README.md b/examples/README.md index d852e7105..9f6784e65 100644 --- a/examples/README.md +++ b/examples/README.md @@ -17,7 +17,7 @@ You may find it easier to use than other toolchains, especially when it comes to - `zig build [module]` to compile all examples for a module (e.g. `zig build core`) - `zig build [example]` to compile _and run_ a particular example (e.g. `zig build core_basic_window`) -## EXAMPLES COLLECTION [TOTAL: 173] +## EXAMPLES COLLECTION [TOTAL: 174] ### category: core [40] @@ -66,7 +66,7 @@ Examples using raylib[core](../src/rcore.c) platform functionality like window c | [core_undo_redo](core/core_undo_redo.c) | core_undo_redo | ⭐⭐⭐☆ | 5.5 | 5.6 | [Ramon Santamaria](https://github.com/raysan5) | | [core_input_actions](core/core_input_actions.c) | core_input_actions | ⭐⭐☆☆ | 5.5 | 5.6 | [Jett](https://github.com/JettMonstersGoBoom) | -### category: shapes [24] +### category: shapes [25] Examples using raylib shapes drawing functionality, provided by raylib [shapes](../src/rshapes.c) module. @@ -95,6 +95,7 @@ Examples using raylib shapes drawing functionality, provided by raylib [shapes]( | [shapes_digital_clock](shapes/shapes_digital_clock.c) | shapes_digital_clock | ⭐⭐⭐⭐️ | 5.5 | 5.6 | [Hamza RAHAL](https://github.com/hmz-rhl) | | [shapes_double_pendulum](shapes/shapes_double_pendulum.c) | shapes_double_pendulum | ⭐⭐☆☆ | 5.5 | 5.5 | [JoeCheong](https://github.com/Joecheong2006) | | [shapes_dashed_line](shapes/shapes_dashed_line.c) | shapes_dashed_line | ⭐☆☆☆ | 5.5 | 5.5 | [Luís Almeida](https://github.com/luis605) | +| [shapes_triangle_strip](shapes/shapes_triangle_strip.c) | shapes_triangle_strip | ⭐⭐☆☆ | 5.6-dev | 5.6-dev | [Jopestpe](https://github.com/jopestpe) | | [shapes_vector_angle](shapes/shapes_vector_angle.c) | shapes_vector_angle | ⭐⭐☆☆ | 1.0 | 5.0 | [Ramon Santamaria](https://github.com/raysan5) | ### category: textures [26] diff --git a/examples/examples_list.txt b/examples/examples_list.txt index 5a0c679a4..879f5707b 100644 --- a/examples/examples_list.txt +++ b/examples/examples_list.txt @@ -70,6 +70,7 @@ shapes;shapes_splines_drawing;★★★☆;5.0;5.0;2023;2025;"Ramon Santamaria"; shapes;shapes_digital_clock;★★★★;5.5;5.6;2025;2025;"Hamza RAHAL";@hmz-rhl shapes;shapes_double_pendulum;★★☆☆;5.5;5.5;2025;2025;"JoeCheong";@Joecheong2006 shapes;shapes_dashed_line;★☆☆☆;5.5;5.5;2025;2025;"Luís Almeida";@luis605 +shapes;shapes_triangle_strip;★★☆☆;5.6-dev;5.6-dev;2025;2025;"Jopestpe";@jopestpe shapes;shapes_vector_angle;★★☆☆;1.0;5.0;2023;2025;"Ramon Santamaria";@raysan5 textures;textures_logo_raylib;★☆☆☆;1.0;1.0;2014;2025;"Ramon Santamaria";@raysan5 textures;textures_srcrec_dstrec;★★★☆;1.3;1.3;2015;2025;"Ramon Santamaria";@raysan5 diff --git a/examples/shapes/shapes_triangle_strip.c b/examples/shapes/shapes_triangle_strip.c new file mode 100644 index 000000000..f27a5bf44 --- /dev/null +++ b/examples/shapes/shapes_triangle_strip.c @@ -0,0 +1,115 @@ +/******************************************************************************************* +* +* raylib [shapes] example - triangle strip +* +* Example complexity rating: [★★☆☆] 2/4 +* +* Example originally created with raylib 5.6-dev, last time updated with raylib 5.6-dev +* +* Example contributed by Jopestpe (@jopestpe) +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2018-2025 Jopestpe (@jopestpe) +* +********************************************************************************************/ + +#include "raylib.h" +#include + +#define RAYGUI_IMPLEMENTATION +#include "raygui.h" // Required for GUI controls + +//---------------------------------------------------------------------------------- +// Module Functions Declaration +//---------------------------------------------------------------------------------- +static Vector2 CalculatePoint(Vector2 start, float angle, float length); +static void DrawTriangleCustom(Vector2 point1, Vector2 point2, Vector2 point3, float angle, bool outline); + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [shapes] example - triangle strip"); + + Vector2 points[120] = { 0 }; + Vector2 center = { (screenWidth/2.0f) - 125.f, screenHeight/2.0f }; + float segments = 6.0f; + float insideRadius = 100.0f; + float outsideRadius = 150.0f; + bool outline = true; + + 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 + //---------------------------------------------------------------------------------- + + int pointCount = (int)(segments); + float angleStep = (360.0f/pointCount)*DEG2RAD; + + for (int i = 0, i2 = 0; i < pointCount; i++, i2 += 2) + { + points[i2] = CalculatePoint(center, i*angleStep, insideRadius); + points[i2 + 1] = CalculatePoint(center, i*angleStep + angleStep/2.0f, outsideRadius); + } + + points[pointCount*2] = points[0]; + points[pointCount*2 + 1] = points[1]; + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + for (int i = 0, i2 = 0; i < pointCount; i++, i2 += 2) + { + DrawTriangleCustom(points[i2], points[i2 + 1], points[i2 + 2], i*angleStep, outline); + DrawTriangleCustom(points[i2 + 2], points[i2 + 1], points[i2 + 3], i*angleStep + (angleStep/2), outline); + } + + DrawLine(580, 0, 580, GetScreenHeight(), (Color){ 218, 218, 218, 255 }); + DrawRectangle(580, 0, GetScreenWidth(), GetScreenHeight(), (Color){ 232, 232, 232, 255 }); + + // Draw GUI controls + //------------------------------------------------------------------------------ + GuiSliderBar((Rectangle){ 640, 40, 120, 20}, "Segments", TextFormat("%.0f", segments), &segments, 6.0f, 60.f); + GuiCheckBox((Rectangle){ 640, 70, 20, 20 }, "Outline", &outline); + //------------------------------------------------------------------------------ + + DrawFPS(10, 10); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +static Vector2 CalculatePoint(Vector2 start, float angle, float radius) +{ + return (Vector2){ start.x + cosf(angle)*radius, start.y + sinf(angle)*radius }; +} + +static void DrawTriangleCustom(Vector2 point1, Vector2 point2, Vector2 point3, float angle, bool outline) +{ + Color color = ColorFromHSV(angle*RAD2DEG, 1.0f, 1.0f); + DrawTriangle(point3, point2, point1, color); + if (outline) DrawTriangleLines(point1, point2, point3, BLACK); +} \ No newline at end of file diff --git a/examples/shapes/shapes_triangle_strip.png b/examples/shapes/shapes_triangle_strip.png new file mode 100644 index 000000000..c291a0849 Binary files /dev/null and b/examples/shapes/shapes_triangle_strip.png differ