Created
July 20, 2024 22:47
-
-
Save luizbills/ba6c5188089aba871dff231019043639 to your computer and use it in GitHub Desktop.
How to draw a line in the direction of a given angle
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
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DEMO
https://litecanvas.js.org?c=eJxVUMGKwjAQvecrZm%2BJW6F03WMPIiJeRMSDHkOaSmAYS5OqVfrvTjZa1tPMe5M3b17QBWs0XbSXSgi0AcwtA9Nn0HBtuKKlsshzIeqOTHBngtZ6d7cVSAUPASyAEhbLzX65O0TYj%2FAohn%2Byrql0sCCrkHSuBrmfb7frzSoRwJ6sZe6QUJ%2FQkdEA8LGsavV1PAC9zFVsXGtqhyjfGX6KDH7Vy4uXf5VAHeLbLsbVdELLPjpoKiRbTl%2FpY3NT6Z0jO%2B7kuN9gzl7%2BKdWE%2FycOmPSOPshZVA989hMGqWQy