76 lines
1.8 KiB
Python
76 lines
1.8 KiB
Python
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() |