Move an Image to a Specific Point on a Curve

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
McJazz
Posts: 111
Joined: Sun Apr 04, 2010 5:59 am

Move an Image to a Specific Point on a Curve

Post by McJazz » Sat Feb 19, 2011 4:07 am

I am relatively new to LiveCode. How do you move an image to specific points on a curve graphic? I know how to move it along all points, just not to one point or specific points.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: Move an Image to a Specific Point on a Curve

Post by dunbarx » Sat Feb 19, 2011 6:14 pm

Do you mean somewhere on a circle, say? If you ask for the points of such a graphic, you will get empty, because it has no vertices.

In that case I think you will have to create a coordinate system and use X/Y pixel locations. This requires a little geometry. A circle, like I mentioned above, can be easily managed.

Another possibility is a freehand curve. If you can overlay your curve with such a graphic, you can get pretty fine control. Make a freehand curve and get the points. There are a lot. Is this resolution fine enough for your needs? If not, you can create a sublist of points between any two of them (or all of them) with a handler. Then you will have pixel resolution, and you cannot get better than that.

Write back if you need more help with this.

What sort of graphics do you have that you want to trace?

Craig Newman

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Move an Image to a Specific Point on a Curve

Post by FourthWorld » Sat Feb 19, 2011 6:46 pm

Throughout the history of xTalks many of us have relied on one person for such geometry needs: Jim Hurley. Now a retired physics professor, he's still the source of most useful geometry routines for LiveCode developers, just as he has been for HyperCard and SuperCard developers in years past. He's a uniquely generous soul, and his generosity is matched by his gift for the art of explanation. Man, if I had him as my physics teacher I would have loved that class. :)

Here's a couple links from him which may help you find circle-plotting algos:

http://jamesphurley.on-rev.com/OnRevTimer/test.html
http://home.infostations.net/jhurley/ShapeLine.rev

He may have others at his Rev page:
http://jamesphurley.on-rev.com/runrev.html

I found the ShapeLine demo mind-blowingly beautiful to play with. Jim is a math god.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Move an Image to a Specific Point on a Curve

Post by jmburnod » Sat Feb 19, 2011 8:13 pm

Hi Richard,
Thank for this link
I found the ShapeLine demo mind-blowingly beautiful to play with. Jim is a math god.
Yes, beautiful and useful

Best

Jean-Marc
https://alternatic.ch

McJazz
Posts: 111
Joined: Sun Apr 04, 2010 5:59 am

Re: Move an Image to a Specific Point on a Curve

Post by McJazz » Sat Feb 19, 2011 10:31 pm

Thanks everyone.

Craig - I would like to get the points of a free hand curve and move an image to any point along the curve. How is this done?

Thanks

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Move an Image to a Specific Point on a Curve

Post by jmburnod » Sat Feb 19, 2011 10:51 pm

Hi McJazz

Code: Select all

move image "myImage" to the points of grc "mypath" in 2 seconds
Best

Jean-Marc
https://alternatic.ch

McJazz
Posts: 111
Joined: Sun Apr 04, 2010 5:59 am

Re: Move an Image to a Specific Point on a Curve

Post by McJazz » Sun Feb 20, 2011 12:58 am

Thank you ... but how can you move to a specific point on the curve, not the entire curve?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: Move an Image to a Specific Point on a Curve

Post by dunbarx » Sun Feb 20, 2011 9:31 pm

You can fill in the blanks between the successive vertices that the "points" function returns. It only takes a little 9th grade math. Say you have a line graphic name "p1". In a button script, say:

Code: Select all

on mouseUp
   put the points of grc "p1" into temp
   put item 1 of line 1 of temp into xStart
   
   put item 1 of line 2 of temp - item 1 of line 1 of temp into xDif
   put item 2 of line 2 of temp - item 2 of line 1 of temp into yDif
   put yDif / xDif into slope
   
   repeat with y = 0 to xDif
      put xStart  + Y & "," & round(xStart + y*slope) & return after fillGaps
   end repeat
   
   answer fillGaps
end mouseUp
The variable fillGaps has the start and ending points, and all those in between, rounded to the nearest pixel.

You can, if you are in earnest, write an elegant handler that takes each pair of successive vertices in a complex graphic and fills in ALL the gaps. This final (probably very long) list will contain every point in the graphic. This is far more worthy a task than remembering the long neglected math.

You can then move your object graphic from point to point in the target graphic, or to any point you wish.

Craig Newman

McJazz
Posts: 111
Joined: Sun Apr 04, 2010 5:59 am

Re: Move an Image to a Specific Point on a Curve

Post by McJazz » Sun Feb 20, 2011 9:45 pm

Craig - Thanks!!! That really helps. I do understand the math. Since I am new to LiveCode, I do not have a grasp on all of the objects and structures yet. From your code, I understand that the points are stored as X,Y coordinates in a row type structure. I am coming from a VB/C background so the syntax is still a awkward for me. I believe that I will want to determine all points and possibly store them in an array.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: Move an Image to a Specific Point on a Curve

Post by dunbarx » Sun Feb 20, 2011 11:30 pm

VB/C?

You will have to post back soon when you see what LC is, and can do, compared with other languages. I expect an epiphany.

Good Luck. Practice making simple stacks; that is the best way, and a method particularly suited to xTalk learning. Facility comes in a flood after a week or two.

Craig Newman

Post Reply