-
Notifications
You must be signed in to change notification settings - Fork 5
/
rayed.bqn
1371 lines (1275 loc) · 41.6 KB
/
rayed.bqn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
## Conventions:
# One big goal of this lib is to eliminate as many bugs of raylib as possible,
# for example, opening the window twice is impossible because it is not intended in raylib, and causes many bugs.
# x and y as variables (also x1 y1, x2 y2 etc) are always positions
# -------
# Exports
⟨
draw, texture, monitor, window, mouse
font, key, clipboard, StartClock
sound, bqnoise, raymath, camera, image, model, low, log
⟩⇐
⟨
materialMapIndex
shaderLocationIndex, shaderUniformDataType, shaderAttributeDataType
pixelFormat
textureFilter, textureWrap
cubemapLayout
fontType
blendMode
gesture
cameramode, cameraProjection
nPatchLayout
color
rlglValues⇐rlgl
⟩ ⇐ ⟨
gamepadButton, gamepadAxis
bqnFontChars
windowConfigFlags
traceLogLevel
⟩ ← •Import "src/constants.bqn"
{!"git-submodules "∾(•Repr𝕩)∾" not found.
Use the following command to install the neccessary git submodules:
git submodule update --init --recursive
"}⍟(0≠≠){¬•file.Exists"imports"•file.At𝕩}¨⊸/ "bqn-libs"‿"BQN386"‿"BQNoise"‿"raylib-bqn"
# -------
# internal functions
NeedsWindow ← {window.isOpen?𝕩;!"Expected window to be open"}
# -------
# -------
# Imports
raylib ⇐ ⟨•file⟩ •Import "src/loadRaylib.bqn"
raymath ← •Import "src/raymath.bqn"
image ← raylib‿NeedsWindow •Import "src/image.bqn"
low ← •Import "src/low.bqn"
bqnoise ← •Import "imports/BQNoise/wav.bqn"
bqnoiseOptions ← •Import "imports/BQNoise/options.bqn"
camera ← @ # has rayed.bqn as a dependency. camera is defined later in rayed.bqn.
# -------
# -------
# defaults
raylib.SetTraceLogLevel traceLogLevel.warning # makes logs not output "INFO:" logs to stdOut
# -------
# -------
# constants
i32_max ← ¯1+2⋆31
i32_min ← -2⋆31
# -------
log ← {
# log.setLevel
setLevel ⇐ {
S‿t ← raylib.SetTraceLogLevel‿traceloglevel
All ⇐ S∘t.all # Display all logs
Trace ⇐ S∘t.trace # Trace logging, intended for internal use only
Debug ⇐ S∘t.debug # Debug logging, used for internal debugging, it should be disabled on release builds
Info ⇐ S∘t.info # Info logging, used for program execution info
Warning ⇐ S∘t.warning # Warning logging, used on recoverable failures
Error ⇐ S∘t.error # Error logging, used on unrecoverable failures
Fatal ⇐ S∘t.fatal # Fatal logging, used to abort program: exit(EXIT_FAILURE)
None ⇐ S∘t.none # Disable logging
}
}
texture ← {
⟨ Load ⋄ Unload ⋄ LoadFromImage ⋄ _WithImage ⋄ _withFile ⋄ _WithRayImage ⟩⇐
# texture.Load
Load ← {𝕊filePath: # Load texture from file into GPU memory (VRAM)
NeedsWindow@
{!"Path given wasn't absolute 𝕩≡"∾•Repr𝕩}⍟("."⊸•file.At⊸≢)𝕩
{𝕊:!"Couldn't find file at "∾filePath}⍟¬•file.Exists 𝕩 #TODO verify if the error message errors when file doesn't exist.
raylib.LoadTexture 𝕩
}
# texture.Unload
Unload ← {𝕊texture:
NeedsWindow@
@⊣raylib.UnloadTexture𝕩
}
# texture._withFile
_withFile ← {𝔽_𝕣 filePath : (Unload⊢𝔽)Load𝕩}
# texture._withRayImage
_withRayImage ← {
NeedsWindow@
(Unload⊢𝔽)raylib.LoadTextureFromImage 𝕩
}
# texture._withImage
_withImage ← {
NeedsWindow@
(Unload⊢𝔽)raylib.LoadTextureFromImage image._AsRayImg 𝕩
}
LoadFromImage ← raylib.LoadTextureFromImage image._AsRayImg⊣NeedsWindow
}
monitor ← {
⟨Selected ⋄ Count
RefreshRate ⋄ Size
Sizemm ⋄ Name ⋄ GetPos⟩⇐
# monitor.Selected
Selected ← {𝕤
NeedsWindow@
raylib.GetCurrentMonitor⟨⟩
}
# monitor.Count
Count ← {𝕤
NeedsWindow@
raylib.GetMonitorCount⟨⟩
}
notAMonitorErr ← "Invalid monitor 𝕩, can only be @ for currently selected monitor or a monitor number; ( 𝕩∊↕monitor.Count@ ) v ( 𝕩≡@ )"
M ← @⊸≢◶Selected‿{𝕩⊣notAMonitorErr!⊑𝕩∊↕Count@} # No need for NeedsWindow because Selected and Count need it so error still works
# monitor.RefreshRate
RefreshRate ← {𝕊monitor:
raylib.GetMonitorRefreshRate M 𝕩
}
# monitor.Size
Size ← {𝕊monitor:
(raylib.GetMonitorWidth ∾ raylib.GetMonitorHeight)M 𝕩
}
# Get size in milimeters
# monitor.Sizemm
Sizemm ← {𝕊monitor:
(raylib.GetMonitorPhysicalWidth ∾ raylib.GetMonitorPhysicalHeight)M 𝕩
}
# monitor.Name
Name ← {𝕊monitor:
raylib.GetMonitorName M 𝕩
}
# monitor.GetPos
GetPos ← {𝕤
raylib.GetMonitorPosition M 𝕩
}
}
# window functionality
window ← {
⟨
_openAs ⋄ Open ⋄ Close ⋄ isOpen ⋄ SetIcon ⋄ GetFPS ⋄ SetFPS ⋄ GetSize
ShouldClose ⋄ Needed ⋄ SetPos ⋄ GetPos ⋄ SetSize ⋄ configFlags
SetTitle
IsFullscreen ⋄ SetFullscreen
IsResizable ⋄ SetResizable
IsDecorated ⋄ SetDecorated
IsTransparent ⋄ SetTransparent
IsMsaa4xhint ⋄ Setmsaa4xhint
IsVsyncHint ⋄ Setvsynchint
IsHidden ⋄ SetHidden
IsRunWhileMinimized ⋄ SetRunWhileMinimized
IsMinimized ⋄ SetMinimized
IsMaximized ⋄ SetMaximized
IsFocused ⋄ SetFocused
IsTopmost ⋄ SetTopmost
IsHighDPI ⋄ SetHighDPI
IsMousePassThrough ⋄ SetMousePassThrough
IsInterlacedhint ⋄ SetInterlacedhint
GetState ⋄ stateNames # get binary list of above settings (including empty ones in the raylib binary format)
⟩⇐
# window.Needed
Needed ← NeedsWindow
isOpen ← 0
# Get the x‿y position of the window (relative to current monitor?)
# window.GetPos
GetPos ← {𝕊:isopen?
raylib.GetWindowPosition⟨⟩
;
tempPos
}
# Set the x‿y position of the window (relative to current monitor?)
# window.SetPos
tempPos ← 0‿0
SetPos ← {isopen?
raylib.SetWindowPosition⊸⊢𝕩
;
tempPos ↩ 2⥊𝕩
}
# tempSize is used to store size until window is open
tempSize ← 0‿0
# Set the width and hight of the window, width and hight being relative to window position
# window.SetSize
SetSize ← {𝕊size:
((⌈⊸≡∨⊢≡0⌈1⌊⊢)𝕩)!˜"Size can only be between 0 and 1, or a positive whole number"
((⟨⟩⊸≡∨⟨2⟩⊸≡)≢𝕩)!˜"Size can be a scalar (⟨⟩≢≢𝕨) or length two list (⟨2⟩≡≢𝕨)"
isOpen?
#TODO: instead of error, save the size for when you make the window normal again.
"Cannot set window size while it's maximized"!¬raylib.IsWindowMaximized⟨⟩
"Cannot set window size while it's minimized"!¬raylib.IsWindowMinimized⟨⟩
s ← (raylib.GetMonitorWidth ∾ raylib.GetMonitorHeight) raylib.GetCurrentMonitor⟨⟩
f ← (1⊸>∧0⊸≤)𝕩
# if given size is 0-1, scale the window relative to monitor size
raylib.SetWindowSize ⌈2⥊s×⟜¬⌾(f⊸/)2⥊𝕩
;
tempSize↩2⥊𝕩
}
# Get the width and hight of the window, width and hight being relative to window position
# window.GetSize
GetSize ← {𝕤
isOpen?
⟨raylib.GetScreenWidth⟨⟩
raylib.GetScreenHeight⟨⟩⟩
;
tempSize
}
# Open the window with default settings
# window.Open
Open ⇐ {𝕊 title:
# Errors
(¬isOpen)!˜"The window cannot be opened twice"
"Cannot set fullscreen and set window size to non-0" !¬ IsFullscreen⊸∧0‿0≢tempSize
# startup
raylib.SetConfigFlags flags←2⊸×⊸+˜´GetState@
raylib.InitWindow 400‿400‿𝕩
isOpen↩1
raylib.SetExitKey 0 # 0 means no key, essentially removing esc key closing programs implicitly
# constants
S ← {𝕊:s⊣s↩(raylib.GetMonitorWidth ∾ raylib.GetMonitorHeight) raylib.GetCurrentMonitor⟨⟩}
isScaling ← (1⊸>∧0⊸≤)tempSize # if given size is 0-1, scale the window relative to monitor size
windowSize ← ⌈{∨´isScaling?isScaling/S@;⟨⟩}⊸×⟜¬⌾(isScaling⊸/)tempSize
raylib.SetWindowPosition {
("windows"≡•platform.os) ∧ IsDecorated⊸∧ ¬IsFullscreen@?
0‿42+𝕩 # 42 here is the window header on windows only
; 𝕩
} tempPos
raylib.SetWindowSize windowSize
# Setting fps to the refresh rate of the currently selected monitor
SetFPS raylib.GetMonitorRefreshRate raylib.GetCurrentMonitor⟨⟩
window
}
# window.ShouldClose
ShouldClose ← {𝕤
NeedsWindow@
raylib.WindowShouldClose⟨⟩
}
# window.Close
Close ← {
NeedsWindow@
raylib.CloseWindow⟨⟩
𝕩⊣isOpen↩0
}
# window.OpenAs
_openAs ← {App _𝕣 title:
Open 𝕩
Close⊸⊢𝔽@
}
# TODO: Needs to test input for image
# window.SetIcon
SetIcon ← {𝕊image: NeedsWindow@ ⋄ raylib.SetWindowIcon𝕩} image._AsRayImg
#window.SetTitle
SetTitle ← {
NeedsWindow@
"𝕩 has to be a list of characters"!(=𝕩)∧∧´2=•Type¨𝕩
raylib.SetWindowTitle 𝕩
}
# window.GetFPS
GetFPS ⇐ {𝕤
NeedsWindow@
raylib.GetFPS⟨⟩
}
# window.SetFPS
SetFPS ⇐ {𝕊fps:
NeedsWindow@
(𝕩=0⌈⌈𝕩)!˜"FPS has to be a positive int"
𝕩⊣raylib.SetTargetFPS𝕩
}
# window.Screenshot
Screenshot ← {𝕊:
NeedsWindow@
raylib.LoadImageFromScreen⟨⟩
}
# window.configFlags
configFlags ← windowConfigFlags
fullscreen ← 0 # Set to run program in fullscreen # window.fullscreen
resizable ← 1 # Set to allow resizable window # window.resizable
decorated ← 1 # Set to 0 to disable window decoration (frame and buttons) # window.decorated
transparent ← 0 # Set to allow transparent framebuffer # window.transparent
msaa4xhint ← 0 # Set to try enabling MSAA 4X # window.msaa4xhint
vsyncHint ← 0 # Set to try enabling V-Sync on GPU # window.vsyncHint
hidden ← 0 # Set to hide window # window.hidden
runWhileMinimized ← 0 # Set to allow windows running while minimized # window.runWhileMinimized
minimized ← 0 # Set to minimize window (iconify) # window.minimized
maximized ← 0 # Set to maximize window (expanded to monitor) # window.maximized
focused ← 1 # Set to 0 to non focus window # window.focused
topmost ← 0 # Set to window always on top # window.topmost
highDPI ← 0 # Set to support HighDPI # window.highDPI
mousePassThrough ← 0 # Set to support mouse passthrough, only supported when FLAG_WINDOW_UNDECORATED # window.mousePassThrough
interlacedhint ← 0 # Set to try enabling interlaced video format (for V3D) # window.interlacedhint
# array of Clear‿Set that clears(Clear sets var to 0) and sets(Set var to 1) used as ◶cs
# window state not available on some platforms so will replace clear‿set with other functions like ToggleFullscreen
IWS ← raylib.IsWindowState
cs ← raylib.ClearWindowState‿raylib.SetWindowState
cf ← configFlags
SetFullscreen ⇐ {!⊑𝕩∊↕2 ⋄ fullscreen ↩ 𝕩 ⊣ raylib.ToggleFullscreen∘⟨⟩⍟(𝕩≠IWS)⍟isopen cf.fullscreen_mode} # window.SetFullscreen
SetResizable ⇐ {!⊑𝕩∊↕2 ⋄ resizable ↩ 𝕩 ⊣ 𝕩◶cs⍟isOpen cf.window_resizable } # window.SetResizable
SetDecorated ⇐ {!⊑𝕩∊↕2 ⋄ decorated ↩ 𝕩 ⊣ ¬∘𝕩◶cs⍟isOpen cf.window_undecorated } # window.SetDecorated
SetTransparent ⇐ {!⊑𝕩∊↕2 ⋄ transparent ↩ 𝕩 ⊣ 𝕩◶cs⍟isOpen cf.window_transparent } # window.SetTransparent
Setmsaa4xhint ⇐ {!⊑𝕩∊↕2 ⋄ msaa4xhint ↩ 𝕩 ⊣ 𝕩◶cs⍟isOpen cf.msaa4xhint } # window.Setmsaa4xhint
Setvsynchint ⇐ {!⊑𝕩∊↕2 ⋄ vsyncHint ↩ 𝕩 ⊣ 𝕩◶cs⍟isOpen cf.vsync_hint } # window.Setvsynchint
SetHidden ⇐ {!⊑𝕩∊↕2 ⋄ hidden ↩ 𝕩 ⊣ 𝕩◶cs⍟isOpen cf.window_hidden } # window.SetHidden
SetRunWhileMinimized ⇐ {!⊑𝕩∊↕2 ⋄ runWhileMinimized ↩ 𝕩 ⊣ 𝕩◶cs⍟isOpen cf.window_always_run } # window.SetRunWhileMinimized
SetMinimized ⇐ {!⊑𝕩∊↕2 ⋄ minimized ↩ 𝕩 ⊣ 𝕩◶cs⍟isOpen cf.window_minimized } # window.SetMinimized
SetMaximized ⇐ {!⊑𝕩∊↕2 ⋄ maximized ↩ 𝕩 ⊣ raylib.MaximizeWindow∘⟨⟩⍟(𝕩=IWS)⍟isOpen cf.window_maximized} # window.SetMaximized
SetFocused ⇐ {!⊑𝕩∊↕2 ⋄ focused ↩ 𝕩 ⊣ ¬∘𝕩◶cs⍟isOpen cf.window_unfocused } # window.SetFocused
SetTopmost ⇐ {!⊑𝕩∊↕2 ⋄ topmost ↩ 𝕩 ⊣ 𝕩◶cs⍟isOpen cf.window_topmost } # window.SetTopmost
SetHighDPI ⇐ {!⊑𝕩∊↕2 ⋄ highDPI ↩ 𝕩 ⊣ 𝕩◶cs⍟isOpen cf.highDPI } # window.SetHighDPI
SetMousePassThrough ⇐ {!⊑𝕩∊↕2 ⋄ topmost ↩ 𝕩 ⊣ 𝕩◶cs⍟isOpen cf.window_mouse_passthrough } # window.SetMousePassThrough
SetInterlacedhint ⇐ {!⊑𝕩∊↕2 ⋄ interlacedhint ↩ 𝕩 ⊣ 𝕩◶cs⍟isOpen cf.window_interlacedhint } # window.SetInterlacedhint
IsFullscreen ⇐ {𝕊: isOpen? IWS cf.fullscreen_mode ; fullscreen }
IsResizable ⇐ {𝕊: isOpen? IWS cf.window_resizable ; resizable }
IsDecorated ⇐ {𝕊: isOpen? ¬IWS cf.window_undecorated ; decorated }
IsTransparent ⇐ {𝕊: isOpen? IWS cf.window_transparent ; transparent }
IsMsaa4xhint ⇐ {𝕊: isOpen? IWS cf.msaa4xhint ; msaa4xhint }
IsVsyncHint ⇐ {𝕊: isOpen? IWS cf.vsync_hint ; vsyncHint }
IsHidden ⇐ {𝕊: isOpen? IWS cf.window_hidden ; hidden }
IsRunWhileMinimized ⇐ {𝕊: isOpen? IWS cf.window_always_run ; runWhileMinimized }
IsMinimized ⇐ {𝕊: isOpen? IWS cf.window_minimized ; minimized }
IsMaximized ⇐ {𝕊: isOpen? IWS cf.window_maximized ; maximized }
IsFocused ⇐ {𝕊: isOpen? ¬IWS cf.window_unfocused ; focused }
IsTopmost ⇐ {𝕊: isOpen? IWS cf.window_topmost ; topmost }
IsHighDPI ⇐ {𝕊: isOpen? IWS cf.highDPI ; highDPI }
IsMousePassThrough ⇐ {𝕊: isOpen? IWS cf.window_mouse_passthrough ; mousePassThrough }
IsInterlacedhint ⇐ {𝕊: isOpen? IWS cf.window_interlacedhint ; interlacedhint }
# window.stateNames
stateNames ← ⟨
"fullscreen"
"resizable"
"undecorated"
"transparent"
"msaa4xhint"
"vsyncHint"
"hidden"
"runWhileMinimized"
"minimized"
"maximized"
"unfocused"
"topmost"
"highDPI"
"mousePassThrough"
"interlacedhint"
⟩
# window.GetState
GetState ← {𝕤 # returns binary list that corrisponds to raylib's config_flags format
0‿fullscreen‿resizable‿(¬decorated)‿transparent‿msaa_4x_hint‿vsync_hint‿hidden‿runWhileMinimized‿minimized‿maximized‿(¬focused)‿topmost‿highdpi‿mouse_passthrough‿0‿interlaced_hint
}
}
# Drawing
draw ← {
⟨
_WithCanvas ⋄ _in3D ⋄ _inRectangle
Rectangle ⋄ Triangle ⋄ Line
Ellipse ⋄ EllipseOutline
Text ⋄ Texture ⋄ advanced
⟩⇐
# Start 3d mode, drawing relative to camera using 𝔽, then ends 3d mode
# draw._in3D
_in3D ← {𝕨 Drawing3D _𝕣 camera:
NeedsWindow@ # pos target up FOV Camera projection type
"_in3D: wrong types as input"!𝕩•Type⊸⊑⟜"_icfmdn"⚇0⊸≡"iii"‿"iii"‿"iii"‿'i'‿'i'
raylib.BeginMode3D 𝕩
raylib.EndMode3D∘⟨⟩⊸⊢𝔽𝕩
}
# Start drawing, draw background as color 𝕩, use function 𝔽𝕨, end drawing
# draw._WithCanvas
_withCanvas ← {𝕨DrawingFunc _𝕣 color: arg←𝕨⊣@
NeedsWindow@
"_WithCanvas only accepts 𝕩 as a color; 4 ints in the range 0-255 inclusive"!∧´⟨
𝕩•Type⊸⊑⟜"_icfmdn"⚇0⊸≡"iiii"
∧´(255⊸≥∧0⊸≤)𝕩
⟩
raylib.BeginDrawing⟨⟩
raylib.ClearBackground 𝕩
raylib.EndDrawing∘⟨⟩⊸⊢𝔽arg
}
# draw._inTexture
_inTexture ← {𝔽 _𝕣 texture:
raylib.BeginTextureMode𝕩
raylib.EndTextureMode∘⟨⟩⊸⊢ 𝔽𝕩
}
# draw._withShader
_withShader ← {
raylib.BeginShaderMode𝕩
raylib.EndShaderMode∘⟨⟩⊸⊢𝔽𝕩
}
# draw._inRectangle
_inRectangle ← {
raylib.BeginScissorMode (⊣∾-˜)˝∧˘⌾⍉i32_max⌊0⌈⌊𝕩
raylib.EndScissorMode∘⟨⟩⊸⊢𝔽𝕩
}
_withBlend ← {
raylib.BeginBlendMode𝕩
raylib.EndBlendMode∘⟨⟩⊸⊢𝔽𝕩
}
# Draw text at x‿y in given font, color, and size
# draw.Text
Text ← {𝕨𝕊⟨x‿y⋄text⟩:
NeedsWindow@
t ← ⟨r‿g‿b‿a⋄font⋄fontSize⋄spacing⟩ ⇐ ∾⟜1⍟(3≡≠)𝕨
"Text: wrong types as input"!t‿𝕩•Type⊸⊑⟜"_icfmdn"⚇0⊸≡⟨"iiii"‿("iii"∾(5⥊'i')‿'n'‿'n')‿'i'‿'i'⋄"ii"⋈'c'¨text⟩
raylib.DrawTextCodepoints ⟨font⋄text-@⋄≠text⋄x‿y⋄fontSize⋄spacing⋄r‿g‿b‿a⟩
}
# Draw line from x1‿y1 to x2‿y2
# draw.Line
Line ← {r‿g‿b‿a𝕊[x1‿y1⋄x2‿y2]:
NeedsWindow@
"Line: wrong types as input"!𝕨‿𝕩•Type⊸⊑⟜"_icfmdn"⚇0⊸≡⟨"iiii"⋄2‿2⥊'i'⟩
raylib.DrawLineEx(<˘𝕩)∾1⋈𝕨
}⎉1‿2
ThickLine ← {𝕊:
NeedsWindow@
leftArg ← {
𝕊r‿g‿b‿a:1⋈˜𝕩;
𝕊⟨r‿g‿b‿a⋄thickness⟩:𝕩
}𝕨
"Line: wrong types as input"!leftArg‿𝕩•Type⊸⊑⟜"_icfmdn"⚇0⊸≡⟨"iiii"‿'i'⋄2‿2⥊'i'⟩
raylib.DrawLineEx(<˘𝕩)∾⌽leftArg
}
# draw.Texture
Texture ← {tint‿texture‿scale‿rotation𝕊x‿y:
NeedsWindow@
"Texture: wrong types as input"!⟨tint⋄texture⋄scale⋄rotation⟩‿𝕩•Type⊸⊑⟜"_icfmdn"⚇0⊸≡⟨"iiii"‿"iiiii"‿'i'‿'i'⋄"ii"⟩
raylib.DrawTextureEx ⟨texture⋄x‿y⋄rotation⋄scale⋄tint⟩ # texture‿v2‿f‿f‿color # texture position rotation scale tint
}
# draw.Rectangle
Rectangle ← {r‿g‿b‿a𝕊[x1‿y1⋄x2‿y2]:
NeedsWindow@
"Rectangle: wrong types as input"!𝕨‿𝕩•Type⊸⊑⟜"_icfmdn"⚇0⊸≡"iiii"⋈2‿2⥊'i'
raylib.DrawRectangleV 𝕨∾⟜<˜(⊣⋈-˜)˝∧˘⌾⍉i32_max⌊i32_min⌈⌊𝕩 # capping with max and min to avoid errors at ∞
}⎉1‿2
# draw.Ellipse
Ellipse ← {r‿g‿b‿a𝕊[x1‿y1⋄x2‿y2]:
NeedsWindow@
𝕩(i32_max⌊i32_min⌈⌊)↩
((∧´⌈⊸=∧0⊸≤∧≤⟜255)𝕨)!˜"𝕨 (color) only accepts ints in the range 0-255 inclusive"
raylib.DrawEllipse 𝕨∾⟜<˜(⌈∾⊢-⊏∘𝕩)(+˝÷≠)𝕩
}⎉1‿2
# Draw a color-filled circle
# draw.Circle
Circle ← {r‿g‿b‿a𝕊⟨x‿y⋄radius⟩: # color 𝕊 pos‿radius
NeedsWindow@
(𝕨‿𝕩•Type⊸⊑⟜"_icfmdn"⚇0⊸≡"iiii"‿⟨"ii"⋄'i'⟩)!˜"Wrong input types given to draw.Circle"
((∧´⌈⊸=∨∞=|)x‿y)!˜"Position for draw.Circle has to be two ints"
((∧´0⊸≤∧≤⟜255)𝕨)!˜"𝕨 (color) only accepts ints in the range 0-255 inclusive"
raylib.DrawCircle x‿y‿radius‿𝕨
}
# draw.EllipseOutline
EllipseOutline ← {r‿g‿b‿a𝕊[x1‿y1⋄x2‿y2]:
NeedsWindow@
raylib.DrawEllipseLines 𝕨∾⟜<˜(⌈∾⊢-⊏∘𝕩)(+˝÷≠)𝕩 # i‿i‿f‿f‿color # centerX centerY radiusH radiusV
}⎉1‿2
# draw.Triangle
Triangle ← {color𝕊[x1‿y1⋄x2‿y2⋄x3‿y3]:
[p1,p2,p3] ← 𝕩
raylib.DrawTriangle p1‿𝕨∾˜p2‿p3⌽˜p3<○(•math.Atan2´p2⊸-)p1
}⎉1‿2
# These aren't recommended because they are useless if you use _WithCanvas.
# They also don't behave well if ran in the wrong order,
# you only want to run them in the "start, background, end" sequence
advanced ⇐ {
Start‿Background‿End⇐
# draw.advanced.Start
Start ← {𝕤
NeedsWindow@
raylib.BeginDrawing⟨⟩
}
# draw.advanced.Background
Background ← {𝕊r‿g‿b‿a:
NeedsWindow@
"Background: wrong types as input"!𝕩•Type⊸⊑⟜"_icfmdn"⚇0⊸≡"iiii"
(∧´(255⊸≥∧>0⊸≤)𝕩)!˜"ClearBackground only accepts ints in the range 0-255 inclusive"
raylib.ClearBackground 𝕩
}
# draw.advanced.End
End ← {𝕤
NeedsWindow@
raylib.EndDrawing⟨⟩
}
}
}
font ← {
⟨ Load ⋄ LoadBQN ⋄ LoadRaylib ⋄ Unload ⟩⇐
IsFont ← {
(𝕩•Type⊸⊑⟜"_icfmdn"⚇0⊸≡"iii"∾"iiiii"<⊸∾⋈˜'n')!˜"Expected a valid font"
𝕩⊣(¬∨´low.IsNull¨¯2↑𝕩)!˜"Invalid font. font has null pointers, making it invalid"
}
glyphInfo ← {value‿offsetX‿offsetY‿advanceX‿image⇐↕5} # The namespace is for eliminating magic-numbers
# font.Unload
Unload ⇐ {
NeedsWindow@
IsFont 𝕩
raylib.UnloadFont 𝕩
}
# font.Load
Load ⇐ {
NeedsWindow@
F ← {
𝕊size‿filePath:
⟨filePath⋄size⋄≍@⋄0⟩
; # fontSize fontChars glyphCount # use NULL for fontChars and 0 for glyphCount to load the default character set
charactersAllowed 𝕊 size‿filePath:
⟨filePath⋄size⋄𝕨-@⋄≠𝕨⟩
}
·‿filePath ← 𝕩
{!"Path given wasn't absolute 𝕩≡"∾•Repr𝕩}⍟("."⊸•file.At⊸≢)filePath
{𝕊:!"Couldn't find file at "∾filePath}⍟¬•file.Exists filePath
IsFont raylib.LoadFontEx 𝕨F𝕩
}
# font.LoadBQN
LoadBQN ← {𝕊fontSize: fontSize 100⍟(@⊸≡)↩
NeedsWindow@
file ← •file.RealPath ("Expected file at: "⊸∾!•file.Exists)⊸⊢ •file.At "imports/BQN386/BQN386.ttf"
raylib.LoadFontEx⟨file⋄fontSize⋄bqnFontChars-@⋄≠bqnFontChars⟩
}
# font.LoadRaylib
LoadRaylib ← {𝕊@:
raylib.GetFontDefault⟨⟩
}
}
clipboard ← {
⟨Get ⋄ Set⟩⇐
⟨ToBytes⟩ ← •Import "imports/bqn-libs/strings.bqn"
# clipboard.Get
Get ⇐ {𝕤
NeedsWindow@
low.IsNull◶⟨
low.StrLen⊸low.MakeUTF8
""
⟩ raylib.GetClipboardText⟨⟩
}
# clipboard.Set
Set ⇐ {𝕊text:
NeedsWindow@
raylib.SetClipboardText ToBytes 𝕩
}
}
# start clock then tick at the start of every frame to get accurate clock.delta and clock.time
StartClock ← {𝕊@:
⟨
Time ⋄ Tick
startTime ⋄ delta ⋄ frame
⟩⇐
# time is relative to when you started the clock
lastTime ← 0
startTime ⇐ •MonoTime@ # clock.startTime
delta ⇐ 0 # clock.delta
frame ⇐ 0 # clock.frame
# clock.Time
Time ⇐ {𝕊:startTime-˜•Monotime@}
# clock.Tick
Tick ⇐ {𝕊:
frame+↩1
delta ↩ lastTime-˜startTime-˜•MonoTime@
lastTime ↩ startTime-˜•MonoTime@
delta
}
}
mouse ← {
buttons ← 7
# mouse.button.
button ⇐ {
left‿right‿middle‿side‿extra‿forward‿back ⇐ ↕buttons
}
# mouse.GetPos
GetPos ⇐ {𝕊:
NeedsWindow@
raylib.GetMousePosition⟨⟩
}
# mouse.SetPos
SetPos ⇐ {𝕊x‿y:
NeedsWindow@
raylib.SetMousePosition x‿y
}
# mouse.GetDelta
GetDelta ⇐ {𝕊:
NeedsWindow@
raylib.GetMouseDelta⟨⟩
}
# mouse.SetOffset
SetOffset ⇐ {𝕊offsetX‿offsetY:
NeedsWindow@
raylib.SetMouseOffset ⌊𝕩
}
# mouse.SetScale
SetScale ⇐ {𝕊scaleX‿scaleY:
NeedsWindow@
raylib.SetMouseScale 𝕩
}
# mouse.WheelMoved
WheelMoved ⇐ {𝕊:
NeedsWindow@
raylib.GetMouseWheelMove⟨⟩
}
IsMouseButton ← "Mouse button doesn't exist. (𝕩∊↕7)"⊸!∘⊑∘∊⟜(↕buttons)⚇0
# mouse.IsButtonDown
IsButtonDown ⇐ {𝕊mouseButton:
NeedsWindow@
IsMouseButton 𝕩
raylib.IsMouseButtonDown⚇0 𝕩
}
# mouse.IsButtonPressed
IsButtonPressed ⇐ {𝕊mouseButton:
NeedsWindow@
IsMouseButton 𝕩
raylib.IsMouseButtonPressed⚇0 𝕩
}
# mouse.IsButtonReleased
IsButtonReleased ⇐ {𝕊mouseButton:
NeedsWindow@
IsMouseButton 𝕩
raylib.IsMouseButtonReleased⚇0 𝕩
}
# mouse.IsButtonUp
IsButtonUp ⇐ {𝕊mouseButton:
NeedsWindow@
IsMouseButton 𝕩
raylib.IsMouseButtonUp⚇0 𝕩
}
cursor ⇐ {
# mouse.cursor.Show
Show ⇐ {𝕊:
NeedsWindow@
𝕩⊣raylib.ShowCursor⟨⟩
}
# mouse.cursor.Hide
Hide ⇐ {𝕊:
NeedsWindow@
𝕩⊣raylib.HideCursor⟨⟩
}
# mouse.cursor.IsHidden
IsHidden ⇐ {𝕊:
NeedsWindow@
𝕩⊣raylib.IsCursorHidden⟨⟩
}
# mouse.cursor.Enable
Enable ⇐ {𝕊:
NeedsWindow@
𝕩⊣raylib.EnableCursor⟨⟩
}
# mouse.cursor.Disable
Disable ⇐ {𝕊:
NeedsWindow@
𝕩⊣raylib.DisableCursor⟨⟩
}
# mouse.cursor.IsOnScreen
IsOnScreen ⇐ {𝕊:
NeedsWindow@
𝕩⊣raylib.IsCursorOnScreen⟨⟩
}
# mouse.cursor.Set
Set ⇐ {
NeedsWindow@
𝕩⊣raylib.SetMouseCursor 𝕩
}
# mouse.cursor.shape
shape ⇐ {
default ⇐ 0 # Default pointer shape
arrow ⇐ 1 # Arrow shape
ibeam ⇐ 2 # Text writing cursor shape
crosshair ⇐ 3 # Cross shape
pointing_hand ⇐ 4 # Pointing hand cursor
resize_ew ⇐ 5 # Horizontal resize/move arrow shape
resize_ns ⇐ 6 # Vertical resize/move arrow shape
resize_nwse ⇐ 7 # Top-left to bottom-right diagonal resize/move arrow shape
resize_nesw ⇐ 8 # The top-right to bottom-left diagonal resize/move arrow shape
resize_all ⇐ 9 # The omnidirectional resize/move cursor shape
not_allowed ⇐ 10 # The operation-not-allowed shape
}
}
}
# Wave, audio wave data
sound ⇐ {
⟨
Play ⋄ Stop ⋄ Pause ⋄ Resume ⋄ IsPlaying
SetVolume ⋄ SetPitch ⋄ SetPan
LoadFromFile ⋄ Unload
_withDevice ⋄ wave
⟩⇐
audioReady ← 0
NeedsAudio ← { # Everything that needs audio also needs the window to be open
NeedsWindow@
𝕩⊣"Audio not started, run audio with sound._withDevice"!audioReady
}
wave ⇐ {
⟨LoadFromFile ⋄ Unload ⋄ _withFile⟩⇐
# sound.wave.LoadFromFile
LoadFromFile ⇐ {𝕊filePath:
{!"Path given wasn't absolute 𝕩≡"∾•Repr𝕩}⍟("."⊸•file.At⊸≢)𝕩
{𝕊:!"Couldn't find file at "∾filePath}⍟¬•file.Exists 𝕩
bqnSound ← {
freq‿format‿bqnSound ← bqnoise.ReadFull filePath
⌊∘÷⟜(2⋆¯16+1⊑format) freq‿bqnoiseOptions.freq bqnoiseOptions.Resample⍟(≢´⊣) bqnSound
}
⟨
1⊑≢bqnSound # frameCount
bqnoiseOptions.freq # sampleRate
1⊑bqnoiseOptions.fmt # sampleSize
≠bqnSound # channels
{ # *data
data ← ⥊⍉bqnSound
{↕∘≠⊸(𝕩.Write¨) data}⊸⊢(raylib.MemAlloc 2×≠data).Cast "i16"
}
⟩
}
# sound.wave.Unload
Unload ⇐ {𝕊frameCount‿sampleRate‿sampleSize‿channels‿data:
raylib.MemFree data
}
# sound.wave._withFile
_withFile ⇐ {(Unload⊢𝔽)LoadFromFile}
}
# sound._withDevice
_withDevice ⇐ {𝕨𝔽_𝕣𝕩:
NeedsWindow@
raylib.InitAudioDevice⟨⟩
audioReady ↩ 1
r←𝕨𝔽𝕩
raylib.CloseAudioDevice⟨⟩
audioReady ↩ 0
r
}
# sound.LoadFromFile
LoadFromFile ⇐ {𝕊:
NeedsAudio@
raylib.LoadSoundFromWave 𝕩
} wave._withFile
# sound.Play
Play ⇐ {𝕊sound:
NeedsAudio@
raylib.PlaySound 𝕩
}
# sound.Stop
Stop ⇐ {𝕊sound:
NeedsAudio@
raylib.StopSound 𝕩
}
# sound.Pause
Pause ⇐ {𝕊sound:
NeedsAudio@
raylib.PauseSound𝕩
}
# sound.Resume
Resume ⇐ {𝕊sound:
NeedsAudio@
raylib.ResumeSound 𝕩
}
# sound.IsPlaying
IsPlaying ⇐ {𝕊sound:
NeedsAudio@
raylib.IsSoundPlaying 𝕩
}
# sound.SetVolume
SetVolume ⇐ {volume𝕊sound:
"Volume must be a number"!0≡•Type𝕨
NeedsAudio@
raylib.SetSoundVolume 𝕩‿𝕨
}
# sound.SetPitch
SetPitch ⇐ {pitch𝕊sound:
"Pitch must be a number"!0≡•Type𝕨
NeedsAudio@
raylib.SetSoundPitch 𝕩‿𝕨
}
# sound.SetPan
SetPan ⇐ {pan𝕊sound:
"Pan must be a number"!0≡•Type𝕨
NeedsAudio@
raylib.SetSoundPan 𝕩‿𝕨
}
# sound.Unload
Unload ⇐ raylib.UnloadSound
}
#gamepad ← {
# button‿axis⇐gamepadButton‿gamepadAxis
#
# unknown ⇐ 0 # Unknown button, just for error checking
# left_face_up ⇐ 1 # Gamepad left DPAD up button
# left_face_right ⇐ 2 # Gamepad left DPAD right button
# left_face_down ⇐ 3 # Gamepad left DPAD down button
# left_face_left ⇐ 4 # Gamepad left DPAD left button
# right_face_up ⇐ 5 # Gamepad right button up (i.e. PS3: Triangle, Xbox: Y)
# right_face_right ⇐ 6 # Gamepad right button right (i.e. PS3: Square, Xbox: X)
# right_face_down ⇐ 7 # Gamepad right button down (i.e. PS3: Cross, Xbox: A)
# right_face_left ⇐ 8 # Gamepad right button left (i.e. PS3: Circle, Xbox: B)
# left_trigger_1 ⇐ 9 # Gamepad top/back trigger left (first), it could be a trailing button
# left_trigger_2 ⇐ 10 # Gamepad top/back trigger left (second), it could be a trailing button
# right_trigger_1 ⇐ 11 # Gamepad top/back trigger right (one), it could be a trailing button
# right_trigger_2 ⇐ 12 # Gamepad top/back trigger right (second), it could be a trailing button
# middle_left ⇐ 13 # Gamepad center buttons, left one (i.e. PS3: Select)
# middle ⇐ 14 # Gamepad center buttons, middle one (i.e. PS3: PS, Xbox: XBOX)
# middle_right ⇐ 15 # Gamepad center buttons, right one (i.e. PS3: Start)
# left_thumb ⇐ 16 # Gamepad joystick pressed button left
# right_thumb ⇐ 17 # Gamepad joystick pressed button right
#
# ps4 ← {
# x ⇐ right_face_down
# o ⇐ right_face_left
# square ⇐ right_face_right
# triangle ⇐ right_face_up
# }
# xboxButton ←
# isGamepadAvailable
# getGamepadName
# isGamepadButtonPressed
# isGamepadButtonDown
# isGamepadButtonReleased
# isGamepadButtonUp
# getGamepadButtonPressed
# getGamepadAxisCount
# getGamepadAxisMovement
# setGamepadMappings
# setGamepadVibration
#}
key ← {
IsKey ⇐ ("Key doesn't exist"!0⊸≤∧<⟜512)⚇0 @-˜⍟≤⚇0⊢
# key.IsPressed
IsPressed ⇐ {𝕊key:
NeedsWindow@
IsKey 𝕩
(raylib.IsKeyPressed @-˜⍟≤⊢)⚇0 𝕩
}
# key.IsPressedRepeat
IsPressedRepeat ⇐ {𝕊key:
NeedsWindow@
IsKey 𝕩
(raylib.IsKeyPressedRepeat @-˜⍟≤⊢)⚇0 𝕩
}
# key.IsReleased
IsReleased ⇐ {𝕊key:
NeedsWindow@
IsKey 𝕩
(raylib.IsKeyReleased @-˜⍟≤⊢)⚇0 𝕩
}
# key.IsKeyUp
IsKeyUp ⇐ {𝕊key:
NeedsWindow@
IsKey 𝕩
(raylib.IsKeyUp @-˜⍟≤⊢)⚇0 𝕩
}
# key.IsDown
IsDown ⇐ {
NeedsWindow@
IsKey 𝕩
(raylib.IsKeyDown @-˜⍟<⊢)⚇0 𝕩
}
# key.PressedKey
PressedKey ⇐ {𝕤
NeedsWindow@
raylib.GetKeyPressed⟨⟩
}
# key.PressedChar
PressedChar ⇐ {𝕤
NeedsWindow@
@+raylib.GetcharPressed⟨⟩
}
# Keyboard keys (US keyboard layout)
# NOTE: Use GetKeyPressed() to allow redefining
# required keys for alternative layouts
# vars Keycodes Keys
null ⇐ 0 # NULL, used for no key pressed
# Alphanumeric keys
apostrophe ⇐ 39 # '
comma ⇐ 44 # ,
minus ⇐ 45 # -
period ⇐ 46 # .
slash ⇐ 47 # /
zero‿one‿two‿three‿four‿five‿six‿seven‿eight‿nine ⇐ 48+↕10 # 0-9
semicolon ⇐ 59 # ;
equal ⇐ 61 # =
a‿b‿c‿d‿e‿f‿g‿h‿i‿j‿k‿l‿m‿n‿o‿p‿q‿r‿s‿t‿u‿v‿w‿x‿y‿z ⇐ 65+↕26 # A-Z | a-z
left_bracket ⇐ 91 # [
backslash ⇐ 92 # \
right_bracket ⇐ 93 # ]
grave ⇐ 96 # `
# Function keys
space ⇐ 32 # Space
escape ⇐ 256 # Esc
enter ⇐ 257 # Enter
tab ⇐ 258 # Tab
backspace ⇐ 259 # Backspace
insert ⇐ 260 # Ins
delete ⇐ 261 # Del
right ⇐ 262 # Cursor right
left ⇐ 263 # Cursor left
down ⇐ 264 # Cursor down
up ⇐ 265 # Cursor up
page_up ⇐ 266 # Page up
page_down ⇐ 267 # Page down
home ⇐ 268 # Home
end ⇐ 269 # End
caps_lock ⇐ 280 # Caps lock
scroll_lock ⇐ 281 # Scroll down
print_screen ⇐ 283 # Print screen
pause ⇐ 284 # Pause
f1‿f2‿f3‿f4‿f5‿f6‿f7‿f8‿f9‿f10‿f11‿f12 ⇐ 290+↕12 # F1 - F12
left_shift ⇐ 340 # Shift left
left_control ⇐ 341 # Control left
left_alt ⇐ 342 # Alt left
left_super ⇐ 343 # Super left
right_shift ⇐ 344 # Shift right
right_control ⇐ 345 # Control right
right_alt ⇐ 346 # Alt right
right_super ⇐ 347 # Super right
kb_menu ⇐ 348 # KB menu
keypad ⇐ {
num_lock ⇐ 282 # Num lock
zero‿one‿two‿three‿four‿five‿six‿seven‿eight‿nine←320+↕10 # Keypad 0-9
decimal ⇐ 330 # Keypad .
divide ⇐ 331 # Keypad /
multiply ⇐ 332 # Keypad *
subtract ⇐ 333 # Keypad -
add ⇐ 334 # Keypad +
enter ⇐ 335 # Keypad Enter
equal ⇐ 336 # Keypad =
}
android ⇐ {