Last active
January 31, 2024 13:43
-
-
Save 0racle/2869688e49df0976cbed1a3e8ae80c85 to your computer and use it in GitHub Desktop.
Demo raylib bindings for J
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nixlib =. '/usr/local/lib/libraylib.so' | |
winlib =. jpath '~/raylib/lib/raylib.dll' | |
raylib =: IFUNIX {:: winlib;nixlib | |
Uh =: 0 {:: ] f. NB. Unbox head | |
NB. Window-related functions | |
InitWindow =: (raylib,' InitWindow n i i *c') cd ] | |
CloseWindow =: (raylib,' CloseWindow n') cd ] | |
WindowShouldClose =: Uh (raylib,' WindowShouldClose i') cd ] | |
NB. Cursor-related functions | |
ShowCursor =: (raylib,' ShowCursor n') cd ] | |
HideCursor =: (raylib,' HideCursor n') cd ] | |
IsCursorOnScreen =: Uh (raylib,' IsCursorOnScreen i') cd ] | |
NB. Drawing-related functions | |
ClearBackground =: (raylib,' ClearBackground n i') cd ] | |
BeginDrawing =: (raylib,' BeginDrawing n') cd ] | |
EndDrawing =: (raylib,' EndDrawing n') cd ] | |
NB. Timing-related functions | |
SetTargetFPS =: (raylib,' SetTargetFPS n i') cd ] | |
NB. Basic shapes drawing functions | |
DrawCircle =: (raylib,' DrawCircle n i i f i') cd ] | |
DrawCircleV =: (raylib,' DrawCircleV n d f i') cd ] | |
NB. Input-related functions: keyboard | |
IsKeyDown =: Uh (raylib,' IsKeyDown b i') cd ] | |
GetKeyPressed =: Uh (raylib,' GetKeyPressed i') cd ] | |
NB. Input-related functions: mouse | |
IsMouseButtonPressed =: Uh (raylib,' IsMouseButtonPressed b i') cd ] | |
IsMouseButtonDown =: Uh (raylib,' IsMouseButtonDown b i') cd ] | |
IsMouseButtonReleased =: Uh (raylib,' IsMouseButtonReleased b i') cd ] | |
IsMouseButtonUp =: Uh (raylib,' IsMouseButtonUp b i') cd ] | |
GetMouseX =: Uh (raylib,' GetMouseX i') cd ] | |
GetMouseY =: Uh (raylib,' GetMouseY i') cd ] | |
GetMousePosition =: Uh (raylib,' GetMousePosition d') cd ] | |
GetMouseDelta =: Uh (raylib,' GetMouseDelta d') cd ] | |
SetMouseCursor =: (raylib,' SetMouseCursor n i') cd ] | |
NB. Text drawing functions | |
DrawText =: (raylib,' DrawText n *c i i i i') cd ] | |
NB. J helpers | |
Color =: 256 #. |. | |
Color_J =: |.@((4 # 256) #: ]) :. Color | |
Vector2 =: {.@(_2 fc 1 fc ]) | |
Vector2_J =: (_1 fc 2 fc ]) :. Vector2 | |
white =: Color 255 255 255 255 | |
gold =: Color 255 203 0 255 | |
darkgray =: Color 80 80 80 255 | |
blue =: Color 0 121 241 255 | |
mouseL =: 0 | |
arrows =: 262 + i. 4 | |
dirs =: 0 2 1 3 { (, -) =/~ i. 2 | |
speed =: 5 | |
{{ | |
try. | |
'width height' =: 800,450 | |
cpos =. Vector2 <. 2 %~ width,height | |
InitWindow width;height;'test' | |
SetTargetFPS 60 | |
ShowCursor '' | |
SetMouseCursor 3 NB. Crosshair | |
while. -. WindowShouldClose '' do. | |
dir =. speed * +/ dirs #~ IsKeyDown"0 arrows | |
cpos =. (dir + ])&.Vector2_J cpos | |
BeginDrawing '' | |
ClearBackground darkgray | |
DrawText 'move the ball with the arrow keys';10;10;20;white | |
DrawCircleV cpos;50.0;gold | |
if. IsCursorOnScreen '' do. | |
xy =. ',' joinstring ":&.> Vector2_J mpos =. GetMousePosition '' | |
DrawText xy;(width-100);(height-20);20;white | |
if. IsMouseButtonDown mouseL do. | |
DrawCircleV mpos;20.0;blue | |
end. | |
end. | |
EndDrawing '' | |
end. | |
CloseWindow '' | |
catch. | |
echo dberm '' | |
echo cder '' | |
echo cderx '' | |
end. | |
}} '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Auto-generated bindings of all the low-hanging fruit (ie. basic types) generated from here