浏览代码

[examples] Add shapes_triangle_strip

pull/5240/head
Jopestpe 1 天前
committed by GitHub
父节点
当前提交
68baddb41d
找不到此签名对应的密钥 GPG 密钥 ID: B5690EEEBB952194
共有 6 个文件被更改,包括 124 次插入2 次删除
  1. +1
    -0
      examples/Makefile
  2. +4
    -0
      examples/Makefile.Web
  3. +3
    -2
      examples/README.md
  4. +1
    -0
      examples/examples_list.txt
  5. +115
    -0
      examples/shapes/shapes_triangle_strip.c
  6. 二进制
      examples/shapes/shapes_triangle_strip.png

+ 1
- 0
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 = \

+ 4
- 0
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)

+ 3
- 2
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) | <img src="core/core_undo_redo.png" alt="core_undo_redo" width="80"> | ⭐⭐⭐☆ | 5.5 | 5.6 | [Ramon Santamaria](https://github.com/raysan5) |
| [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) |
### 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) | <img src="shapes/shapes_digital_clock.png" alt="shapes_digital_clock" width="80"> | ⭐⭐⭐⭐️ | 5.5 | 5.6 | [Hamza RAHAL](https://github.com/hmz-rhl) |
| [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) |
| [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) |
| [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) |
| [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) |
### category: textures [26]

+ 1
- 0
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

+ 115
- 0
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 <math.h>
#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);
}

二进制
examples/shapes/shapes_triangle_strip.png 查看文件

之前 之后
宽度: 800  |  高度: 450  |  大小: 12 KiB

正在加载...
取消
保存