Skip to content

Commit 9bf7699

Browse files
authored
[examples] Added shapes_kaleidoscope (#5233)
* ADDED: example: `shapes_kaleidoscope` * Add line reflection * Updated with `rexm update` * Follow raylib's conventions
1 parent 4cfae99 commit 9bf7699

File tree

9 files changed

+764
-12
lines changed

9 files changed

+764
-12
lines changed

examples/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ SHAPES = \
554554
shapes/shapes_easings_box \
555555
shapes/shapes_easings_rectangles \
556556
shapes/shapes_following_eyes \
557+
shapes/shapes_kaleidoscope \
557558
shapes/shapes_lines_bezier \
558559
shapes/shapes_logo_raylib \
559560
shapes/shapes_logo_raylib_anim \

examples/Makefile.Web

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ SHAPES = \
554554
shapes/shapes_easings_box \
555555
shapes/shapes_easings_rectangles \
556556
shapes/shapes_following_eyes \
557+
shapes/shapes_kaleidoscope \
557558
shapes/shapes_lines_bezier \
558559
shapes/shapes_logo_raylib \
559560
shapes/shapes_logo_raylib_anim \
@@ -855,6 +856,9 @@ shapes/shapes_easings_rectangles: shapes/shapes_easings_rectangles.c
855856
shapes/shapes_following_eyes: shapes/shapes_following_eyes.c
856857
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
857858

859+
shapes/shapes_kaleidoscope: shapes/shapes_kaleidoscope.c
860+
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
861+
858862
shapes/shapes_lines_bezier: shapes/shapes_lines_bezier.c
859863
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
860864

examples/README.md

Lines changed: 4 additions & 3 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: 174]
20+
## EXAMPLES COLLECTION [TOTAL: 175]
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 [25]
69+
### category: shapes [26]
7070

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

@@ -84,8 +84,8 @@ Examples using raylib shapes drawing functionality, provided by raylib [shapes](
8484
| [shapes_following_eyes](shapes/shapes_following_eyes.c) | <img src="shapes/shapes_following_eyes.png" alt="shapes_following_eyes" width="80"> | ⭐⭐☆☆ | 2.5 | 2.5 | [Ramon Santamaria](https://github.com/raysan5) |
8585
| [shapes_easings_ball](shapes/shapes_easings_ball.c) | <img src="shapes/shapes_easings_ball.png" alt="shapes_easings_ball" width="80"> | ⭐⭐☆☆ | 2.5 | 2.5 | [Ramon Santamaria](https://github.com/raysan5) |
8686
| [shapes_easings_box](shapes/shapes_easings_box.c) | <img src="shapes/shapes_easings_box.png" alt="shapes_easings_box" width="80"> | ⭐⭐☆☆ | 2.5 | 2.5 | [Ramon Santamaria](https://github.com/raysan5) |
87-
| [shapes_recursive_tree](shapes/shapes_recursive_tree.c) | <img src="shapes/shapes_recursive_tree.png" alt="shapes_recursive_tree" width="80"> | ⭐⭐⭐☆ | 5.6-dev | 5.6-dev| [Jopestpe](https://github.com/jopestpe) |
8887
| [shapes_easings_rectangles](shapes/shapes_easings_rectangles.c) | <img src="shapes/shapes_easings_rectangles.png" alt="shapes_easings_rectangles" width="80"> | ⭐⭐⭐☆ | 2.0 | 2.5 | [Ramon Santamaria](https://github.com/raysan5) |
88+
| [shapes_recursive_tree](shapes/shapes_recursive_tree.c) | <img src="shapes/shapes_recursive_tree.png" alt="shapes_recursive_tree" width="80"> | ⭐⭐⭐☆ | 5.6-dev | 5.6-dev | [Jopestpe](https://github.com/jopestpe) |
8989
| [shapes_ring_drawing](shapes/shapes_ring_drawing.c) | <img src="shapes/shapes_ring_drawing.png" alt="shapes_ring_drawing" width="80"> | ⭐⭐⭐☆ | 2.5 | 2.5 | [Vlad Adrian](https://github.com/demizdor) |
9090
| [shapes_circle_sector_drawing](shapes/shapes_circle_sector_drawing.c) | <img src="shapes/shapes_circle_sector_drawing.png" alt="shapes_circle_sector_drawing" width="80"> | ⭐⭐⭐☆ | 2.5 | 2.5 | [Vlad Adrian](https://github.com/demizdor) |
9191
| [shapes_rounded_rectangle_drawing](shapes/shapes_rounded_rectangle_drawing.c) | <img src="shapes/shapes_rounded_rectangle_drawing.png" alt="shapes_rounded_rectangle_drawing" width="80"> | ⭐⭐⭐☆ | 2.5 | 2.5 | [Vlad Adrian](https://github.com/demizdor) |
@@ -97,6 +97,7 @@ Examples using raylib shapes drawing functionality, provided by raylib [shapes](
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) |
9898
| [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) |
9999
| [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) |
100+
| [shapes_kaleidoscope](shapes/shapes_kaleidoscope.c) | <img src="shapes/shapes_kaleidoscope.png" alt="shapes_kaleidoscope" width="80"> | ⭐⭐☆☆ | 5.5 | 5.6 | [Hugo ARNAL](https://github.com/hugoarnal) |
100101

101102
### category: textures [26]
102103

examples/examples_list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,4 @@ others;easings_testbed;★★★☆;2.5;3.0;2019;2025;"Juan Miguel López";@flas
181181
others;raylib_opengl_interop;★★★★;3.8;4.0;2021;2025;"Stephan Soller";@arkanis
182182
others;embedded_files_loading;★★☆☆;3.0;3.5;2020;2025;"Kristian Holmgren";@defutura
183183
others;web_basic_window;★☆☆☆;5.6-dev;5.6-dev;2014;2025;"Ramon Santamaria";@raysan5
184+
shapes;shapes_kaleidoscope;★★☆☆;5.5;5.6;2025;2025;"Hugo ARNAL";@hugoarnal
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*******************************************************************************************
2+
*
3+
* raylib [shapes] example - kaleidoscope
4+
*
5+
* Example complexity rating: [★★☆☆] 2/4
6+
*
7+
* Example originally created with raylib 5.5, last time updated with raylib 5.6
8+
*
9+
* Example contributed by Hugo ARNAL (@hugoarnal) 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 Hugo ARNAL (@hugoarnal)
15+
*
16+
********************************************************************************************/
17+
18+
#include "raylib.h"
19+
#include "raymath.h"
20+
21+
//------------------------------------------------------------------------------------
22+
// Program main entry point
23+
//------------------------------------------------------------------------------------
24+
int main(void)
25+
{
26+
// Initialization
27+
//--------------------------------------------------------------------------------------
28+
const int screenWidth = 800;
29+
const int screenHeight = 450;
30+
31+
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - kaleidoscope");
32+
33+
int symmetry = 6;
34+
float angle = 360.0f/(float)symmetry;
35+
float thickness = 3.0f;
36+
Vector2 prevMousePos = { 0 };
37+
38+
SetTargetFPS(60);
39+
ClearBackground(BLACK);
40+
41+
Vector2 offset = { (float)screenWidth/2.0f, (float)screenHeight/2.0f };
42+
Camera2D camera = { 0 };
43+
camera.target = (Vector2){ 0 };
44+
camera.offset = offset;
45+
camera.rotation = 0.0f;
46+
camera.zoom = 1.0f;
47+
48+
Vector2 scaleVector = { 1.0f, -1.0f };
49+
//--------------------------------------------------------------------------------------
50+
51+
// Main game loop
52+
while (!WindowShouldClose()) // Detect window close button or ESC key
53+
{
54+
// Update
55+
//----------------------------------------------------------------------------------
56+
Vector2 mousePos = GetMousePosition();
57+
Vector2 lineStart = Vector2Subtract(mousePos, offset);
58+
Vector2 lineEnd = Vector2Subtract(prevMousePos, offset);
59+
//----------------------------------------------------------------------------------
60+
61+
// Draw
62+
//----------------------------------------------------------------------------------
63+
BeginDrawing();
64+
BeginMode2D(camera);
65+
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) {
66+
for (int i = 0; i < symmetry; i++) {
67+
lineStart = Vector2Rotate(lineStart, angle*DEG2RAD);
68+
lineEnd = Vector2Rotate(lineEnd, angle*DEG2RAD);
69+
70+
DrawLineEx(lineStart, lineEnd, thickness, WHITE);
71+
72+
Vector2 reflectLineStart = Vector2Multiply(lineStart, scaleVector);
73+
Vector2 reflectLineEnd = Vector2Multiply(lineEnd, scaleVector);
74+
75+
DrawLineEx(reflectLineStart, reflectLineEnd, thickness, WHITE);
76+
}
77+
}
78+
79+
prevMousePos = mousePos;
80+
EndMode2D();
81+
EndDrawing();
82+
//----------------------------------------------------------------------------------
83+
}
84+
85+
// De-Initialization
86+
//--------------------------------------------------------------------------------------
87+
88+
CloseWindow(); // Close window and OpenGL context
89+
//--------------------------------------------------------------------------------------
90+
91+
return 0;
92+
}
38.4 KB
Loading

0 commit comments

Comments
 (0)