Could modified my simple module for drawing arrows.

Code: Select all

```
local Arrow = {}
local gr,pi,sin,cos,atan2,floor,sqrt = love.graphics,math.pi,math.sin,math.cos,math.atan2,math.floor,math.sqrt
function Arrow.angle( pt1, pt2 )
return atan2( pt1.y-pt2.y, pt1.x-pt2.x ) - pi
end
function Arrow.length(pt1,pt2)
return math.sqrt((pt1.x-pt2.x)^2+(pt1.y-pt2.y)^2)
end
function Arrow.StartEnd( pt1, pt2, cl ) -- from, to, color
local cl = cl or { 0, 255, 0 }
gr.setColor( unpack( cl ) )
Arrow.Draw( pt1, pt2 )
local an = floor( 180 * (atan2( pt1.y-pt2.y , pt1.x-pt2.x ) ) / pi + 270 )
an = an <= 360 and an or an - 360
gr.print( an, pt1.x - 10, pt1.y + 30 )
end
function Arrow.Direction( pt1, an, ln, cl ) -- location, direction, length, [color]
local cl = cl or { 0, 255, 0 }
gr.setColor( unpack( cl ) )
local pt2 = {x=ln * cos(an) + pt1.x,y=ln * sin(an) + pt1.y }
Arrow.Draw( pt1, pt2, ln )
local aa = floor( 180 * an / pi + 450 ) -- convert angle to North = 0 degrees
return aa and aa or aa - 360
end
function Arrow.Draw( pt1, pt2, ln ) -- start, end, [length]
local x1 ,y1, x2, y2 = pt1.x, pt1.y, pt2.x, pt2.y
local ln = ln and ln or sqrt( (x2-x1)^2 + (y2-y1)^2 )
local hd = 0.2 * ln
gr.line( x1, y1, x2, y2 ) -- arrow shaft (point1 to point2)
local dx = x2 - x1 -- arrow head (at point2)
local dy = y2 - y1
local a1 = -0.42 * pi - atan2( dy , dx )
local x3 = hd * sin( a1) + x2
local y3 = hd * cos( a1 ) + y2
gr.line( x2, y2, x3, y3 )
local a2 = -0.58 * pi - atan2( dy , dx )
local x4 = hd * sin( a2 ) + x2
local y4 = hd * cos( a2 ) + y2
gr.line( x2, y2, x4, y4 )
end
return Arrow
```