Skip to content

Instantly share code, notes, and snippets.

@0racle
Last active June 15, 2026 06:02
Show Gist options
  • Select an option

  • Save 0racle/0b2196977a6a23c53c37e3d029b0bcb0 to your computer and use it in GitHub Desktop.

Select an option

Save 0racle/0b2196977a6a23c53c37e3d029b0bcb0 to your computer and use it in GitHub Desktop.
BQN Viewmat
GetEnv ← ¯1↓1⊑·•SH"printenv"⋈⊢
pathToLib ← •file.RealPath "/usr/local/lib/libraylib.so"
rl ← ⟨pathToLib⟩ •Import (GetEnv"BQNLIB")∾"/raylib-bqn/raylib.bqn"
⟨Viewmat,grayscale,turbo,viridis⟩⇐
GetVm1 ← {
val ← ⥊ mat ← 𝕩
max ← ⌈´ val
min ← ⌊´ val
⌊ 𝕨 GetHue (mat-min)÷max-min
}
GetHue ← {
x ← 𝕩×1-˜≠𝕨
b ← 𝕨⊏˜⌊x
t ← 𝕨⊏˜⌈x
k ← x-⌊x
(t×k)+b׬k
}
grayscale ← [0‿0‿0,255‿255‿255]
turbo ← [
48‿18‿59,64‿64‿162,70‿107‿227,66‿148‿255,
41‿187‿236,24‿220‿195,49‿241‿153,107‿254‿100,
163‿253‿61,204‿237‿52,237‿208‿58,253‿173‿53,
251‿128‿34,236‿82‿15,210‿49‿5,172‿23‿1,122‿4‿3
]
viridis ← [
68‿1‿84,72‿21‿104,72‿38‿118,69‿55‿128,
63‿71‿136,57‿85‿140,50‿100‿142,45‿113‿142,
40‿125‿142,35‿138‿141,31‿150‿139,32‿163‿134,
41‿175‿128,60‿188‿117,86‿190‿103,116‿208‿85,
148‿216‿64,184‿222‿41,220‿227‿24,253‿231‿37
]
GetPalette ← {
𝕨‿𝕨‿turbo‿grayscale⊑˜2‿1+´∘×(0=≠𝕨)‿(0‿1≡(⌊´∾⌈´)⥊𝕩)
}
Viewmat ← {𝕊𝕩: ⟨⟩𝕊𝕩; 𝕨𝕊𝕩:
h‿w ← ≢𝕩
palette ← (𝕨 GetPalette 𝕩)
rgb ← palette GetVm1 𝕩
colors ← <˘∾⟜255˘∾˝rgb
white ← 255‿255‿255‿255
rl.SetTraceLogLevel rl.rlTraceLogLevel.rL_LOG_ERROR
rl.InitWindow 600‿600‿"viewmat"
rl.SetExitKey rl.keyboardKey.key_q
img ← rl.GenImageColor⟨w,h,white⟩
rl.ImageDrawPixel¨ (⟨⋈img⟩)⊸∾¨(∾˝⍉↕w‿h)∾⟜⋈¨colors
tex ← rl.LoadTextureFromImage img
Draw ← {𝕊:
rl.BeginDrawing⟨⟩
rl.DrawTexturePro⟨tex,
0‿0‿w‿h,
0‿0‿(rl.GetScreenWidth⟨⟩)‿(rl.GetScreenHeight⟨⟩),
0‿0,
0,
white
rl.EndDrawing⟨⟩
}
Draw⟨⟩
{𝕊:
rl.BeginDrawing⟨⟩
Draw⍟rl.IsWindowResized⟨⟩
rl.EndDrawing⟨⟩
}•_while_(¬rl.WindowShouldClose∘⟨⟩)@
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment