Last active
November 1, 2021 00:39
-
-
Save dansanderson/2d835e6b66e654b63f16cb027274569f to your computer and use it in GitHub Desktop.
Calculating the angle formed by three points in PICO-8
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
-- ❎ changes selected point | |
-- direction keys move point | |
function _init() | |
a = {x=20,y=20} | |
b = {x=80,y=80} | |
c = {x=40,y=60} | |
pts = {a,b,c} | |
sel = 1 | |
end | |
function _update() | |
if (btn(⬆️) and pts[sel].y > 0) pts[sel].y -= 1 | |
if (btn(⬇️) and pts[sel].y < 127) pts[sel].y += 1 | |
if (btn(⬅️) and pts[sel].x > 0) pts[sel].x -= 1 | |
if (btn(➡️) and pts[sel].x < 127) pts[sel].x += 1 | |
if (btnp(❎)) sel = ((sel + 1) % #pts) + 1 | |
end | |
function _draw() | |
cls() | |
line(a.x, a.y, b.x, b.y, 13) | |
line(b.x, b.y, c.x, c.y, 14) | |
circfill(a.x, a.y, 2, 8) | |
circfill(b.x, b.y, 2, 11) | |
circfill(c.x, c.y, 2, 12) | |
circ(pts[sel].x, pts[sel].y, 4, 7) | |
ab = atan2(b.x-a.x, b.y-a.y) | |
bc = atan2(b.x-c.x, b.y-c.y) | |
angle = ab-bc | |
print('\f8a\fbb\f6='..ab, 0, 128-18, 6) | |
print('\fcc\fbb\f6='..bc, 0, 128-12, 6) | |
print('angle='..angle, 0, 128-6, 6) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment