diff options
| author | Ray <[email protected]> | 2017-04-04 01:54:49 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2017-04-04 01:54:49 +0200 |
| commit | dd4dd0e87d7d215a21b8fc129cbe1adc4b96afe8 (patch) | |
| tree | 724f11991d301fc8bfd01ccd13321f66d8969329 /examples/shapes | |
| parent | 5a230659ef39c6eb3bdb5412ca6e1bfc9eeda98e (diff) | |
| download | raylib-dd4dd0e87d7d215a21b8fc129cbe1adc4b96afe8.tar.gz raylib-dd4dd0e87d7d215a21b8fc129cbe1adc4b96afe8.zip | |
Reorganize examples folder
Diffstat (limited to 'examples/shapes')
| -rw-r--r-- | examples/shapes/shapes_basic_shapes.c | 72 | ||||
| -rw-r--r-- | examples/shapes/shapes_basic_shapes.png | bin | 0 -> 30382 bytes | |||
| -rw-r--r-- | examples/shapes/shapes_colors_palette.c | 97 | ||||
| -rw-r--r-- | examples/shapes/shapes_colors_palette.png | bin | 0 -> 5230 bytes | |||
| -rw-r--r-- | examples/shapes/shapes_logo_raylib.c | 56 | ||||
| -rw-r--r-- | examples/shapes/shapes_logo_raylib.png | bin | 0 -> 12676 bytes | |||
| -rw-r--r-- | examples/shapes/shapes_logo_raylib_anim.c | 160 | ||||
| -rw-r--r-- | examples/shapes/shapes_logo_raylib_anim.png | bin | 0 -> 4787 bytes |
8 files changed, 385 insertions, 0 deletions
diff --git a/examples/shapes/shapes_basic_shapes.c b/examples/shapes/shapes_basic_shapes.c new file mode 100644 index 00000000..6b2719fc --- /dev/null +++ b/examples/shapes/shapes_basic_shapes.c @@ -0,0 +1,72 @@ +/******************************************************************************************* +* +* raylib [shapes] example - Draw basic shapes 2d (rectangle, circle, line...) +* +* This example has been created using raylib 1.0 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2014 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing"); + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("some basic shapes available on raylib", 20, 20, 20, DARKGRAY); + + DrawLine(18, 42, screenWidth - 18, 42, BLACK); + + DrawCircle(screenWidth/4, 120, 35, DARKBLUE); + DrawCircleGradient(screenWidth/4, 220, 60, GREEN, SKYBLUE); + DrawCircleLines(screenWidth/4, 340, 80, DARKBLUE); + + DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED); + DrawRectangleGradient(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD); + DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE); + + DrawTriangle((Vector2){screenWidth/4*3, 80}, + (Vector2){screenWidth/4*3 - 60, 150}, + (Vector2){screenWidth/4*3 + 60, 150}, VIOLET); + + DrawTriangleLines((Vector2){screenWidth/4*3, 160}, + (Vector2){screenWidth/4*3 - 20, 230}, + (Vector2){screenWidth/4*3 + 20, 230}, DARKBLUE); + + DrawPoly((Vector2){screenWidth/4*3, 320}, 6, 80, 0, BROWN); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/shapes/shapes_basic_shapes.png b/examples/shapes/shapes_basic_shapes.png Binary files differnew file mode 100644 index 00000000..a7d4a991 --- /dev/null +++ b/examples/shapes/shapes_basic_shapes.png diff --git a/examples/shapes/shapes_colors_palette.c b/examples/shapes/shapes_colors_palette.c new file mode 100644 index 00000000..dcab862e --- /dev/null +++ b/examples/shapes/shapes_colors_palette.c @@ -0,0 +1,97 @@ +/******************************************************************************************* +* +* raylib [shapes] example - Draw raylib custom color palette +* +* This example has been created using raylib 1.0 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2014 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib color palette"); + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("raylib color palette", 28, 42, 20, BLACK); + + DrawRectangle(26, 80, 100, 100, DARKGRAY); + DrawRectangle(26, 188, 100, 100, GRAY); + DrawRectangle(26, 296, 100, 100, LIGHTGRAY); + DrawRectangle(134, 80, 100, 100, MAROON); + DrawRectangle(134, 188, 100, 100, RED); + DrawRectangle(134, 296, 100, 100, PINK); + DrawRectangle(242, 80, 100, 100, ORANGE); + DrawRectangle(242, 188, 100, 100, GOLD); + DrawRectangle(242, 296, 100, 100, YELLOW); + DrawRectangle(350, 80, 100, 100, DARKGREEN); + DrawRectangle(350, 188, 100, 100, LIME); + DrawRectangle(350, 296, 100, 100, GREEN); + DrawRectangle(458, 80, 100, 100, DARKBLUE); + DrawRectangle(458, 188, 100, 100, BLUE); + DrawRectangle(458, 296, 100, 100, SKYBLUE); + DrawRectangle(566, 80, 100, 100, DARKPURPLE); + DrawRectangle(566, 188, 100, 100, VIOLET); + DrawRectangle(566, 296, 100, 100, PURPLE); + DrawRectangle(674, 80, 100, 100, DARKBROWN); + DrawRectangle(674, 188, 100, 100, BROWN); + DrawRectangle(674, 296, 100, 100, BEIGE); + + + DrawText("DARKGRAY", 65, 166, 10, BLACK); + DrawText("GRAY", 93, 274, 10, BLACK); + DrawText("LIGHTGRAY", 61, 382, 10, BLACK); + DrawText("MAROON", 186, 166, 10, BLACK); + DrawText("RED", 208, 274, 10, BLACK); + DrawText("PINK", 204, 382, 10, BLACK); + DrawText("ORANGE", 295, 166, 10, BLACK); + DrawText("GOLD", 310, 274, 10, BLACK); + DrawText("YELLOW", 300, 382, 10, BLACK); + DrawText("DARKGREEN", 382, 166, 10, BLACK); + DrawText("LIME", 420, 274, 10, BLACK); + DrawText("GREEN", 410, 382, 10, BLACK); + DrawText("DARKBLUE", 498, 166, 10, BLACK); + DrawText("BLUE", 526, 274, 10, BLACK); + DrawText("SKYBLUE", 505, 382, 10, BLACK); + DrawText("DARKPURPLE", 592, 166, 10, BLACK); + DrawText("VIOLET", 621, 274, 10, BLACK); + DrawText("PURPLE", 620, 382, 10, BLACK); + DrawText("DARKBROWN", 705, 166, 10, BLACK); + DrawText("BROWN", 733, 274, 10, BLACK); + DrawText("BEIGE", 737, 382, 10, BLACK); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/shapes/shapes_colors_palette.png b/examples/shapes/shapes_colors_palette.png Binary files differnew file mode 100644 index 00000000..dd3cf4a5 --- /dev/null +++ b/examples/shapes/shapes_colors_palette.png diff --git a/examples/shapes/shapes_logo_raylib.c b/examples/shapes/shapes_logo_raylib.c new file mode 100644 index 00000000..be94988c --- /dev/null +++ b/examples/shapes/shapes_logo_raylib.c @@ -0,0 +1,56 @@ +/******************************************************************************************* +* +* raylib [shapes] example - Draw raylib logo using basic shapes +* +* This example has been created using raylib 1.0 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2014 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo using shapes"); + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawRectangle(screenWidth/2 - 128, screenHeight/2 - 128, 256, 256, BLACK); + DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, RAYWHITE); + DrawText("raylib", screenWidth/2 - 44, screenHeight/2 + 48, 50, BLACK); + + DrawText("this is NOT a texture!", 350, 370, 10, GRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/shapes/shapes_logo_raylib.png b/examples/shapes/shapes_logo_raylib.png Binary files differnew file mode 100644 index 00000000..6b385f7c --- /dev/null +++ b/examples/shapes/shapes_logo_raylib.png diff --git a/examples/shapes/shapes_logo_raylib_anim.c b/examples/shapes/shapes_logo_raylib_anim.c new file mode 100644 index 00000000..c6d3796e --- /dev/null +++ b/examples/shapes/shapes_logo_raylib_anim.c @@ -0,0 +1,160 @@ +/******************************************************************************************* +* +* raylib [shapes] example - raylib logo animation +* +* This example has been created using raylib 1.4 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2014 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo animation"); + + int logoPositionX = screenWidth/2 - 128; + int logoPositionY = screenHeight/2 - 128; + + int framesCounter = 0; + int lettersCount = 0; + + int topSideRecWidth = 16; + int leftSideRecHeight = 16; + + int bottomSideRecWidth = 16; + int rightSideRecHeight = 16; + + int state = 0; // Tracking animation states (State Machine) + float alpha = 1.0f; // Useful for fading + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (state == 0) // State 0: Small box blinking + { + framesCounter++; + + if (framesCounter == 120) + { + state = 1; + framesCounter = 0; // Reset counter... will be used later... + } + } + else if (state == 1) // State 1: Top and left bars growing + { + topSideRecWidth += 4; + leftSideRecHeight += 4; + + if (topSideRecWidth == 256) state = 2; + } + else if (state == 2) // State 2: Bottom and right bars growing + { + bottomSideRecWidth += 4; + rightSideRecHeight += 4; + + if (bottomSideRecWidth == 256) state = 3; + } + else if (state == 3) // State 3: Letters appearing (one by one) + { + framesCounter++; + + if (framesCounter/12) // Every 12 frames, one more letter! + { + lettersCount++; + framesCounter = 0; + } + + if (lettersCount >= 10) // When all letters have appeared, just fade out everything + { + alpha -= 0.02f; + + if (alpha <= 0.0f) + { + alpha = 0.0f; + state = 4; + } + } + } + else if (state == 4) // State 4: Reset and Replay + { + if (IsKeyPressed('R')) + { + framesCounter = 0; + lettersCount = 0; + + topSideRecWidth = 16; + leftSideRecHeight = 16; + + bottomSideRecWidth = 16; + rightSideRecHeight = 16; + + alpha = 1.0f; + state = 0; // Return to State 0 + } + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + if (state == 0) + { + if ((framesCounter/15)%2) DrawRectangle(logoPositionX, logoPositionY, 16, 16, BLACK); + } + else if (state == 1) + { + DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK); + DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK); + } + else if (state == 2) + { + DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK); + DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK); + + DrawRectangle(logoPositionX + 240, logoPositionY, 16, rightSideRecHeight, BLACK); + DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, BLACK); + } + else if (state == 3) + { + DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, Fade(BLACK, alpha)); + DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, Fade(BLACK, alpha)); + + DrawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha)); + DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha)); + + DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, Fade(RAYWHITE, alpha)); + + DrawText(SubText("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha)); + } + else if (state == 4) + { + DrawText("[R] REPLAY", 340, 200, 20, GRAY); + } + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/shapes/shapes_logo_raylib_anim.png b/examples/shapes/shapes_logo_raylib_anim.png Binary files differnew file mode 100644 index 00000000..103dfc4a --- /dev/null +++ b/examples/shapes/shapes_logo_raylib_anim.png |
