Drawing+an+arrow

Function to draw an arrow
code format="vbnet" nomainwin open "Drawing arrows demo" for graphics_nsb as #gr
 * 1) gr "trapclose [quit]"
 * 2) gr "down"
 * 3) gr "size 2"

for i = 1 to 10 x1 = rnd(1)*300 y1 = rnd(1)*300 x2 = rnd(1)*300 y2 = rnd(1)*300

call drawArrow "#gr", x1,y1,x2,y2 next

wait

[quit] close #gr end

'*****************************************************

'Function for drawing an arrow 'needs function atan2(x,y) below sub drawArrow handle$, x1,y1,x2,y2 'arrow head paramters, could be changed headLen=20     'pixels headAngle=30   'degrees

dx = x2 - x1   dy = y2 - y1    a = atan2(dx, dy)   '0..360

#handle$ "place ";x1;" ";y1

#handle$ "goto ";x2;" ";y2 #handle$ "north" #handle$ "turn ";a+90   'look forward t = -180-headAngle      'half an arrowhead #handle$ "turn ";t #handle$ "go ";headLen

#handle$ "go ";0-headLen 'back #handle$ "turn ";2*headAngle   'other half of an arrowhead #handle$ "go ";headLen

end sub

function atan2(x,y) 'returns 0..360 degrees if abs(x)<0.001 then atan2 = 90+(y<0)*180 : exit function pi = acs(-1) tan = y/x atn = atn(tan) select case case x>0 and y>0 atan2 = atn/pi*180 case x<=0 atn = atn + pi       atan2 = atn/pi*180 case else atn = atn + 2*pi atan2 = atn/pi*180 end select end function

code