← ziglang.inraylib-zigGitHub

basic shapes

★☆☆☆by Ramon Santamaria (@raysan5)

There is no browser build of this example yet.

Is it the same as C?

//! raylib [shapes] example - basic shapes
//!
//! Zig-API translation of examples/shapes/shapes_basic_shapes.c (raylib 6.2).
//! Example licensed under an unmodified zlib/libpng license.
//! Copyright (c) 2014-2025 Ramon Santamaria (@raysan5)

const rl = @import("raylib");

pub fn main() void {
    // Initialization
    const screen_width = 800;
    const screen_height = 450;

    rl.initWindow(screen_width, screen_height, "raylib [shapes] example - basic shapes");
    defer rl.closeWindow(); // Close window and OpenGL context

    var rotation: f32 = 0.0;

    rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second

    // Main game loop
    while (!rl.windowShouldClose()) { // Detect window close button or ESC key
        // Update
        rotation += 0.2;

        // Draw
        rl.beginDrawing();
        defer rl.endDrawing();

        rl.clearBackground(.ray_white);

        rl.drawText("some basic shapes available on raylib", 20, 20, 20, .dark_gray);

        // Circle shapes and lines
        rl.drawCircle(screen_width / 5, 120, 35, .dark_blue);
        rl.drawCircleGradient(.{ .x = screen_width / 5.0, .y = 220.0 }, 60, .green, .sky_blue);
        rl.drawCircleLines(screen_width / 5, 340, 80, .dark_blue);
        rl.drawEllipse(screen_width / 5, 120, 25, 20, .yellow);
        rl.drawEllipseLines(screen_width / 5, 120, 30, 25, .yellow);

        // Rectangle shapes and lines
        rl.drawRectangle(screen_width / 4 * 2 - 60, 100, 120, 60, .red);
        rl.drawRectangleGradientH(screen_width / 4 * 2 - 90, 170, 180, 130, .maroon, .gold);
        rl.drawRectangleLines(screen_width / 4 * 2 - 40, 320, 80, 60, .orange); // NOTE: Uses QUADS internally, not lines

        // Triangle shapes and lines
        const tri_x = screen_width / 4.0 * 3.0;
        rl.drawTriangle(
            .{ .x = tri_x, .y = 80.0 },
            .{ .x = tri_x - 60.0, .y = 150.0 },
            .{ .x = tri_x + 60.0, .y = 150.0 },
            .violet,
        );
        rl.drawTriangleLines(
            .{ .x = tri_x, .y = 160.0 },
            .{ .x = tri_x - 20.0, .y = 230.0 },
            .{ .x = tri_x + 20.0, .y = 230.0 },
            .dark_blue,
        );

        // Polygon shapes and lines
        const poly_center: rl.Vector2 = .{ .x = tri_x, .y = 330 };
        rl.drawPoly(poly_center, 6, 80, rotation, .brown);
        rl.drawPolyLines(poly_center, 6, 90, rotation, .brown);
        rl.drawPolyLinesEx(poly_center, 6, 85, rotation, 6, .beige);

        // NOTE: We draw all LINES based shapes together to optimize internal drawing,
        // this way, all LINES are rendered in a single draw pass
        rl.drawLine(18, 42, screen_width - 18, 42, .black);
    }
}
/*******************************************************************************************
*
*   raylib [shapes] example - basic shapes
*
*   Example complexity rating: [★☆☆☆] 1/4
*
*   Example originally created with raylib 1.0, last time updated with raylib 4.2
*
*   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) 2014-2025 Ramon Santamaria (@raysan5)
*
********************************************************************************************/

#include "raylib.h"

//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main(void)
{
    // Initialization
    //--------------------------------------------------------------------------------------
    const int screenWidth = 800;
    const int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes");

    float rotation = 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
    {
        // Update
        //----------------------------------------------------------------------------------
        rotation += 0.2f;
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

            ClearBackground(RAYWHITE);

            DrawText("some basic shapes available on raylib", 20, 20, 20, DARKGRAY);

            // Circle shapes and lines
            DrawCircle(screenWidth/5, 120, 35, DARKBLUE);
            DrawCircleGradient((Vector2){ screenWidth/5.0f, 220.0f }, 60, GREEN, SKYBLUE);
            DrawCircleLines(screenWidth/5, 340, 80, DARKBLUE);
            DrawEllipse(screenWidth/5, 120, 25, 20, YELLOW);
            DrawEllipseLines(screenWidth/5, 120, 30, 25, YELLOW);

            // Rectangle shapes and lines
            DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED);
            DrawRectangleGradientH(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD);
            DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE);  // NOTE: Uses QUADS internally, not lines

            // Triangle shapes and lines
            DrawTriangle((Vector2){ screenWidth/4.0f *3.0f, 80.0f },
                         (Vector2){ screenWidth/4.0f *3.0f - 60.0f, 150.0f },
                         (Vector2){ screenWidth/4.0f *3.0f + 60.0f, 150.0f }, VIOLET);

            DrawTriangleLines((Vector2){ screenWidth/4.0f*3.0f, 160.0f },
                              (Vector2){ screenWidth/4.0f*3.0f - 20.0f, 230.0f },
                              (Vector2){ screenWidth/4.0f*3.0f + 20.0f, 230.0f }, DARKBLUE);

            // Polygon shapes and lines
            DrawPoly((Vector2){ screenWidth/4.0f*3, 330 }, 6, 80, rotation, BROWN);
            DrawPolyLines((Vector2){ screenWidth/4.0f*3, 330 }, 6, 90, rotation, BROWN);
            DrawPolyLinesEx((Vector2){ screenWidth/4.0f*3, 330 }, 6, 85, rotation, 6, BEIGE);

            // NOTE: We draw all LINES based shapes together to optimize internal drawing,
            // this way, all LINES are rendered in a single draw pass
            DrawLine(18, 42, screenWidth - 18, 42, BLACK);
        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    CloseWindow();        // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}

From raylib 6.2. The original on GitHub.