raylib/ports/shapes/shapes_basic_shapes
Licence This example has its own licence, rather than Odin's: raylib/ports/LICENSE
These are ported Raylib examples, and as such, they are subject to Raylib's license.
Copyright (c) 2013-2024 Ramon Santamaria (@raysan5)
The rest of the licence
This software is provided "as-is", without any express or implied warranty. In no event
will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you
wrote the original software. If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented
as being the original software.
3. This notice may not be removed or altered from any source distribution.
Code
shapes_basic_shapes.odin ¶86 linesSource
1package raylib_examples
2
3/*******************************************************************************************
4*
5* raylib [shapes] example - Draw basic shapes 2d (rectangle, circle, line...)
6*
7* This example was originally created in C with raylib 1.0, and updated with raylib 4.2
8* before being translated to Odin.
9*
10* The original example in C can be found on raylib.com at:
11*
12* https://www.raylib.com/examples/shapes/loader.html?name=shapes_basic_shapes
13*
14* raylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
15* BSD-like license that allows static linking with closed source software. The license
16* can be found in its entirety as part of the standard Odin distribution at:
17*
18* /vendor/raylib/LICENSE
19*
20* or online at:
21*
22* https://www.raylib.com/license.html
23*
24* This example is licensed under an unmodified zlib/libpng license, which is an
25* OSI-certified, BSD-like license that allows static linking with closed source software.
26*
27* Copyright (c) 2014-2023 Ramon Santamaria (@raysan5)
28* Copyright (c) 2023 Benjamin G. Thompson (@bg-thompson)
29*
30********************************************************************************************/
31
32import rl "vendor:raylib"
33
34SCREEN_WIDTH :: 800
35SCREEN_HEIGHT :: 450
36
37main :: proc() {
38 rl.InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [shapes] example - basic shapes drawing")
39 defer rl.CloseWindow() // Close window and OpenGL context when leaving main.
40
41 rotation: f32 = 0
42 rl.SetTargetFPS(60) // Set frames per second.
43
44 // The primary loop.
45 for !rl.WindowShouldClose() { // Detect window close button or ESC key press.
46 rotation += 0.2
47
48 // Start drawing.
49 rl.BeginDrawing()
50
51 // Draw background and text.
52 rl.ClearBackground(rl.RAYWHITE)
53 rl.DrawText("some basic shapes available on raylib", 20, 20, 20, rl.DARKGRAY)
54
55 // Draw circle shapes and lines.
56 rl.DrawCircle(SCREEN_WIDTH / 5, 120, 35, rl.DARKBLUE)
57 rl.DrawCircleGradient({SCREEN_WIDTH / 5, 220}, 60, rl.GREEN, rl.SKYBLUE)
58 rl.DrawCircleLines(SCREEN_WIDTH / 5, 340, 80, rl.DARKBLUE)
59
60 // Draw rectangle shapes and lines.
61 rl.DrawRectangle(SCREEN_WIDTH / 4 * 2 - 60, 100, 120, 60, rl.RED)
62 rl.DrawRectangleGradientH(SCREEN_WIDTH /4 * 2 - 90, 170, 180, 130, rl.MAROON, rl.GOLD)
63 rl.DrawRectangleLines(SCREEN_WIDTH / 4 * 2 - 40, 320, 80, 60, rl.ORANGE) // NOTE: Uses QUADS internally, not lines.
64
65 // Draw triangle shapes and lines.
66 rl.DrawTriangle({SCREEN_WIDTH / 4 * 3, 80},
67 {SCREEN_WIDTH / 4 * 3 - 60, 150},
68 {SCREEN_WIDTH / 4 * 3 + 60, 150},
69 rl.VIOLET)
70
71 rl.DrawTriangleLines({SCREEN_WIDTH / 4 * 3, 160},
72 {SCREEN_WIDTH / 4 * 3 - 20, 230},
73 {SCREEN_WIDTH / 4 * 3 + 20, 230},
74 rl.DARKBLUE)
75
76 // Draw polygon shapes and lines.
77 rl.DrawPoly({ SCREEN_WIDTH / 4 * 3, 330}, 6, 80, rotation, rl.BROWN)
78 rl.DrawPolyLines({SCREEN_WIDTH / 4 * 3, 330}, 6, 90, rotation, rl.BROWN)
79 rl.DrawPolyLinesEx({SCREEN_WIDTH / 4 * 3, 330}, 6, 85, rotation, 6, rl.BEIGE)
80
81 // NOTE: We draw all LINES based shapes together to optimize internal drawing,
82 // this way, all LINES are rendered in a single draw pass.
83 rl.DrawLine(18, 42, SCREEN_WIDTH - 18, 42, rl.BLACK)
84 rl.EndDrawing()
85 }
86}
Declarations Used 33
- vendor:raylib BeginDrawing · BEIGE · BLACK · BROWN · ClearBackground · CloseWindow · DARKBLUE · DARKGRAY · DrawCircle · DrawCircleGradient · DrawCircleLines · DrawLine · DrawPoly · DrawPolyLines · DrawPolyLinesEx · DrawRectangle · DrawRectangleGradientH · DrawRectangleLines · DrawText · DrawTriangle · DrawTriangleLines · EndDrawing · GOLD · GREEN · InitWindow · MAROON · ORANGE · RAYWHITE · RED · SetTargetFPS · SKYBLUE · VIOLET · WindowShouldClose