← ziglang.inraylib-zigGitHub

digital clock

★★★★by Hamza RAHAL (@hmz-rhl)

There is no browser build of this example yet.

Is it the same as C?

//! raylib [shapes] example - digital clock
//!
//! Zig-API translation of examples/shapes/shapes_digital_clock.c (raylib 6.2).
//! Example licensed under an unmodified zlib/libpng license.
//! Copyright (c) 2025 Hamza RAHAL (@hmz-rhl) and Ramon Santamaria (@raysan5)

const rl = @import("raylib");

/// Local wall-clock time comes from libc (`time` + `localtime`), as in the C
/// example: Zig's standard library has no time-zone-aware local time.
const libc = struct {
    const Tm = extern struct {
        sec: c_int,
        min: c_int,
        hour: c_int,
        mday: c_int,
        mon: c_int,
        year: c_int,
        wday: c_int,
        yday: c_int,
        isdst: c_int,
        gmtoff: c_long,
        zone: ?[*:0]const u8,
    };
    extern "c" fn time(tloc: ?*c_long) c_long;
    extern "c" fn localtime(timer: *const c_long) *const Tm;
};

const ClockMode = enum { analog, digital };

/// Clock hand type
const ClockHand = struct {
    value: u32 = 0, // Time value (unsigned: `{d:0>2}` would print a sign for signed ints)

    // Visual elements
    angle: f32, // Hand angle
    length: i32, // Hand length
    thickness: i32, // Hand thickness
    color: rl.Color, // Hand color
};

/// Clock hands
const Clock = struct {
    second: ClockHand, // Clock hand for seconds
    minute: ClockHand, // Clock hand for minutes
    hour: ClockHand, // Clock hand for hours

    /// Update clock time: hand values and angles
    fn update(clock: *Clock) void {
        const now = libc.time(null);
        const time_info = libc.localtime(&now);

        // Updating time data
        clock.second.value = @intCast(time_info.sec);
        clock.minute.value = @intCast(time_info.min);
        clock.hour.value = @intCast(time_info.hour);

        clock.hour.angle = @as(f32, @floatFromInt(@mod(time_info.hour, 12))) * 180.0 / 6.0;
        clock.hour.angle += @as(f32, @floatFromInt(@mod(time_info.min, 60) * 30)) / 60.0;
        clock.hour.angle -= 90;

        clock.minute.angle = @as(f32, @floatFromInt(@mod(time_info.min, 60))) * 6.0;
        clock.minute.angle += @as(f32, @floatFromInt(@mod(time_info.sec, 60) * 6)) / 60.0;
        clock.minute.angle -= 90;

        clock.second.angle = @as(f32, @floatFromInt(@mod(time_info.sec, 60))) * 6.0;
        clock.second.angle -= 90;
    }
};

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

    rl.setConfigFlags(.{ .msaa_4x_hint = true });
    rl.initWindow(screen_width, screen_height, "raylib [shapes] example - digital clock");
    defer rl.closeWindow(); // Close window and OpenGL context

    var clock_mode: ClockMode = .digital;

    // Initialize clock
    // NOTE: Includes visual info for analog clock
    var clock: Clock = .{
        .second = .{ .angle = 45, .length = 140, .thickness = 3, .color = .maroon },
        .minute = .{ .angle = 10, .length = 130, .thickness = 7, .color = .dark_gray },
        .hour = .{ .angle = 0, .length = 100, .thickness = 7, .color = .black },
    };

    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
        if (rl.isKeyPressed(.space)) {
            // Toggle clock mode
            clock_mode = switch (clock_mode) {
                .digital => .analog,
                .analog => .digital,
            };
        }

        clock.update(); // Update clock required data: value and angle

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

        rl.clearBackground(.ray_white);

        // Draw clock in selected mode
        switch (clock_mode) {
            .analog => drawClockAnalog(clock, .{ .x = 400, .y = 240 }),
            .digital => {
                drawClockDigital(clock, .{ .x = 30, .y = 60 });

                // Draw clock using default raylib font
                // WARNING: Pointing to an internal static string that is reused between TextFormat() calls
                const clock_time = rl.textFormat("{d:0>2}:{d:0>2}:{d:0>2}", .{ clock.hour.value, clock.minute.value, clock.second.value });
                rl.drawText(clock_time, @divTrunc(rl.getScreenWidth(), 2) - @divTrunc(rl.measureText(clock_time, 150), 2), 300, 150, .black);
            },
        }

        const mode_name = switch (clock_mode) {
            .digital => "DIGITAL CLOCK",
            .analog => "ANALOGUE CLOCK",
        };
        rl.drawText(rl.textFormat("Press [SPACE] to switch clock mode: {s}", .{mode_name}), 10, 10, 20, .dark_gray);
    }
}

/// Draw analog clock
/// Parameter: position, refers to center position
fn drawClockAnalog(clock: Clock, position: rl.Vector2) void {
    // Draw clock base
    rl.drawCircleV(position, @as(f32, @floatFromInt(clock.second.length)) + 40.0, .light_gray);
    rl.drawCircleV(position, 12.0, .gray);

    // Draw clock minutes/seconds lines
    for (0..60) |i| {
        const angle = (6.0 * @as(f32, @floatFromInt(i)) - 90.0) * rl.deg2rad;
        const inner: f32 = @floatFromInt(clock.second.length + @as(i32, if (i % 5 != 0) 10 else 6));
        const outer: f32 = @floatFromInt(clock.second.length + 20);
        rl.drawLineEx(
            .{ .x = position.x + inner * @cos(angle), .y = position.y + inner * @sin(angle) },
            .{ .x = position.x + outer * @cos(angle), .y = position.y + outer * @sin(angle) },
            if (i % 5 != 0) 1.0 else 3.0,
            .dark_gray,
        );
    }

    // Draw hands: seconds, minutes, hours
    for ([_]ClockHand{ clock.second, clock.minute, clock.hour }) |hand| {
        const thickness: f32 = @floatFromInt(hand.thickness);
        rl.drawRectanglePro(
            .{ .x = position.x, .y = position.y, .width = @floatFromInt(hand.length), .height = thickness },
            .{ .x = 0.0, .y = thickness / 2.0 },
            hand.angle,
            hand.color,
        );
    }
}

/// Draw digital clock
/// Parameter: position, refers to top-left corner
fn drawClockDigital(clock: Clock, position: rl.Vector2) void {
    const off = rl.fade(.light_gray, 0.3);
    const blink: rl.Color = if (clock.second.value % 2 != 0) .red else off;

    // Draw clock using custom 7-segments display (made of shapes)
    drawDisplayValue(.{ .x = position.x, .y = position.y }, clock.hour.value / 10, .red, off);
    drawDisplayValue(.{ .x = position.x + 120, .y = position.y }, clock.hour.value % 10, .red, off);

    const x: i32 = @intFromFloat(position.x);
    const y: i32 = @intFromFloat(position.y);
    rl.drawCircle(x + 240, y + 70, 12, blink);
    rl.drawCircle(x + 240, y + 150, 12, blink);

    drawDisplayValue(.{ .x = position.x + 260, .y = position.y }, clock.minute.value / 10, .red, off);
    drawDisplayValue(.{ .x = position.x + 380, .y = position.y }, clock.minute.value % 10, .red, off);

    rl.drawCircle(x + 500, y + 70, 12, blink);
    rl.drawCircle(x + 500, y + 150, 12, blink);

    drawDisplayValue(.{ .x = position.x + 520, .y = position.y }, clock.second.value / 10, .red, off);
    drawDisplayValue(.{ .x = position.x + 640, .y = position.y }, clock.second.value % 10, .red, off);
}

/// Active segments (bit 0 = A ... bit 6 = G) for each decimal digit
const digit_segments = [10]u7{
    0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110,
    0b1101101, 0b1111101, 0b0000111, 0b1111111, 0b1101111,
};

/// Draw 7-segment display with value
fn drawDisplayValue(position: rl.Vector2, value: u32, color_on: rl.Color, color_off: rl.Color) void {
    if (value > 9) return;
    draw7SDisplay(position, digit_segments[value], color_on, color_off);
}

/// Draw seven segments display
/// Parameter: position, refers to top-left corner of display
/// Parameter: segments, defines in binary the segments to be activated
fn draw7SDisplay(position: rl.Vector2, segments: u7, color_on: rl.Color, color_off: rl.Color) void {
    const segment_len = 60;
    const segment_thick = 20;
    const offset_y_adjust: f32 = segment_thick * 0.3; // HACK: Adjust gap space between segment limits

    const Segment = struct { center: rl.Vector2, vertical: bool };
    const segments_layout = [7]Segment{
        // Segment A
        .{ .center = .{ .x = position.x + segment_thick + segment_len / 2.0, .y = position.y + segment_thick }, .vertical = false },
        // Segment B
        .{ .center = .{ .x = position.x + segment_thick + segment_len + segment_thick / 2.0, .y = position.y + 2 * segment_thick + segment_len / 2.0 - offset_y_adjust }, .vertical = true },
        // Segment C
        .{ .center = .{ .x = position.x + segment_thick + segment_len + segment_thick / 2.0, .y = position.y + 4 * segment_thick + segment_len + segment_len / 2.0 - 3 * offset_y_adjust }, .vertical = true },
        // Segment D
        .{ .center = .{ .x = position.x + segment_thick + segment_len / 2.0, .y = position.y + 5 * segment_thick + 2 * segment_len - 4 * offset_y_adjust }, .vertical = false },
        // Segment E
        .{ .center = .{ .x = position.x + segment_thick / 2.0, .y = position.y + 4 * segment_thick + segment_len + segment_len / 2.0 - 3 * offset_y_adjust }, .vertical = true },
        // Segment F
        .{ .center = .{ .x = position.x + segment_thick / 2.0, .y = position.y + 2 * segment_thick + segment_len / 2.0 - offset_y_adjust }, .vertical = true },
        // Segment G
        .{ .center = .{ .x = position.x + segment_thick + segment_len / 2.0, .y = position.y + 3 * segment_thick + segment_len - 2 * offset_y_adjust }, .vertical = false },
    };

    for (segments_layout, 0..) |segment, bit| {
        const on = (segments >> @intCast(bit)) & 1 != 0;
        drawDisplaySegment(segment.center, segment_len, segment_thick, segment.vertical, if (on) color_on else color_off);
    }
}

/// Draw one 7-segment display segment, horizontal or vertical
fn drawDisplaySegment(center: rl.Vector2, length: i32, thick: i32, vertical: bool, color: rl.Color) void {
    const half_len = @as(f32, @floatFromInt(length)) / 2.0;
    const half_thick = @as(f32, @floatFromInt(thick)) / 2.0;

    if (!vertical) {
        // Horizontal segment points
        //
        //      3___________________________5
        //     /                             \
        //    /1             x               6\
        //    \                               /
        //     \2___________________________4/
        //
        const segment_points_h = [6]rl.Vector2{
            .{ .x = center.x - half_len - half_thick, .y = center.y }, // Point 1
            .{ .x = center.x - half_len, .y = center.y + half_thick }, // Point 2
            .{ .x = center.x - half_len, .y = center.y - half_thick }, // Point 3
            .{ .x = center.x + half_len, .y = center.y + half_thick }, // Point 4
            .{ .x = center.x + half_len, .y = center.y - half_thick }, // Point 5
            .{ .x = center.x + half_len + half_thick, .y = center.y }, // Point 6
        };
        rl.drawTriangleStrip(&segment_points_h, color);
    } else {
        // Vertical segment points
        const segment_points_v = [6]rl.Vector2{
            .{ .x = center.x, .y = center.y - half_len - half_thick }, // Point 1
            .{ .x = center.x - half_thick, .y = center.y - half_len }, // Point 2
            .{ .x = center.x + half_thick, .y = center.y - half_len }, // Point 3
            .{ .x = center.x - half_thick, .y = center.y + half_len }, // Point 4
            .{ .x = center.x + half_thick, .y = center.y + half_len }, // Point 5
            .{ .x = center.x, .y = center.y + half_len + half_thick }, // Point 6
        };
        rl.drawTriangleStrip(&segment_points_v, color);
    }
}
/*******************************************************************************************
*
*   raylib [shapes] example - digital clock
*
*   Example complexity rating: [★★★★] 4/4
*
*   Example originally created with raylib 5.5, last time updated with raylib 5.6
*
*   Example contributed by Hamza RAHAL (@hmz-rhl) and reviewed by Ramon Santamaria (@raysan5)
*
*   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) 2025 Hamza RAHAL (@hmz-rhl) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/

#define _CRT_SECURE_NO_WARNINGS   // Disable some Visual Studio warnings

#include "raylib.h"

#include <math.h>       // Required for: cosf(), sinf()
#include <time.h>       // Required for: time(), localtime()

#define CLOCK_ANALOG    0
#define CLOCK_DIGITAL   1

//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
// Clock hand type
typedef struct {
    int value;          // Time value

    // Visual elements
    float angle;        // Hand angle
    int length;         // Hand length
    int thickness;      // Hand thickness
    Color color;        // Hand color
} ClockHand;

// Clock hands
typedef struct {
    ClockHand second;   // Clock hand for seconds
    ClockHand minute;   // Clock hand for minutes
    ClockHand hour;     // Clock hand for hours
} Clock;

//----------------------------------------------------------------------------------
// Module Functions Declaration
//----------------------------------------------------------------------------------
static void UpdateClock(Clock *clock); // Update clock time
static void DrawClockAnalog(Clock clock, Vector2 position); // Draw analog clock at desired center position
static void DrawClockDigital(Clock clock, Vector2 position); // Draw digital clock at desired position

static void DrawDisplayValue(Vector2 position, int value, Color colorOn, Color colorOff);
static void Draw7SDisplay(Vector2 position, char segments, Color colorOn, Color colorOff);
static void DrawDisplaySegment(Vector2 center, int length, int thick, bool vertical, Color color);

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

    SetConfigFlags(FLAG_MSAA_4X_HINT);
    InitWindow(screenWidth, screenHeight, "raylib [shapes] example - digital clock");

    int clockMode = CLOCK_DIGITAL;

    // Initialize clock
    // NOTE: Includes visual info for anlaog clock
    Clock clock = {
        .second.angle = 45,
        .second.length = 140,
        .second.thickness = 3,
        .second.color = MAROON,

        .minute.angle = 10,
        .minute.length = 130,
        .minute.thickness = 7,
        .minute.color = DARKGRAY,

        .hour.angle = 0,
        .hour.length = 100,
        .hour.thickness = 7,
        .hour.color = BLACK,
    };

    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
        //----------------------------------------------------------------------------------
        if (IsKeyPressed(KEY_SPACE))
        {
            // Toggle clock mode
            if (clockMode == CLOCK_DIGITAL) clockMode = CLOCK_ANALOG;
            else if (clockMode == CLOCK_ANALOG) clockMode = CLOCK_DIGITAL;
        }

        UpdateClock(&clock); // Update clock required data: value and angle
        //----------------------------------------------------------------------------------

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

            ClearBackground(RAYWHITE);

            // Draw clock in selected mode
            if (clockMode == CLOCK_ANALOG) DrawClockAnalog(clock, (Vector2){ 400, 240 });
            else if (clockMode == CLOCK_DIGITAL)
            {
                DrawClockDigital(clock, (Vector2){ 30, 60 });

                // Draw clock using default raylib font
                // Get pointer to formated clock time string
                // WARNING: Pointing to an internal static string that is reused between TextFormat() calls
                const char *clockTime = TextFormat("%02i:%02i:%02i", clock.hour.value, clock.minute.value, clock.second.value);
                DrawText(clockTime, GetScreenWidth()/2 - MeasureText(clockTime, 150)/2, 300, 150, BLACK);
            }

            DrawText(TextFormat("Press [SPACE] to switch clock mode: %s",
                (clockMode == CLOCK_DIGITAL)? "DIGITAL CLOCK" : "ANALOGUE CLOCK"), 10, 10, 20, DARKGRAY);

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

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

    return 0;
}

//----------------------------------------------------------------------------------
// Module Functions Definition
//----------------------------------------------------------------------------------
// Update clock time
static void UpdateClock(Clock *clock)
{
    time_t rawtime;
    struct tm *timeinfo;

    time(&rawtime);
    timeinfo = localtime(&rawtime);

    // Updating time data
    clock->second.value = timeinfo->tm_sec;
    clock->minute.value = timeinfo->tm_min;
    clock->hour.value = timeinfo->tm_hour;

    clock->hour.angle = (timeinfo->tm_hour%12)*180.0f/6.0f;
    clock->hour.angle += (timeinfo->tm_min%60)*30/60.0f;
    clock->hour.angle -= 90;

    clock->minute.angle = (timeinfo->tm_min%60)*6.0f;
    clock->minute.angle += (timeinfo->tm_sec%60)*6/60.0f;
    clock->minute.angle -= 90;

    clock->second.angle = (timeinfo->tm_sec%60)*6.0f;
    clock->second.angle -= 90;
}

// Draw analog clock
// Parameter: position, refers to center position
static void DrawClockAnalog(Clock clock, Vector2 position)
{
        // Draw clock base
        DrawCircleV(position, clock.second.length + 40.0f, LIGHTGRAY);
        DrawCircleV(position, 12.0f, GRAY);

        // Draw clock minutes/seconds lines
        for (int i = 0; i < 60; i++)
        {
            DrawLineEx((Vector2){ position.x + (clock.second.length + ((i%5)? 10 : 6))*cosf((6.0f*i - 90.0f)*DEG2RAD),
                position.y + (clock.second.length + ((i%5)? 10 : 6))*sinf((6.0f*i - 90.0f)*DEG2RAD) },
                (Vector2){ position.x + (clock.second.length + 20)*cosf((6.0f*i - 90.0f)*DEG2RAD),
                position.y + (clock.second.length + 20)*sinf((6.0f*i - 90.0f)*DEG2RAD) }, ((i%5)? 1.0f : 3.0f), DARKGRAY);

            // Draw seconds numbers
            //DrawText(TextFormat("%02i", i), centerPosition.x + (clock.second.length + 50)*cosf((6.0f*i - 90.0f)*DEG2RAD) - 10/2,
            //    centerPosition.y + (clock.second.length + 50)*sinf((6.0f*i - 90.0f)*DEG2RAD) - 10/2, 10, GRAY);
        }

        // Draw hand seconds
        DrawRectanglePro((Rectangle){ position.x, position.y, (float)clock.second.length, (float)clock.second.thickness },
            (Vector2){ 0.0f, clock.second.thickness/2.0f }, clock.second.angle, clock.second.color);

        // Draw hand minutes
        DrawRectanglePro((Rectangle){ position.x, position.y, (float)clock.minute.length, (float)clock.minute.thickness },
            (Vector2){ 0.0f, clock.minute.thickness/2.0f }, clock.minute.angle, clock.minute.color);

        // Draw hand hours
        DrawRectanglePro((Rectangle){ position.x, position.y, (float)clock.hour.length, (float)clock.hour.thickness },
            (Vector2){ 0.0f, clock.hour.thickness/2.0f }, clock.hour.angle, clock.hour.color);
}

// Draw digital clock
// PARAM: position, refers to top-left corner
static void DrawClockDigital(Clock clock, Vector2 position)
{
    // Draw clock using custom 7-segments display (made of shapes)
    DrawDisplayValue((Vector2){ position.x, position.y }, clock.hour.value/10, RED, Fade(LIGHTGRAY, 0.3f));
    DrawDisplayValue((Vector2){ position.x + 120, position.y }, clock.hour.value%10, RED, Fade(LIGHTGRAY, 0.3f));

    DrawCircle((int)position.x + 240, (int)position.y + 70, 12, (clock.second.value%2)? RED : Fade(LIGHTGRAY, 0.3f));
    DrawCircle((int)position.x + 240, (int)position.y + 150, 12, (clock.second.value%2)? RED : Fade(LIGHTGRAY, 0.3f));

    DrawDisplayValue((Vector2){ position.x + 260, position.y }, clock.minute.value/10, RED, Fade(LIGHTGRAY, 0.3f));
    DrawDisplayValue((Vector2){ position.x + 380, position.y }, clock.minute.value%10, RED, Fade(LIGHTGRAY, 0.3f));

    DrawCircle((int)position.x + 500, (int)position.y + 70, 12, (clock.second.value%2)? RED : Fade(LIGHTGRAY, 0.3f));
    DrawCircle((int)position.x + 500, (int)position.y + 150, 12, (clock.second.value%2)? RED : Fade(LIGHTGRAY, 0.3f));

    DrawDisplayValue((Vector2){ position.x + 520, position.y }, clock.second.value/10, RED, Fade(LIGHTGRAY, 0.3f));
    DrawDisplayValue((Vector2){ position.x + 640, position.y }, clock.second.value%10, RED, Fade(LIGHTGRAY, 0.3f));
}

// Draw 7-segment display with value
static void DrawDisplayValue(Vector2 position, int value, Color colorOn, Color colorOff)
{
    switch (value)
    {
        case 0: Draw7SDisplay(position, 0b00111111, colorOn, colorOff); break;
        case 1: Draw7SDisplay(position, 0b00000110, colorOn, colorOff); break;
        case 2: Draw7SDisplay(position, 0b01011011, colorOn, colorOff); break;
        case 3: Draw7SDisplay(position, 0b01001111, colorOn, colorOff); break;
        case 4: Draw7SDisplay(position, 0b01100110, colorOn, colorOff); break;
        case 5: Draw7SDisplay(position, 0b01101101, colorOn, colorOff); break;
        case 6: Draw7SDisplay(position, 0b01111101, colorOn, colorOff); break;
        case 7: Draw7SDisplay(position, 0b00000111, colorOn, colorOff); break;
        case 8: Draw7SDisplay(position, 0b01111111, colorOn, colorOff); break;
        case 9: Draw7SDisplay(position, 0b01101111, colorOn, colorOff); break;
        default: break;
    }
}

// Draw seven segments display
// Parameter: position, refers to top-left corner of display
// Parameter: segments, defines in binary the segments to be activated
static void Draw7SDisplay(Vector2 position, char segments, Color colorOn, Color colorOff)
{
    int segmentLen = 60;
    int segmentThick = 20;
    float offsetYAdjust = segmentThick*0.3f; // HACK: Adjust gap space between segment limits

    // Segment A
    DrawDisplaySegment((Vector2){ position.x + segmentThick + segmentLen/2.0f, position.y + segmentThick },
        segmentLen, segmentThick, false, (segments & 0b00000001)? colorOn : colorOff);
    // Segment B
    DrawDisplaySegment((Vector2){ position.x + segmentThick + segmentLen + segmentThick/2.0f, position.y + 2*segmentThick + segmentLen/2.0f - offsetYAdjust },
        segmentLen, segmentThick, true, (segments & 0b00000010)? colorOn : colorOff);
    // Segment C
    DrawDisplaySegment((Vector2){ position.x + segmentThick + segmentLen + segmentThick/2.0f, position.y + 4*segmentThick + segmentLen + segmentLen/2.0f - 3*offsetYAdjust },
        segmentLen, segmentThick, true, (segments & 0b00000100)? colorOn : colorOff);
    // Segment D
    DrawDisplaySegment((Vector2){ position.x + segmentThick + segmentLen/2.0f, position.y + 5*segmentThick + 2*segmentLen - 4*offsetYAdjust },
        segmentLen, segmentThick, false, (segments & 0b00001000)? colorOn : colorOff);
    // Segment E
    DrawDisplaySegment((Vector2){ position.x + segmentThick/2.0f, position.y + 4*segmentThick + segmentLen + segmentLen/2.0f - 3*offsetYAdjust },
        segmentLen, segmentThick, true, (segments & 0b00010000)? colorOn : colorOff);
    // Segment F
    DrawDisplaySegment((Vector2){ position.x + segmentThick/2.0f, position.y + 2*segmentThick + segmentLen/2.0f - offsetYAdjust },
        segmentLen, segmentThick, true, (segments & 0b00100000)? colorOn : colorOff);
    // Segment G
    DrawDisplaySegment((Vector2){ position.x + segmentThick + segmentLen/2.0f, position.y + 3*segmentThick + segmentLen - 2*offsetYAdjust },
        segmentLen, segmentThick, false, (segments & 0b01000000)? colorOn : colorOff);
}

// Draw one 7-segment display segment, horizontal or vertical
static void DrawDisplaySegment(Vector2 center, int length, int thick, bool vertical, Color color)
{
    if (!vertical)
    {
        // Horizontal segment points
        /*
             3___________________________5
            /                             \
           /1             x               6\
           \                               /
            \2___________________________4/
        */
        Vector2 segmentPointsH[6] = {
            (Vector2){ center.x - length/2.0f - thick/2.0f,  center.y },  // Point 1
            (Vector2){ center.x - length/2.0f,  center.y + thick/2.0f },  // Point 2
            (Vector2){ center.x - length/2.0f, center.y - thick/2.0f },   // Point 3
            (Vector2){ center.x + length/2.0f,  center.y + thick/2.0f },  // Point 4
            (Vector2){ center.x + length/2.0f,  center.y - thick/2.0f },  // Point 5
            (Vector2){ center.x + length/2.0f + thick/2.0f,  center.y },  // Point 6
        };

        DrawTriangleStrip(segmentPointsH, 6, color);
    }
    else
    {
        // Vertical segment points
        Vector2 segmentPointsV[6] = {
            (Vector2){ center.x,  center.y - length/2.0f - thick/2.0f },  // Point 1
            (Vector2){ center.x - thick/2.0f,  center.y - length/2.0f },  // Point 2
            (Vector2){ center.x + thick/2.0f, center.y - length/2.0f },   // Point 3
            (Vector2){ center.x - thick/2.0f,  center.y + length/2.0f },  // Point 4
            (Vector2){ center.x + thick/2.0f,  center.y + length/2.0f },  // Point 5
            (Vector2){ center.x,  center.y + (float)length/2 + thick/2.0f },     // Point 6
        };

        DrawTriangleStrip(segmentPointsV, 6, color);
    }
}

From raylib 6.2. The original on GitHub.