Skip to content

Instantly share code, notes, and snippets.

@tankorsmash
Last active March 11, 2025 04:52
Show Gist options
  • Select an option

  • Save tankorsmash/d1a6648cf8f4edc46dcd87aae09bf8eb to your computer and use it in GitHub Desktop.

Select an option

Save tankorsmash/d1a6648cf8f4edc46dcd87aae09bf8eb to your computer and use it in GitHub Desktop.
Bouncing Tsoding using BQN and Rayed-BQN https://github.com/Brian-ED/rayed-bqn/
color,window,draw, key⟩ ← r•Import "./rayed.bqn" # run from rayed-bqn root
fntSzspd503
boxClr25500255
posdir ← ⟨00, 11
wh ← ⟨1920÷2, 1080÷2
PerFrame ← {𝕊font⟩:
fps" FPS"˜•Repr window.GetFPS@ # display FPS
color.whitefontfntSz draw.Text r.mouse.GetPosfps
boxClr draw.Rectangle 100+˜pos # display rect
window.Close (´ key.IsPressed¨key.q,key.escape⟩) # close if ESC
# bounce off walls
FlipIfBounce ← { ¯1×((𝕩>𝕨-100) (𝕩<0))1}
newDirdir × wh FlipIfBounce pos
# change color and dir if bounce
{𝕊:dirnewDirboxClr↩(3 •rand.Range 255)255} newDirdir
pos (dir×spd)+# apply speed and direction
𝕩
} draw._withCanvas((316)255)
App ← {𝕊:
window.SetSize wh
fonts ← ⟨ r.font.LoadRaylib@ ⟩
PerFrame_While_(¬window.ShouldClose) fonts
}
App window._openAs "Bouncing Tsoding"
@tankorsmash
Copy link
Author

I referenced examples/2_text/textTests.bqn, examples/14_dasher/dasher.bqn, and examples/4_games/snake.bqn to try to figure out how this all is meant to work. It was relatively straight forward, and runs great in WSL2 on Windows 10!

(caveat: I had to hardcode the 144hz, because raylib was incorrectly reporting a 60fps cap here: https://github.com/Brian-ED/rayed-bqn/blob/master/rayed.bqn#L273)

Learned about how you can increment a value as you instantiate them in the snake example to look up their indices in the state, even if I didn't end up needing it.

Happy to know what I could do better here, whether its style, tacitness or anything else!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment