Compare commits

..

10 Commits

Author SHA1 Message Date
3824fcc15b chore: update LICENSE 2026-04-11 19:09:28 +02:00
a646dc3650 chore: update docs 2026-04-11 19:07:00 +02:00
d871db2b2f refactor: restructure the project 2026-04-11 18:33:11 +02:00
53649df179 feat: generate demo gifs for all languages 2026-04-11 18:21:34 +02:00
6b1ce83aba feat(ada): implement 2026-03-11 21:51:36 +01:00
f906676b21 feat(zig): implement 2026-03-11 20:46:40 +01:00
d55b1486d6 feat(oding): implement 2026-03-11 20:36:11 +01:00
4a4a630eaf feat(go): implement 2026-03-11 20:29:13 +01:00
54f2fc9bd4 refactor: constant logo height instead of using scale 2026-03-11 19:06:11 +01:00
96a26cea5c chore: update readme 2026-03-11 19:05:30 +01:00
69 changed files with 894 additions and 192 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
**/raylib_* **/raylib_*
demo_gen

View File

@@ -1,4 +1,4 @@
Copyright (c) 2025 Pihkaal <hello@pihkaal.me> Copyright (c) 2025-2026 Pihkaal <hello@pihkaal.me>
Permission is hereby granted, free of charge, to any person Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without files (the "Software"), to deal in the Software without

12
Makefile Normal file
View File

@@ -0,0 +1,12 @@
# used to generate the demos for all languages
demo_gen: tools/demo_gen.c
gcc -Wall -Wextra -pedantic -I./third_party/raylib-5.5_linux_amd64/include $^ -o $@ -L./third_party/raylib-5.5_linux_amd64/lib -l:libraylib.a -lm
.PHONY: run
run: demo_gen
./demo_gen
.PHONY: clean
clean:
rm -f ./**/raylib* ./demo_gen

View File

@@ -1,4 +1,24 @@
# raylib speedruns <div align="center">
<h1>Raylib Speedruns</h1>
<img src="./docs/demo.gif" alt="demo" />
</div>
Bouncing logos in different programming languages. Bouncing logos in different programming languages.
Get raylib at https://github.com/raysan5/raylib. Idea stolen from https://tsoding.github.io. Get raylib at https://github.com/raysan5/raylib. Idea stolen from https://tsoding.github.io.
All projects are built using `make`, so all commands you need are inside `Makefile`s.
## Implementations
| | |
|:---------------------------------------------------------:|:-----------------------------|
| <img width="32" src="./languages/ada/ada_logo.png"> | [Ada](./languages/ada) |
| <img width="32" src="./languages/c/c_logo.png"> | [C](./languages/c) |
| <img width="32" src="./languages/csharp/csharp_logo.png"> | [C#](./languages/csharp) |
| <img width="32" src="./languages/d/d_logo.png"> | [D](./languages/d) |
| <img width="32" src="./languages/go/go_logo.png"> | [Go](./languages/go) |
| <img width="32" src="./languages/odin/odin_logo.png"> | [Odin](./languages/odin) |
| <img width="32" src="./languages/python/python_logo.png"> | [Python](./languages/python) |
| <img width="32" src="./languages/rust/rust_logo.png"> | [Rust](./languages/rust) |
| <img width="32" src="./languages/zig/zig_logo.png"> | [Zig](./languages/zig) |

View File

@@ -1,2 +0,0 @@
raylib_c: main.c
gcc main.c -Wall -Wextra -Werror -pedantic -o raylib_c -I../_raylib-5.5_linux_amd64/include -L../_raylib-5.5_linux_amd64/lib -l:libraylib.a -lm

View File

@@ -1,8 +0,0 @@
# Raylib in C
## Quick start
```sh
$ make
$ ./raylib_c
```

View File

@@ -1,14 +0,0 @@
# Raylib in C#
I'm using Mono because i don't like Microsoft.
## Quick start
```shell
$ make
$ mono raylib_csharp.exe
```
## Credits
- Logo: [Wikipedia](https://wikipedia.org/wiki/File:Logo_C_sharp.svg)

View File

@@ -1,3 +0,0 @@
raylib_d: main.d
dmd main.d -of=./raylib_d ../_raylib-5.5_linux_amd64/lib/libraylib.a
rm ./raylib_d.o

View File

@@ -1,8 +0,0 @@
# Raylib in D
## Quick start
```sh
$ make
$ ./raylib_d
```

BIN
docs/demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 KiB

6
languages/ada/Makefile Normal file
View File

@@ -0,0 +1,6 @@
raylib_ada: main.adb
gnatmake main.adb -o raylib_ada \
-I../raylib-5.5_linux_amd64/include \
-largs ../raylib-5.5_linux_amd64/lib/libraylib.a \
-lm
rm -f main.ali main.o

17
languages/ada/README.md Normal file
View File

@@ -0,0 +1,17 @@
<div align="center">
<h1>Raylib in Ada</h1>
<img src="./demo.gif" alt="Ada Raylib demo" />
</div>
## Quick start
```sh
$ make
$ ./raylib_ada
```
Complete command in [Makefile](./Makefile)
## Credits
- Logo: [Wikimedia](https://commons.wikimedia.org/wiki/File:Ada_horizon_green_logo_with_slogan.svg)

BIN
languages/ada/ada_logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

BIN
languages/ada/demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

147
languages/ada/main.adb Normal file
View File

@@ -0,0 +1,147 @@
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
with Ada.Calendar;
with System;
procedure Main is
WINDOW_WIDTH : constant := 800;
WINDOW_HEIGHT : constant := 600;
LOGO_HEIGHT : constant := 64;
LOGO_SPEED : constant float := 300.0;
type Unsigned_Char is mod 2 ** 8;
for Unsigned_Char'Size use 8;
type Color is record
R, G, B, A : Unsigned_Char;
end record;
pragma Convention (C_Pass_By_Copy, Color);
type Vector2 is record
X, Y : float;
end record;
pragma Convention (C_Pass_By_Copy, Vector2);
type Image is record
Data : System.Address;
Width : int;
Height : int;
Mipmaps : int;
Format : int;
end record;
pragma Convention (C_Pass_By_Copy, Image);
type Texture2D is record
Id : unsigned;
Width : int;
Height : int;
Mipmaps : int;
Format : int;
end record;
pragma Convention (C_Pass_By_Copy, Texture2D);
BLACK : constant Color := (R => 0, G => 0, B => 0, A => 255);
WHITE : constant Color := (R => 255, G => 255, B => 255, A => 255);
procedure Init_Window (Width : int; Height : int; Title : chars_ptr);
pragma Import (C, Init_Window, "InitWindow");
procedure Set_Target_FPS (Fps : int);
pragma Import (C, Set_Target_FPS, "SetTargetFPS");
procedure Set_Random_Seed (Seed : unsigned);
pragma Import (C, Set_Random_Seed, "SetRandomSeed");
function Load_Image (File_Name : chars_ptr) return Image;
pragma Import (C, Load_Image, "LoadImage");
procedure Image_Resize (Img : access Image; New_Width : int; New_Height : int);
pragma Import (C, Image_Resize, "ImageResize");
function Load_Texture_From_Image (Img : Image) return Texture2D;
pragma Import (C, Load_Texture_From_Image, "LoadTextureFromImage");
procedure Unload_Image (Img : Image);
pragma Import (C, Unload_Image, "UnloadImage");
function Get_Random_Value (Min : int; Max : int) return int;
pragma Import (C, Get_Random_Value, "GetRandomValue");
function Window_Should_Close return int;
pragma Import (C, Window_Should_Close, "WindowShouldClose");
function Get_Frame_Time return float;
pragma Import (C, Get_Frame_Time, "GetFrameTime");
procedure Begin_Drawing;
pragma Import (C, Begin_Drawing, "BeginDrawing");
procedure End_Drawing;
pragma Import (C, End_Drawing, "EndDrawing");
procedure Clear_Background (C : Color);
pragma Import (C, Clear_Background, "ClearBackground");
procedure Draw_Texture_V (Tex : Texture2D; Pos : Vector2; Tint : Color);
pragma Import (C, Draw_Texture_V, "DrawTextureV");
procedure Unload_Texture (Tex : Texture2D);
pragma Import (C, Unload_Texture, "UnloadTexture");
procedure Close_Window;
pragma Import (C, Close_Window, "CloseWindow");
use type System.Address;
Logo_Image : aliased Image;
Logo_Texture : Texture2D;
X, Y : float;
Dx, Dy : float;
Delta_Time : float;
Seed : unsigned;
begin
Init_Window (WINDOW_WIDTH, WINDOW_HEIGHT, New_String ("Raylib in Ada"));
Set_Target_FPS (60);
Seed := unsigned (Ada.Calendar.Seconds (Ada.Calendar.Clock));
Set_Random_Seed (Seed);
Logo_Image := Load_Image (New_String ("./ada_logo.png"));
Image_Resize (Logo_Image'Access,
Logo_Image.Width * LOGO_HEIGHT / Logo_Image.Height,
LOGO_HEIGHT);
Logo_Texture := Load_Texture_From_Image (Logo_Image);
Unload_Image (Logo_Image);
X := float (Get_Random_Value (0, WINDOW_WIDTH - Logo_Texture.Width));
Y := float (Get_Random_Value (0, WINDOW_HEIGHT - Logo_Texture.Height));
Dx := (if Get_Random_Value (0, 1) = 1 then -LOGO_SPEED else LOGO_SPEED);
Dy := (if Get_Random_Value (0, 1) = 1 then -LOGO_SPEED else LOGO_SPEED);
while Window_Should_Close = 0 loop
Delta_Time := Get_Frame_Time;
X := X + Dx * Delta_Time;
Y := Y + Dy * Delta_Time;
if X < 0.0 or else X + float (Logo_Texture.Width) >= float (WINDOW_WIDTH) - 1.0 then
Dx := -Dx;
X := X + Dx * Delta_Time;
end if;
if Y < 0.0 or else Y + float (Logo_Texture.Height) >= float (WINDOW_HEIGHT) - 1.0 then
Dy := -Dy;
Y := Y + Dy * Delta_Time;
end if;
Begin_Drawing;
Clear_Background (BLACK);
Draw_Texture_V (Logo_Texture, (X => X, Y => Y), WHITE);
End_Drawing;
end loop;
Unload_Texture (Logo_Texture);
Close_Window;
end Main;

2
languages/c/Makefile Normal file
View File

@@ -0,0 +1,2 @@
raylib_c: main.c
gcc main.c -Wall -Wextra -Werror -pedantic -o raylib_c -I../raylib-5.5_linux_amd64/include -L../raylib-5.5_linux_amd64/lib -l:libraylib.a -lm

17
languages/c/README.md Normal file
View File

@@ -0,0 +1,17 @@
<div align="center">
<h1>Raylib in C</h1>
<img src="./demo.gif" alt="C Raylib demo" />
</div>
## Quick start
```sh
$ make
$ ./raylib_c
```
Complete command in [Makefile](./Makefile)
## Credits
- Logo: [Wikimedia](https://upload.wikimedia.org/wikipedia/commons/1/18/C_Programming_Language.svg)

View File

Before

Width:  |  Height:  |  Size: 108 KiB

After

Width:  |  Height:  |  Size: 108 KiB

BIN
languages/c/demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

View File

@@ -4,7 +4,7 @@
#define WINDOW_WIDTH 800 #define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600 #define WINDOW_HEIGHT 600
#define LOGO_SCALE 0.04f #define LOGO_HEIGHT 64
#define LOGO_SPEED 300 #define LOGO_SPEED 300
int main() int main()
@@ -13,13 +13,13 @@ int main()
SetTargetFPS(60); SetTargetFPS(60);
SetRandomSeed(time(NULL)); SetRandomSeed(time(NULL));
Texture2D logo_texture = LoadTexture("./c_logo.png"); Image logo_image = LoadImage("./c_logo.png");
ImageResize(&logo_image, logo_image.width * LOGO_HEIGHT / logo_image.height, LOGO_HEIGHT);
Texture2D logo_texture = LoadTextureFromImage(logo_image);
UnloadImage(logo_image);
float logo_width = logo_texture.width * LOGO_SCALE; float x = GetRandomValue(0, WINDOW_WIDTH - logo_texture.width);
float logo_height = logo_texture.height * LOGO_SCALE; float y = GetRandomValue(0, WINDOW_HEIGHT - logo_texture.height);
float x = GetRandomValue(0, WINDOW_WIDTH - logo_width);
float y = GetRandomValue(0, WINDOW_HEIGHT - logo_height);
float dx = LOGO_SPEED * (GetRandomValue(0, 1) ? -1 : 1); float dx = LOGO_SPEED * (GetRandomValue(0, 1) ? -1 : 1);
float dy = LOGO_SPEED * (GetRandomValue(0, 1) ? -1 : 1); float dy = LOGO_SPEED * (GetRandomValue(0, 1) ? -1 : 1);
@@ -31,12 +31,12 @@ int main()
x += dx * delta_time; x += dx * delta_time;
y += dy * delta_time; y += dy * delta_time;
if (x < 0 || (x + logo_width) >= WINDOW_WIDTH - 1) if (x < 0 || (x + logo_texture.width) >= WINDOW_WIDTH - 1)
{ {
dx *= -1; dx *= -1;
x += dx * delta_time; x += dx * delta_time;
} }
if (y < 0 || (y + logo_height) >= WINDOW_HEIGHT - 1) if (y < 0 || (y + logo_texture.height) >= WINDOW_HEIGHT - 1)
{ {
dy *= -1; dy *= -1;
y += dy * delta_time; y += dy * delta_time;
@@ -45,7 +45,7 @@ int main()
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(BLACK);
DrawTextureEx(logo_texture, (Vector2){x, y}, 0, LOGO_SCALE, WHITE); DrawTextureV(logo_texture, (Vector2){x, y}, WHITE);
EndDrawing(); EndDrawing();
} }

View File

@@ -0,0 +1,19 @@
<div align="center">
<h1>Raylib in C#</h1>
<img src="./demo.gif" alt="C# Raylib demo" />
</div>
I'm using Mono because i don't like Microsoft.
## Quick start
```sh
$ make
$ mono raylib_csharp.exe
```
Complete command in [Makefile](./Makefile)
## Credits
- Logo: [Wikimedia](https://commons.wikimedia.org/wiki/File:Logo_C_sharp.svg)

View File

Before

Width:  |  Height:  |  Size: 117 KiB

After

Width:  |  Height:  |  Size: 117 KiB

BIN
languages/csharp/demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

View File

@@ -1,7 +1,18 @@
using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
static class Program static class Program
{ {
[StructLayout(LayoutKind.Sequential)]
struct Image
{
public IntPtr data;
public int width;
public int height;
public int mipmaps;
public int format;
}
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
struct Texture2D struct Texture2D
{ {
@@ -28,17 +39,19 @@ static class Program
public byte a; public byte a;
} }
private const string RAYLIB = "../_raylib-5.5_linux_amd64/lib/libraylib.so"; private const string RAYLIB = "../raylib-5.5_linux_amd64/lib/libraylib.so";
[DllImport(RAYLIB)] private static extern void InitWindow(int width, int height, string title); [DllImport(RAYLIB)] private static extern void InitWindow(int width, int height, string title);
[DllImport(RAYLIB)] private static extern void CloseWindow(); [DllImport(RAYLIB)] private static extern void CloseWindow();
[DllImport(RAYLIB)] private static extern void SetTargetFPS(int fps); [DllImport(RAYLIB)] private static extern void SetTargetFPS(int fps);
[DllImport(RAYLIB)] private static extern void SetRandomSeed(uint seed); [DllImport(RAYLIB)] private static extern void SetRandomSeed(uint seed);
[DllImport(RAYLIB)] private static extern int GetRandomValue(int min, int max); [DllImport(RAYLIB)] private static extern int GetRandomValue(int min, int max);
[DllImport(RAYLIB)] private static extern Texture2D LoadTexture(string file_name); [DllImport(RAYLIB)] private static extern Image LoadImage(string file_name);
[DllImport(RAYLIB)] private static extern void ImageResize(ref Image image, int new_width, int new_height);
[DllImport(RAYLIB)] private static extern Texture2D LoadTextureFromImage(Image image);
[DllImport(RAYLIB)] private static extern void UnloadImage(Image image);
[DllImport(RAYLIB)] private static extern void UnloadTexture(Texture2D texture); [DllImport(RAYLIB)] private static extern void UnloadTexture(Texture2D texture);
[DllImport(RAYLIB)] private static extern bool WindowShouldClose(); [DllImport(RAYLIB)] private static extern bool WindowShouldClose();
@@ -46,12 +59,12 @@ static class Program
[DllImport(RAYLIB)] private static extern void BeginDrawing(); [DllImport(RAYLIB)] private static extern void BeginDrawing();
[DllImport(RAYLIB)] private static extern void ClearBackground(Color color); [DllImport(RAYLIB)] private static extern void ClearBackground(Color color);
[DllImport(RAYLIB)] private static extern void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); [DllImport(RAYLIB)] private static extern void DrawTextureV(Texture2D texture, Vector2 position, Color tint);
[DllImport(RAYLIB)] private static extern void EndDrawing(); [DllImport(RAYLIB)] private static extern void EndDrawing();
private const int WINDOW_WIDTH = 800; private const int WINDOW_WIDTH = 800;
private const int WINDOW_HEIGHT = 600; private const int WINDOW_HEIGHT = 600;
private const float LOGO_SCALE = 0.05f; private const int LOGO_HEIGHT = 64;
private const float LOGO_SPEED = 300; private const float LOGO_SPEED = 300;
private static Color BLACK = new Color() { r = 0, g = 0, b = 0, a = 255 }; private static Color BLACK = new Color() { r = 0, g = 0, b = 0, a = 255 };
@@ -62,13 +75,13 @@ static class Program
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Raylib in C#"); InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Raylib in C#");
SetTargetFPS(60); SetTargetFPS(60);
Texture2D logo_texture = LoadTexture("./csharp_logo.png"); Image logo_image = LoadImage("./csharp_logo.png");
ImageResize(ref logo_image, logo_image.width * LOGO_HEIGHT / logo_image.height, LOGO_HEIGHT);
Texture2D logo_texture = LoadTextureFromImage(logo_image);
UnloadImage(logo_image);
int logo_width = (int)(logo_texture.width * LOGO_SCALE); float x = GetRandomValue(0, WINDOW_WIDTH - logo_texture.width);
int logo_height = (int)(logo_texture.height * LOGO_SCALE); float y = GetRandomValue(0, WINDOW_HEIGHT - logo_texture.height);
float x = GetRandomValue(0, WINDOW_WIDTH - logo_width);
float y = GetRandomValue(0, WINDOW_HEIGHT - logo_height);
float dx = LOGO_SPEED * (GetRandomValue(0, 1) == 1 ? -1 : 1); float dx = LOGO_SPEED * (GetRandomValue(0, 1) == 1 ? -1 : 1);
float dy = LOGO_SPEED * (GetRandomValue(0, 1) == 1 ? -1 : 1); float dy = LOGO_SPEED * (GetRandomValue(0, 1) == 1 ? -1 : 1);
@@ -80,12 +93,12 @@ static class Program
x += dx * delta_time; x += dx * delta_time;
y += dy * delta_time; y += dy * delta_time;
if (x < 0 || (x + logo_width) >= WINDOW_WIDTH - 1) if (x < 0 || (x + logo_texture.width) >= WINDOW_WIDTH - 1)
{ {
dx *= -1; dx *= -1;
x += dx * delta_time; x += dx * delta_time;
} }
if (y < 0 || (y + logo_height) >= WINDOW_HEIGHT - 1) if (y < 0 || (y + logo_texture.height) >= WINDOW_HEIGHT - 1)
{ {
dy *= -1; dy *= -1;
y += dy * delta_time; y += dy * delta_time;
@@ -94,7 +107,7 @@ static class Program
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(BLACK);
DrawTextureEx(logo_texture, new Vector2() { x = x, y = y }, 0, LOGO_SCALE, WHITE); DrawTextureV(logo_texture, new Vector2() { x = x, y = y }, WHITE);
EndDrawing(); EndDrawing();
} }

3
languages/d/Makefile Normal file
View File

@@ -0,0 +1,3 @@
raylib_d: main.d
dmd main.d -of=./raylib_d ../raylib-5.5_linux_amd64/lib/libraylib.a
rm ./raylib_d.o

17
languages/d/README.md Normal file
View File

@@ -0,0 +1,17 @@
<div align="center">
<h1>Raylib in D</h1>
<img src="./demo.gif" alt="D Raylib demo" />
</div>
## Quick start
```sh
$ make
$ ./raylib_d
```
Complete command in [Makefile](./Makefile)
## Credits
- Logo: [Wikimedia](https://commons.wikimedia.org/wiki/File:D_Programming_Language_logo.svg)

View File

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 76 KiB

BIN
languages/d/demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 KiB

View File

@@ -1,6 +1,14 @@
import std.stdio; import std.stdio;
import std.datetime; import std.datetime;
struct Image {
void* data;
int width;
int height;
int mipmaps;
int format;
}
struct Texture2D { struct Texture2D {
uint id; uint id;
int width; int width;
@@ -29,7 +37,10 @@ extern(C):
void SetRandomSeed(uint seed); void SetRandomSeed(uint seed);
int GetRandomValue(int min, int max); int GetRandomValue(int min, int max);
Texture2D LoadTexture(const char* file_name); Image LoadImage(const char* file_name);
void ImageResize(Image* image, int new_width, int new_height);
Texture2D LoadTextureFromImage(Image image);
void UnloadImage(Image image);
void UnloadTexture(Texture2D texture); void UnloadTexture(Texture2D texture);
bool WindowShouldClose(); bool WindowShouldClose();
@@ -37,29 +48,29 @@ extern(C):
void BeginDrawing(); void BeginDrawing();
void ClearBackground(Color color); void ClearBackground(Color color);
void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); void DrawTextureV(Texture2D texture, Vector2 position, Color tint);
void EndDrawing(); void EndDrawing();
const int WINDOW_WIDTH = 800; const int WINDOW_WIDTH = 800;
const int WINDOW_HEIGHT = 600; const int WINDOW_HEIGHT = 600;
const float LOGO_SCALE = 0.1f; const int LOGO_HEIGHT = 64;
const float LOGO_SPEED = 300; const float LOGO_SPEED = 300;
const Color BLACK = Color(0, 0, 0, 255); const Color BLACK = Color(0, 0, 0, 255);
const Color WHITE = Color(255, 255, 255, 255); const Color WHITE = Color(255, 255, 255, 255);
void main() { void main() {
InitWindow(800, 600, "Raylib in D"); InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Raylib in D");
SetTargetFPS(60); SetTargetFPS(60);
SetRandomSeed(cast(uint)Clock.currStdTime()); SetRandomSeed(cast(uint)Clock.currStdTime());
Texture2D logo_texture = LoadTexture("./d_logo.png"); Image logo_image = LoadImage("./d_logo.png");
ImageResize(&logo_image, logo_image.width * LOGO_HEIGHT / logo_image.height, LOGO_HEIGHT);
Texture2D logo_texture = LoadTextureFromImage(logo_image);
UnloadImage(logo_image);
int logo_width = cast(int)(logo_texture.width * LOGO_SCALE); float x = GetRandomValue(0, WINDOW_WIDTH - logo_texture.width);
int logo_height = cast(int)(logo_texture.height * LOGO_SCALE); float y = GetRandomValue(0, WINDOW_HEIGHT - logo_texture.height);
float x = GetRandomValue(0, WINDOW_WIDTH - logo_width);
float y = GetRandomValue(0, WINDOW_HEIGHT - logo_height);
float dx = LOGO_SPEED * (GetRandomValue(0, 1) ? -1 : 1); float dx = LOGO_SPEED * (GetRandomValue(0, 1) ? -1 : 1);
float dy = LOGO_SPEED * (GetRandomValue(0, 1) ? -1 : 1); float dy = LOGO_SPEED * (GetRandomValue(0, 1) ? -1 : 1);
@@ -70,12 +81,12 @@ void main() {
x += dx * delta_time; x += dx * delta_time;
y += dy * delta_time; y += dy * delta_time;
if (x < 0 || (x + logo_width) >= WINDOW_WIDTH - 1) if (x < 0 || (x + logo_texture.width) >= WINDOW_WIDTH - 1)
{ {
dx *= -1; dx *= -1;
x += dx * delta_time; x += dx * delta_time;
} }
if (y < 0 || (y + logo_height) >= WINDOW_HEIGHT - 1) if (y < 0 || (y + logo_texture.height) >= WINDOW_HEIGHT - 1)
{ {
dy *= -1; dy *= -1;
y += dy * delta_time; y += dy * delta_time;
@@ -84,7 +95,7 @@ void main() {
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(BLACK);
DrawTextureEx(logo_texture, Vector2(x, y), 0, LOGO_SCALE, WHITE); DrawTextureV(logo_texture, Vector2(x, y), WHITE);
EndDrawing(); EndDrawing();
} }

2
languages/go/Makefile Normal file
View File

@@ -0,0 +1,2 @@
raylib_go: main.go
go build -o raylib_go main.go

17
languages/go/README.md Normal file
View File

@@ -0,0 +1,17 @@
<div align="center">
<h1>Raylib in Go</h1>
<img src="./demo.gif" alt="Go Raylib demo" />
</div>
## Quick start
```sh
$ make
$ ./raylib_go
```
Complete command in [Makefile](./Makefile)
## Credits
- Logo: [Wikimedia](https://commons.wikimedia.org/wiki/File:Go_Logo_Blue.svg)

BIN
languages/go/demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 KiB

BIN
languages/go/go_logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

66
languages/go/main.go Normal file
View File

@@ -0,0 +1,66 @@
package main
/*
#cgo CFLAGS: -I../raylib-5.5_linux_amd64/include
#cgo LDFLAGS: -L../raylib-5.5_linux_amd64/lib -l:libraylib.a -lm
#include <raylib.h>
*/
import "C"
import "time"
const (
windowWidth = 800
windowHeight = 600
logoHeight = 64
logoSpeed = 300.0
)
func main() {
C.InitWindow(windowWidth, windowHeight, C.CString("Raylib in Go"))
C.SetTargetFPS(60)
C.SetRandomSeed(C.uint(time.Now().Unix()))
logoImage := C.LoadImage(C.CString("./go_logo.png"))
C.ImageResize(&logoImage, logoImage.width*logoHeight/logoImage.height, logoHeight)
logoTexture := C.LoadTextureFromImage(logoImage)
C.UnloadImage(logoImage)
x := float32(C.GetRandomValue(0, windowWidth-C.int(logoTexture.width)))
y := float32(C.GetRandomValue(0, windowHeight-C.int(logoTexture.height)))
dx := float32(logoSpeed)
if C.GetRandomValue(0, 1) == 1 {
dx = -dx
}
dy := float32(logoSpeed)
if C.GetRandomValue(0, 1) == 1 {
dy = -dy
}
black := C.Color{0, 0, 0, 255}
white := C.Color{255, 255, 255, 255}
for !bool(C.WindowShouldClose()) {
deltaTime := float32(C.GetFrameTime())
x += dx * deltaTime
y += dy * deltaTime
if x < 0 || x+float32(logoTexture.width) >= windowWidth-1 {
dx *= -1
x += dx * deltaTime
}
if y < 0 || y+float32(logoTexture.height) >= windowHeight-1 {
dy *= -1
y += dy * deltaTime
}
C.BeginDrawing()
C.ClearBackground(black)
C.DrawTextureV(logoTexture, C.Vector2{x: C.float(x), y: C.float(y)}, white)
C.EndDrawing()
}
C.UnloadTexture(logoTexture)
C.CloseWindow()
}

2
languages/odin/Makefile Normal file
View File

@@ -0,0 +1,2 @@
raylib_odin: main.odin
odin build main.odin -file -out:raylib_odin

17
languages/odin/README.md Normal file
View File

@@ -0,0 +1,17 @@
<div align="center">
<h1>Raylib in Odin</h1>
<img src="./demo.gif" alt="Odin Raylib demo" />
</div>
## Quick start
```sh
$ make
$ ./raylib_odin
```
Complete command in [Makefile](./Makefile)
## Credits
- Logo: [Wikimedia](https://commons.wikimedia.org/wiki/File:The_odin_programming_language_logo.svg)

BIN
languages/odin/demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 KiB

107
languages/odin/main.odin Normal file
View File

@@ -0,0 +1,107 @@
package main
import "core:time"
foreign import raylib {
"../raylib-5.5_linux_amd64/lib/libraylib.a",
"system:m",
}
Image :: struct {
data: rawptr,
width: i32,
height: i32,
mipmaps: i32,
format: i32,
}
Texture2D :: struct {
id: u32,
width: i32,
height: i32,
mipmaps: i32,
format: i32,
}
Vector2 :: struct {
x: f32,
y: f32,
}
Color :: struct {
r: u8,
g: u8,
b: u8,
a: u8,
}
@(default_calling_convention = "c")
foreign raylib {
InitWindow :: proc(width: i32, height: i32, title: cstring) ---
CloseWindow :: proc() ---
SetTargetFPS :: proc(fps: i32) ---
SetRandomSeed :: proc(seed: u32) ---
GetRandomValue :: proc(min: i32, max: i32) -> i32 ---
LoadImage :: proc(file_name: cstring) -> Image ---
ImageResize :: proc(image: ^Image, new_width: i32, new_height: i32) ---
LoadTextureFromImage :: proc(image: Image) -> Texture2D ---
UnloadImage :: proc(image: Image) ---
UnloadTexture :: proc(texture: Texture2D) ---
WindowShouldClose :: proc() -> bool ---
GetFrameTime :: proc() -> f32 ---
BeginDrawing :: proc() ---
ClearBackground :: proc(color: Color) ---
DrawTextureV :: proc(texture: Texture2D, position: Vector2, tint: Color) ---
EndDrawing :: proc() ---
}
WINDOW_WIDTH :: 800
WINDOW_HEIGHT :: 600
LOGO_HEIGHT :: 64
LOGO_SPEED :: 300
BLACK :: Color{0, 0, 0, 255}
WHITE :: Color{255, 255, 255, 255}
main :: proc() {
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Raylib in Odin")
SetTargetFPS(60)
SetRandomSeed(cast(u32)time.now()._nsec)
logo_image := LoadImage("./odin_logo.png")
ImageResize(&logo_image, logo_image.width * LOGO_HEIGHT / logo_image.height, LOGO_HEIGHT)
logo_texture := LoadTextureFromImage(logo_image)
UnloadImage(logo_image)
x := f32(GetRandomValue(0, WINDOW_WIDTH - logo_texture.width))
y := f32(GetRandomValue(0, WINDOW_HEIGHT - logo_texture.height))
dx: f32 = LOGO_SPEED
if GetRandomValue(0, 1) == 1 do dx = -dx
dy: f32 = LOGO_SPEED
if GetRandomValue(0, 1) == 1 do dy = -dy
for !WindowShouldClose() {
delta_time := GetFrameTime()
x += dx * delta_time
y += dy * delta_time
if x < 0 || x + f32(logo_texture.width) >= WINDOW_WIDTH - 1 {
dx *= -1
x += dx * delta_time
}
if y < 0 || y + f32(logo_texture.height) >= WINDOW_HEIGHT - 1 {
dy *= -1
y += dy * delta_time
}
BeginDrawing()
ClearBackground(BLACK)
DrawTextureV(logo_texture, Vector2{x, y}, WHITE)
EndDrawing()
}
UnloadTexture(logo_texture)
CloseWindow()
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

View File

@@ -0,0 +1,14 @@
<div align="center">
<h1>Raylib in Python</h1>
<img src="./demo.gif" alt="Python Raylib demo" />
</div>
## Quick start
```sh
$ python ./main.py
```
## Credits
- Logo: [Wikimedia](https://commons.wikimedia.org/wiki/File:Python-logo-notext.svg)

BIN
languages/python/demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

86
languages/python/main.py Normal file
View File

@@ -0,0 +1,86 @@
from ctypes import *
from time import time
rl = CDLL("../raylib-5.5_linux_amd64/lib/libraylib.so")
class Image(Structure):
_fields_ = [
("data", c_void_p),
("width", c_int),
("height", c_int),
("mipmaps", c_int),
("format", c_int),
]
class Texture2D(Structure):
_fields_ = [
("id", c_uint),
("width", c_int),
("height", c_int),
("mipmaps", c_int),
("format", c_int),
]
class Vector2(Structure):
_fields_ = [
("x", c_float),
("y", c_float),
]
class Color(Structure):
_fields_ = [
("r", c_ubyte),
("g", c_ubyte),
("b", c_ubyte),
("a", c_ubyte),
]
rl.LoadImage.restype = Image
rl.LoadTextureFromImage.restype = Texture2D
rl.GetFrameTime.restype = c_float
WINDOW_WIDTH = 800
WINDOW_HEIGHT = 600
LOGO_HEIGHT = 64
LOGO_SPEED = 300
BLACK = Color(r=0,g=0,b=0,a=255)
WHITE = Color(r=255,g=255,b=255,a=255)
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, b"Raylib in Python")
rl.SetTargetFPS(60)
rl.SetRandomSeed(int(time()))
logo_image = rl.LoadImage(b"./python_logo.png")
rl.ImageResize(byref(logo_image), logo_image.width * LOGO_HEIGHT // logo_image.height, LOGO_HEIGHT)
logo_texture = rl.LoadTextureFromImage(logo_image)
rl.UnloadImage(logo_image)
x = rl.GetRandomValue(0, WINDOW_WIDTH - logo_texture.width)
y = rl.GetRandomValue(0, WINDOW_HEIGHT - logo_texture.height)
dx = LOGO_SPEED * (-1 if rl.GetRandomValue(0, 1) else 1)
dy = LOGO_SPEED * (-1 if rl.GetRandomValue(0, 1) else 1)
while not rl.WindowShouldClose():
delta_time = rl.GetFrameTime()
x += dx * delta_time
y += dy * delta_time
if x < 0 or (x + logo_texture.width) >= WINDOW_WIDTH - 1:
dx *= -1
x += dx * delta_time
if y < 0 or (y + logo_texture.height) >= WINDOW_HEIGHT - 1:
dy *= -1
y += dy * delta_time
rl.BeginDrawing()
rl.ClearBackground(BLACK)
rl.DrawTextureV(logo_texture, Vector2(x=x, y=y), WHITE)
rl.EndDrawing()
rl.UnloadTexture(logo_texture)
rl.CloseWindow()

View File

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 78 KiB

2
languages/rust/Makefile Normal file
View File

@@ -0,0 +1,2 @@
raylib_rust: main.rs
rustc --edition 2021 main.rs -C link-args="-L ../raylib-5.5_linux_amd64/lib -l:libraylib.a -lm" -o raylib_rust

17
languages/rust/README.md Normal file
View File

@@ -0,0 +1,17 @@
<div align="center">
<h1>Raylib in Rust</h1>
<img src="./demo.gif" alt="Rust Raylib demo" />
</div>
## Quick start
```sh
$ make
$ ./raylib_rust
```
Complete command in [Makefile](./Makefile)
## Credits
- Logo: [Wikimedia](https://commons.wikimedia.org/wiki/File:Rust_programming_language_black_logo.svg) (tinted)

BIN
languages/rust/demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

View File

@@ -1,17 +1,20 @@
use std::{ use std::{
ffi::{c_float, c_int, c_uchar, c_uint}, ffi::{c_char, c_float, c_int, c_uchar, c_uint, c_void},
time::{SystemTime, UNIX_EPOCH}, time::{SystemTime, UNIX_EPOCH},
}; };
extern "C" { extern "C" {
fn InitWindow(width: c_int, height: c_int, title: *const u8); fn InitWindow(width: c_int, height: c_int, title: *const c_char);
fn CloseWindow(); fn CloseWindow();
fn SetTargetFPS(fps: c_int); fn SetTargetFPS(fps: c_int);
fn SetRandomSeed(seed: c_uint); fn SetRandomSeed(seed: c_uint);
fn GetRandomValue(min: c_int, max: c_int) -> c_int; fn GetRandomValue(min: c_int, max: c_int) -> c_int;
fn LoadTexture(file_name: *const u8) -> Texture2D; fn LoadImage(file_name: *const c_char) -> Image;
fn ImageResize(image: *mut Image, new_width: c_int, new_height: c_int);
fn LoadTextureFromImage(image: Image) -> Texture2D;
fn UnloadImage(image: Image);
fn UnloadTexture(texture: Texture2D); fn UnloadTexture(texture: Texture2D);
fn WindowShouldClose() -> bool; fn WindowShouldClose() -> bool;
@@ -19,16 +22,20 @@ extern "C" {
fn BeginDrawing(); fn BeginDrawing();
fn ClearBackground(color: Color); fn ClearBackground(color: Color);
fn DrawTextureEx( fn DrawTextureV(texture: Texture2D, position: Vector2, tint: Color);
texture: Texture2D,
position: Vector2,
rotation: c_float,
scale: c_float,
tint: Color,
);
fn EndDrawing(); fn EndDrawing();
} }
#[derive(Clone, Copy)]
#[repr(C)]
struct Image {
data: *mut c_void,
width: c_int,
height: c_int,
mipmaps: c_int,
format: c_int,
}
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
#[repr(C)] #[repr(C)]
struct Texture2D { struct Texture2D {
@@ -55,7 +62,7 @@ struct Color {
const WINDOW_WIDTH: c_int = 800; const WINDOW_WIDTH: c_int = 800;
const WINDOW_HEIGHT: c_int = 600; const WINDOW_HEIGHT: c_int = 600;
const LOGO_SCALE: f32 = 0.04; const LOGO_HEIGHT: c_int = 64;
const LOGO_SPEED: f32 = 300.0; const LOGO_SPEED: f32 = 300.0;
const BLACK: Color = Color { const BLACK: Color = Color {
@@ -73,7 +80,7 @@ const WHITE: Color = Color {
fn main() { fn main() {
unsafe { unsafe {
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Raylib in Rust".as_ptr()); InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, c"Raylib in Rust".as_ptr());
SetTargetFPS(60); SetTargetFPS(60);
SetRandomSeed( SetRandomSeed(
SystemTime::now() SystemTime::now()
@@ -82,13 +89,17 @@ fn main() {
.as_secs() as u32, .as_secs() as u32,
); );
let logo_texture = LoadTexture("./rust_logo.png".as_ptr()); let mut logo_image = LoadImage(c"./rust_logo.png".as_ptr());
ImageResize(
&mut logo_image,
logo_image.width * LOGO_HEIGHT / logo_image.height,
LOGO_HEIGHT,
);
let logo_texture = LoadTextureFromImage(logo_image);
UnloadImage(logo_image);
let logo_width = (logo_texture.width as f32 * LOGO_SCALE) as i32; let mut x = GetRandomValue(0, WINDOW_WIDTH - logo_texture.width) as f32;
let logo_height = (logo_texture.height as f32 * LOGO_SCALE) as i32; let mut y = GetRandomValue(0, WINDOW_HEIGHT - logo_texture.height) as f32;
let mut x = GetRandomValue(0, WINDOW_WIDTH - logo_width) as f32;
let mut y = GetRandomValue(0, WINDOW_HEIGHT - logo_height) as f32;
let mut dx = LOGO_SPEED * if GetRandomValue(0, 1) == 1 { -1.0 } else { 1.0 }; let mut dx = LOGO_SPEED * if GetRandomValue(0, 1) == 1 { -1.0 } else { 1.0 };
let mut dy = LOGO_SPEED * if GetRandomValue(0, 1) == 1 { -1.0 } else { 1.0 }; let mut dy = LOGO_SPEED * if GetRandomValue(0, 1) == 1 { -1.0 } else { 1.0 };
@@ -99,11 +110,11 @@ fn main() {
x += dx * delta_time; x += dx * delta_time;
y += dy * delta_time; y += dy * delta_time;
if x < 0.0 || x + logo_width as f32 >= WINDOW_WIDTH as f32 - 1.0 { if x < 0.0 || x + logo_texture.width as f32 >= WINDOW_WIDTH as f32 - 1.0 {
dx *= -1.0; dx *= -1.0;
x += dx * delta_time; x += dx * delta_time;
} }
if y < 0.0 || y + logo_height as f32 >= WINDOW_HEIGHT as f32 - 1.0 { if y < 0.0 || y + logo_texture.height as f32 >= WINDOW_HEIGHT as f32 - 1.0 {
dy *= -1.0; dy *= -1.0;
y += dy * delta_time; y += dy * delta_time;
} }
@@ -111,7 +122,7 @@ fn main() {
BeginDrawing(); BeginDrawing();
ClearBackground(BLACK); ClearBackground(BLACK);
DrawTextureEx(logo_texture, Vector2 { x, y }, 0.0, LOGO_SCALE, WHITE); DrawTextureV(logo_texture, Vector2 { x, y }, WHITE);
EndDrawing(); EndDrawing();
} }

View File

Before

Width:  |  Height:  |  Size: 16 MiB

After

Width:  |  Height:  |  Size: 16 MiB

2
languages/zig/Makefile Normal file
View File

@@ -0,0 +1,2 @@
raylib_zig: main.zig
zig build-exe main.zig -I../raylib-5.5_linux_amd64/include ../raylib-5.5_linux_amd64/lib/libraylib.a -lm -femit-bin=raylib_zig

17
languages/zig/README.md Normal file
View File

@@ -0,0 +1,17 @@
<div align="center">
<h1>Raylib in Zig</h1>
<img src="./demo.gif" alt="Zig Raylib demo" />
</div>
## Quick start
```sh
$ make
$ ./raylib_zig
```
Complete command in [Makefile](./Makefile)
## Credits
- Logo: [Wikimedia](https://commons.wikimedia.org/wiki/File:Zig-logomark-2024.svg)

BIN
languages/zig/demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

53
languages/zig/main.zig Normal file
View File

@@ -0,0 +1,53 @@
const std = @import("std");
const rl = @cImport({
@cInclude("raylib.h");
});
const WINDOW_WIDTH = 800;
const WINDOW_HEIGHT = 600;
const LOGO_HEIGHT = 64;
const LOGO_SPEED: f32 = 300;
const BLACK = rl.Color{ .r = 0, .g = 0, .b = 0, .a = 255 };
const WHITE = rl.Color{ .r = 255, .g = 255, .b = 255, .a = 255 };
pub fn main() void {
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Raylib in Zig");
rl.SetTargetFPS(60);
rl.SetRandomSeed(@intCast(std.time.timestamp()));
var logo_image = rl.LoadImage("./zig_logo.png");
rl.ImageResize(&logo_image, @divTrunc(logo_image.width * LOGO_HEIGHT, logo_image.height), LOGO_HEIGHT);
const logo_texture = rl.LoadTextureFromImage(logo_image);
rl.UnloadImage(logo_image);
var x: f32 = @floatFromInt(rl.GetRandomValue(0, WINDOW_WIDTH - logo_texture.width));
var y: f32 = @floatFromInt(rl.GetRandomValue(0, WINDOW_HEIGHT - logo_texture.height));
var dx: f32 = if (rl.GetRandomValue(0, 1) == 1) -LOGO_SPEED else LOGO_SPEED;
var dy: f32 = if (rl.GetRandomValue(0, 1) == 1) -LOGO_SPEED else LOGO_SPEED;
while (!rl.WindowShouldClose()) {
const delta_time = rl.GetFrameTime();
x += dx * delta_time;
y += dy * delta_time;
if (x < 0 or x + @as(f32, @floatFromInt(logo_texture.width)) >= WINDOW_WIDTH - 1) {
dx *= -1;
x += dx * delta_time;
}
if (y < 0 or y + @as(f32, @floatFromInt(logo_texture.height)) >= WINDOW_HEIGHT - 1) {
dy *= -1;
y += dy * delta_time;
}
rl.BeginDrawing();
rl.ClearBackground(BLACK);
rl.DrawTextureV(logo_texture, rl.Vector2{ .x = x, .y = y }, WHITE);
rl.EndDrawing();
}
rl.UnloadTexture(logo_texture);
rl.CloseWindow();
}

BIN
languages/zig/zig_logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@@ -1,7 +0,0 @@
# Raylib in Python
## Quick start
```sh
$ python ./main.py
```

View File

@@ -1,76 +0,0 @@
from ctypes import *
from time import time
rl = CDLL("../_raylib-5.5_linux_amd64/lib/libraylib.so")
class Texture2D(Structure):
_fields_ = [
("id", c_uint),
("width", c_int),
("height", c_int),
("mipmaps", c_int),
("format", c_int),
]
class Vector2(Structure):
_fields_ = [
("x", c_float),
("y", c_float),
]
class Color(Structure):
_fields_ = [
("r", c_ubyte),
("g", c_ubyte),
("b", c_ubyte),
("a", c_ubyte),
]
rl.LoadTexture.restype = Texture2D
rl.GetFrameTime.restype = c_float
WINDOW_WIDTH = 800
WINDOW_HEIGHT = 600
LOGO_SCALE = 0.04
LOGO_SPEED = 300
BLACK = Color(r=0,g=0,b=0,a=255)
WHITE = Color(r=255,g=255,b=255,a=255)
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Raylib in Python")
rl.SetTargetFPS(60)
rl.SetRandomSeed(int(time()))
logo_texture: Texture2D = rl.LoadTexture(b"./python_logo.png")
logo_width = int(logo_texture.width * LOGO_SCALE)
logo_height = int(logo_texture.height * LOGO_SCALE)
x = rl.GetRandomValue(0, WINDOW_WIDTH - logo_width)
y = rl.GetRandomValue(0, WINDOW_HEIGHT - logo_height)
dx = LOGO_SPEED * (-1 if rl.GetRandomValue(0, 1) else 1)
dy = LOGO_SPEED * (-1 if rl.GetRandomValue(0, 1) else 1)
while not rl.WindowShouldClose():
delta_time = rl.GetFrameTime()
x += dx * delta_time
y += dy * delta_time
if x < 0 or (x + logo_width) >= WINDOW_WIDTH - 1:
dx *= -1
x += dx * delta_time
if y < 0 or (y + logo_height) >= WINDOW_HEIGHT - 1:
dy *= -1
y += dy * delta_time
rl.BeginDrawing()
rl.ClearBackground(BLACK)
rl.DrawTextureEx(logo_texture, Vector2(x=x, y=y), c_float(0), c_float(LOGO_SCALE), WHITE)
rl.EndDrawing()
rl.UnloadTexture(logo_texture)
rl.CloseWindow()

View File

@@ -1,2 +0,0 @@
raylib_rust: main.rs
rustc main.rs -C link-args="-L ../_raylib-5.5_linux_amd64/lib -l:libraylib.a -lm" -o raylib_rust

View File

@@ -1,8 +0,0 @@
# Raylib in Rust
## Quick start
```sh
$ make
$ ./raylib_rust
```

132
tools/demo_gen.c Normal file
View File

@@ -0,0 +1,132 @@
#include <raylib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glob.h>
#include <sys/stat.h>
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
#define LOGO_HEIGHT 64
#define LOGO_SPEED 300.0f
#define GIF_FPS 20
static unsigned int hash_str(const char *s) {
unsigned int h = 5381;
while (*s) h = h * 33 ^ (unsigned char)*s++;
return h;
}
static void generate_gif(const char *output_gif, const char **logo_paths, int logo_count, float switch_secs, int duration_secs) {
if (FileExists(output_gif)) {
TraceLog(LOG_INFO, "Skipping %s (already exists)", output_gif);
return;
}
TraceLog(LOG_INFO, "Generating %s...", output_gif);
char tmpdir[] = "/tmp/demo_gen_XXXXXX";
if (!mkdtemp(tmpdir)) {
perror("mkdtemp");
return;
}
Texture2D *textures = (Texture2D *)malloc(logo_count * sizeof(Texture2D));
for (int i = 0; i < logo_count; i++) {
Image img = LoadImage(logo_paths[i]);
ImageResize(&img, img.width * LOGO_HEIGHT / img.height, LOGO_HEIGHT);
textures[i] = LoadTextureFromImage(img);
UnloadImage(img);
}
RenderTexture2D target = LoadRenderTexture(WINDOW_WIDTH, WINDOW_HEIGHT);
SetRandomSeed(hash_str(output_gif));
int cur_logo = 0;
float x = GetRandomValue(0, WINDOW_WIDTH - textures[cur_logo].width);
float y = GetRandomValue(0, WINDOW_HEIGHT - textures[cur_logo].height);
float vx = LOGO_SPEED * (GetRandomValue(0, 1) ? 1.0f : -1.0f);
float vy = LOGO_SPEED * (GetRandomValue(0, 1) ? 1.0f : -1.0f);
int total_frames = duration_secs * GIF_FPS;
float frame_dt = 1.0f / GIF_FPS;
float logo_timer = 0.0f;
for (int f = 0; f < total_frames; f++) {
Texture2D tex = textures[cur_logo];
x += vx * frame_dt;
y += vy * frame_dt;
if (x < 0 || x + tex.width >= WINDOW_WIDTH) {
vx *= -1.0f;
x += vx * frame_dt;
}
if (y < 0 || y + tex.height >= WINDOW_HEIGHT) {
vy *= -1.0f;
y += vy * frame_dt;
}
logo_timer += frame_dt;
if (logo_timer >= switch_secs) {
logo_timer = 0.0f;
cur_logo = (cur_logo + 1) % logo_count;
}
BeginTextureMode(target);
ClearBackground(BLACK);
DrawTextureV(tex, (Vector2){x, y}, WHITE);
EndTextureMode();
Image frame_img = LoadImageFromTexture(target.texture);
ImageFlipVertical(&frame_img);
ExportImage(frame_img, TextFormat("%s/frame_%04d.png", tmpdir, f));
UnloadImage(frame_img);
TraceLog(LOG_INFO, " frame %d/%d", f + 1, total_frames);
}
UnloadRenderTexture(target);
for (int i = 0; i < logo_count; i++) UnloadTexture(textures[i]);
free(textures);
if (system(TextFormat(
"ffmpeg -y -framerate %d -i '%s/frame_%%04d.png' "
"-vf 'fps=%d,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse' "
"'%s' 2>/dev/null",
GIF_FPS, tmpdir, GIF_FPS, output_gif)) != 0)
TraceLog(LOG_ERROR, "ffmpeg failed for %s", output_gif);
system(TextFormat("rm -rf '%s'", tmpdir));
}
int main(void) {
SetConfigFlags(FLAG_WINDOW_HIDDEN);
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "demo_gen");
glob_t gl;
if (glob("languages/*/*_logo.png", 0, NULL, &gl) != 0) {
TraceLog(LOG_ERROR, "No logos found. Run from project root.");
CloseWindow();
return 1;
}
mkdir("docs", 0755);
// generate docs/demo.gif (cycles all logos)
generate_gif("docs/demo.gif", (const char **)gl.gl_pathv, (int)gl.gl_pathc, 1.0f, (int)gl.gl_pathc);
// generate languages/**/demo.gif
for (size_t i = 0; i < gl.gl_pathc; i++) {
const char *path = gl.gl_pathv[i];
char *output_path = strdup(TextFormat("%s/demo.gif", GetDirectoryPath(path)));
generate_gif(output_path, &path, 1, 9999.0f, 4);
free(output_path);
}
CloseWindow();
globfree(&gl);
return 0;
}