-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[examples] Added shapes_recursive_tree
#5229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8b90958
ADDED: example: shapes_recursive_tree
Jopestpe bbede86
[examples] Added shapes_recursive_tree
Jopestpe 74f4ba7
[examples] shapes_recursive_tree: adjustments
Jopestpe f5328bf
Reduced tree depth from 12 to 10
Jopestpe 568de56
new shapes_recursive_tree.png
Jopestpe e1ce5ab
follow the conventions
Jopestpe 8b31937
follow the conventions 2
Jopestpe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /******************************************************************************************* | ||
| * | ||
| * raylib [shapes] example - shapes recursive tree | ||
| * | ||
| * Example complexity rating: [★★★☆] 3/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 | ||
|
|
||
| float theta; | ||
| float thick = 1.0f; | ||
| float branchDecay = 0.66f; | ||
| bool bezier = false; | ||
|
|
||
| void Branch(Vector2 start, float length, float angle) { | ||
| length *= branchDecay; | ||
|
|
||
| if (length > 2) { | ||
| Vector2 end = { | ||
| start.x + length * sinf(angle), | ||
| start.y - length * cosf(angle) | ||
| }; | ||
|
|
||
| if(!bezier) DrawLineEx(start, end, thick, RED); | ||
| else DrawLineBezier(start, end, thick, RED); | ||
|
|
||
| Branch(end, length, angle + theta); | ||
| Branch(end, length, angle - theta); | ||
| } | ||
| } | ||
|
|
||
| //------------------------------------------------------------------------------------ | ||
| // Program main entry point | ||
| //------------------------------------------------------------------------------------ | ||
| int main(void) | ||
| { | ||
| // Initialization | ||
| //-------------------------------------------------------------------------------------- | ||
| const int screenWidth = 800; | ||
| const int screenHeight = 450; | ||
|
|
||
| InitWindow(screenWidth, screenHeight, "raylib [shapes] example - shapes recursive tree"); | ||
|
|
||
| Vector2 start = { (screenWidth / 2.0f) - 125, screenHeight }; | ||
|
||
| Vector2 end = { (screenWidth / 2.0f) - 125, screenHeight - 120.0f }; | ||
| float angle = 0.0f; | ||
|
|
||
| SetTargetFPS(60); // Set our game to run at 60 frames-per-second | ||
| //-------------------------------------------------------------------------------------- | ||
|
|
||
| // Main game loop | ||
| while (!WindowShouldClose()) // Detect window close button or ESC key | ||
| { | ||
| float a = (angle / screenWidth) * 90.0f; | ||
| theta = a * (PI / 180.0f); | ||
|
|
||
| // Draw | ||
| //---------------------------------------------------------------------------------- | ||
| BeginDrawing(); | ||
|
|
||
| ClearBackground(RAYWHITE); | ||
|
|
||
| DrawLine(560, 0, 560, GetScreenHeight(), Fade(LIGHTGRAY, 0.6f)); | ||
| DrawRectangle(560, 0, GetScreenWidth() - 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.3f)); | ||
|
|
||
| // Draw GUI controls | ||
| //------------------------------------------------------------------------------ | ||
| GuiSliderBar((Rectangle){ 640, 40, 120, 20}, "Angle", TextFormat("%.2f", angle), &angle, 0, 1600); | ||
| GuiSliderBar((Rectangle){ 640, 70, 120, 20}, "Thick", TextFormat("%.2f", thick), &thick, 1, 8); | ||
| GuiSliderBar((Rectangle){ 640, 100, 120, 20}, "Branch Decay", TextFormat("%.2f", branchDecay), &branchDecay, 0.1f, 0.78f); | ||
| GuiCheckBox((Rectangle){ 640, 130, 20, 20 }, "Bezier", &bezier); | ||
| //------------------------------------------------------------------------------ | ||
|
|
||
| DrawLineEx(start, end, thick, RED); | ||
| Branch(end, 120.0f, 0.0f); | ||
|
|
||
| DrawFPS(10, 10); | ||
|
|
||
| EndDrawing(); | ||
| //---------------------------------------------------------------------------------- | ||
| } | ||
|
|
||
| // De-Initialization | ||
| //-------------------------------------------------------------------------------------- | ||
| CloseWindow(); // Close window and OpenGL context | ||
| //-------------------------------------------------------------------------------------- | ||
|
|
||
| return 0; | ||
| } | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.