Page 1 of 1

Draw a line at will

Posted: Mon Nov 23, 2020 4:33 am
by dunbarx
My first at simply posting a gadget I made. This was derived from a need in this thread:
http://forums.livecode.com/viewtopic.php?f=9&t=34913

This draws a line graphic at any angle of any length starting at any point:

Code: Select all

on mouseUp
   drawLine "100,100",30,100 -- Origin, angle in degrees, length in pixels
   
   -- or just for fun...
   -- repeat with y = 0 to 90 
    --  drawLine "100,100",y * 4,100
    --  wait 1
   -- end repeat
end mouseUp

on drawLine tOrigin,tAngle,tLength
   create grc
   set the style of last grc to "line"
   put tAngle mod 360 into tAngle
   if tAngle = 0 then put 0.001 into tAngle
   put tan(tAngle / (180 / pi)) into tRatio
   put tLength ^ 2 into hypot
   put (1 / tRatio) ^ 2 + 1 into factor
   put sqrt(hypot / factor) into y
   put y / tRatio into x
   if tAngle <= 180 then
      set the points of last grc to tOrigin & "," & item 1 of tOrigin + y & "," & item 2 of tOrigin + x
   else
      set the points of last grc to tOrigin & "," & item 1 of tOrigin - y & "," & item 2 of tOrigin - x
   end if
end drawLine
I am interested in anyone who can point out where I could have done this in five lines.

Craig