Skip to content

Instantly share code, notes, and snippets.

@luizbills
Created July 20, 2024 22:47
Show Gist options
  • Save luizbills/ba6c5188089aba871dff231019043639 to your computer and use it in GitHub Desktop.
Save luizbills/ba6c5188089aba871dff231019043639 to your computer and use it in GitHub Desktop.
How to draw a line in the direction of a given angle
litecanvas()
let cx, cy, px, py, len=200
function resized () {
cx = CENTERX
cy = CENTERY
}
function update (dt) {
if (TAPPING) {
px = TAPX
py = TAPY
}
}
function draw () {
cls(0)
circfill(cx, cy, 32, 5)
if (px != null) {
let angle = atan2(py - cy, px - cx)
line(cx, cy, cx + cos(angle)*len, cy + sin(angle)*len, 4)
}
}