How to build a 360 degree angle finder

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
samjith
Posts: 85
Joined: Tue Mar 31, 2015 10:09 am

How to build a 360 degree angle finder

Post by samjith » Mon Mar 28, 2016 9:52 am

Hi,

Is there any way to build a angle finder by user interface itself. Plz find the attachment.

i can't able to rotate the needle handle.
is there any way to disable its 3D view?

Actually i need is that, i can able to rotate the handle inside this circle (mouse down) like a minute handle in a clock and show the current angle when mouse up.
Attachments
test.zip
(8.27 KiB) Downloaded 197 times

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: How to build a 360 degree angle finder

Post by MaxV » Wed Apr 13, 2016 11:11 am

This is the code for a rotating graphic:

Code: Select all

on MouseMove
   if the muovi of me then
      put the loc of me into centro
      put the mouseLoc into mymouse
      put (item 1 of mymouse) - (item 1 of centro)   into dX
      put (item 2 of mymouse) -  (item 2 of centro)  into dY
      if dx = 0 then
         put 90
      else
         if dX > 0 then
            set the angle of me to -1 * ( -1 * 360 / (2 * pi ) * atan(dY/dx))
         else
            set the angle of me to -1 * (  -1 * 360 / (2 * pi ) * atan(dY/dx) + 180   )
         end if
      end if
   end if
end MouseMove

on MouseDown
 set the muovi of me to true
end MouseDown

on MouseUp
  set the muovi of me to false
end MouseUp
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to build a 360 degree angle finder

Post by Klaus » Wed Apr 13, 2016 11:18 am

Hi firends,

maybe you didn't know, but the "mousemove" message comes with 2 parameters,
the current X and Y position of the mouse!

So you can shorten this script and also make it a bit more efficient:

Code: Select all

on MouseMove X,Y
   if the muovi of me then
      put the loc of me into centro
      ## put the mouseLoc into mymouse
      ## put (item 1 of mymouse) - (item 1 of centro)   into dX
      ## put (item 2 of mymouse) -  (item 2 of centro)  into dY
      put X - (item 1 of centro)   into dX
      put Y - (item 2 of centro)  into dY
...
Best

Klaus

Post Reply