Draw a line at will

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Draw a line at will

Post by dunbarx » Mon Nov 23, 2020 4:33 am

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

Post Reply

Return to “Talking LiveCode”