move "to the points of" a graphic BACKWARDS

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
acidjazz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 93
Joined: Mon Feb 16, 2009 2:37 am

move "to the points of" a graphic BACKWARDS

Post by acidjazz » Wed Aug 05, 2009 11:53 pm

Is there a simple way to get a graphic (e.g., rectangle) to move "to the points" of another graphic (e.g., a line) in the OPPOSITE direction? Here's the basic code:

Code: Select all

move graphic "box" to the points of graphic "line" in 1 seconds
Just like you can make a repeat loop go backwards (100 down to 0), is there a way to modify this code? I know I can overlay a second and identical "line" graphic, created by clicking on the end point first, and then dragging to the start point, but that seems very clumsy.

Thanks!
Mark

shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Contact:

Post by shadowslash » Thu Aug 06, 2009 3:00 am

Only possible reason I can think of is that you should re-arrange the points of the line graphic. (E.g. Put the last set of points to the topmost part of the points then the next last set of points to the second line and so on...)
Parañaque, Philippines
Image
Image

acidjazz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 93
Joined: Mon Feb 16, 2009 2:37 am

Post by acidjazz » Thu Aug 06, 2009 5:27 am

Okay, I think I've got it. I put all the points into a list called "tPointList" and then using a repeat loop I move to each point (i.e., each line in tPointList). To go backwards I just read the list starting at the last line of the tPointList and work my way down to line 1.

Code: Select all

on mouseUp

   put the points of graphic "path" into tPointList

   set the MoveSpeed to 500

   -- MOVE FORWARD
   repeat with i = 1 to the number of lines of tPointList
      move graphic "spaceship" to line i of tPointList
   end repeat   

   -- MOVE BACKWARD
   repeat with i = the number of lines of tPointList down to 1
      move graphic "spaceship" to line i of tPointList 
   end repeat
      
end mouseup
This will move an object along the points of a graphic (forwards, and then backwards) no matter how many points it has (e.g., line, rectangle, freehand polygon). Increase the MoveSpeed property to make it go faster.

I still think it's a shame you can't just say

Code: Select all

Move to the points of graphic "path" descending

Cheers,
Mark

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Thu Aug 06, 2009 10:27 am

Mark,

you could reverse the points of the graphic like in:

Code: Select all

on mouseUp 
    put the points of graphic 1 into tpointList
    repeat with i = the number of lines of tpointList down to 1
        put line i of tpointList & cr after tReversePoints
    end repeat
    delete last char of tReversePoints -- a return
    set the points of graphic 1 to tReversePoints
end mouseUp
then you can just let the graphic move along the points of graphic "line".
You can do it either on the fly, it is fast and one does not notice the reversal of the points, or you can create a script local variable for forward and backward movement and just set the points of graphic "line" to the appropriate variable. It is still not the "move backwards" command but it may be easier to code.

regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Thu Aug 06, 2009 1:21 pm

Mark,

try:

Code: Select all

on mouseUp 
    ReversePoints
    move graphic "box" to the points of graphic "line" in 1 seconds
end mouseUp

on ReversePoints
    put the points of graphic "line" into tpointList 
    repeat with i = the number of lines of tpointList down to 1 
        put line i of tpointList & cr after tReversePoints 
    end repeat 
    delete last char of tReversePoints -- a return 
    set the points of graphic "line" to tReversePoints 
end ReversePoints
regards
Bernd

acidjazz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 93
Joined: Mon Feb 16, 2009 2:37 am

Post by acidjazz » Thu Aug 06, 2009 5:05 pm

Thanks Bernd! It's amazing how much I learn from asking a question, then proceding to spend 2 additional hours trying to answer that question myself, and then getting feedback. If I hadn't spent the time, I probably wouldn't have understood your code, but now that I did, I think using a simple "ReversePoints" handler is the way to go. Gracias.

- Mark

Post Reply