PulpCore

pulpcore.math
Class Path

java.lang.Object
  extended by pulpcore.math.Path

public class Path
extends Object

The Path class is a series of straight lines and curves that a Sprite can animate along.

Paths points are immutable, but the path can be translated to another location.

Paths are created from SVG path commands. For example, a triangle path:

path = new Path("M 100 100 L 300 100 L 200 300 L 100 100");
A simple curve:
path = new Path("M100,200 C100,100 400,100 400,200");
See http://www.w3.org/TR/SVG/paths.html#PathData. All SVG commands are supported, however, move-to commands in the middle of a path are treated as line-to commands. That is, subpaths are concatenated together to form one path.

Note, the Path class is not used for rendering paths or shapes.


Constructor Summary
Path(float[] xPoints, float[] yPoints)
          Creates a new Path with the specified points.
Path(String svgPathData)
          Parse an SVG path data string.
 
Method Summary
 void draw(CoreGraphics g, boolean drawJoints)
          Draws the segments of this path using the current color.
 double getAngle(double p)
          Gets the angle of point p on the path, where p is typically from 0 (start of the path) to 1 (end of the path).
 int getEndX()
           
 int getEndY()
           
 double getLength()
           
 int getStartX()
           
 int getStartY()
           
 double getX(double p)
          Gets the x location of point p on the path, where p is typically from 0 (start of the path) to 1 (end of the path).
 double getY(double p)
          Gets the y location of point p on the path, where p is typically from 0 (start of the path) to 1 (end of the path).
 void guide(Timeline timeline, Sprite sprite, double startP, double endP, int duration)
          Deprecated.  
 void guide(Timeline timeline, Sprite sprite, double startP, double endP, int duration, Easing easing)
          Deprecated.  
 void guide(Timeline timeline, Sprite sprite, double startP, double endP, int duration, Easing easing, int startDelay)
          Deprecated.  
 void guide(Timeline timeline, Sprite sprite, int duration)
          Deprecated.  
 void guide(Timeline timeline, Sprite sprite, int duration, Easing easing)
          Deprecated.  
 void guide(Timeline timeline, Sprite sprite, int duration, Easing easing, int startDelay)
          Deprecated.  
 void guideBackwards(Timeline timeline, Sprite sprite, int duration)
          Deprecated.  
 void guideBackwards(Timeline timeline, Sprite sprite, int duration, Easing easing)
          Deprecated.  
 void guideBackwards(Timeline timeline, Sprite sprite, int duration, Easing easing, int startDelay)
          Deprecated.  
 boolean isClosed()
          Returns true if the path is closed, that is, the first point and the last point are identical.
 void move(Sprite sprite, double startP, double endP, int duration)
          Moves a sprite along this path.
 void move(Sprite sprite, double startP, double endP, int duration, Easing easing)
          Moves a sprite along this path.
 void move(Sprite sprite, double startP, double endP, int duration, Easing easing, int startDelay)
          Moves a sprite along this path.
 void moveAndRotate(Sprite sprite, double startP, double endP, int duration)
          Moves a sprite along this path, rotating the sprite so that it is tangent to the path at all times.
 void moveAndRotate(Sprite sprite, double startP, double endP, int duration, Easing easing)
          Moves a sprite along this path, rotating the sprite so that it is tangent to the path at all times.
 void moveAndRotate(Sprite sprite, double startP, double endP, int duration, Easing easing, int startDelay)
          Moves a sprite along this path, rotating the sprite so that it is tangent to the path at all times.
 void moveAndRotateOnTimeline(Timeline timeline, Sprite sprite, double startP, double endP, int duration, Easing easing, int startDelay)
          Moves a sprite along this path, rotating the sprite so that it is tangent to the path at all times.
 void moveOnTimeline(Timeline timeline, Sprite sprite, double startP, double endP, int duration, Easing easing, int startDelay)
          Moves a sprite along this path.
 void place(Sprite sprite, double p)
          Places a Sprite at a position along the path.
 void translate(double x, double y)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Path

public Path(String svgPathData)
     throws IllegalArgumentException
Parse an SVG path data string. supported. See http://www.w3.org/TR/SVG/paths.html#PathData

Throws:
IllegalArgumentException - If the path data string could not be parsed.

Path

public Path(float[] xPoints,
            float[] yPoints)
Creates a new Path with the specified points.

Method Detail

isClosed

public boolean isClosed()
Returns true if the path is closed, that is, the first point and the last point are identical.


getLength

public double getLength()

translate

public void translate(double x,
                      double y)

getStartX

public int getStartX()

getStartY

public int getStartY()

getEndX

public int getEndX()

getEndY

public int getEndY()

getX

public double getX(double p)
Gets the x location of point p on the path, where p is typically from 0 (start of the path) to 1 (end of the path).

Parameters:
p - The position along the path to place the sprite, from 0 to 1.

getY

public double getY(double p)
Gets the y location of point p on the path, where p is typically from 0 (start of the path) to 1 (end of the path).

Parameters:
p - The position along the path to place the sprite, from 0 to 1.

getAngle

public double getAngle(double p)
Gets the angle of point p on the path, where p is typically from 0 (start of the path) to 1 (end of the path).

Parameters:
p - The position along the path to place the sprite, from 0 to 1.

place

public void place(Sprite sprite,
                  double p)
Places a Sprite at a position along the path.

Parameters:
sprite - The Sprite to place.
p - The position along the path to place the sprite, from 0 to 1.

move

public void move(Sprite sprite,
                 double startP,
                 double endP,
                 int duration)
Moves a sprite along this path.

If the path is open (isClosed() returns false), the position is clamped from 0 to 1. Otherwise, if the path is open, the position wraps. For example, for a closed path, moving from 0 to 1.5 is the same as moving from 0 to 1 and then from 0 to 0.5.

Parameters:
sprite - The sprite
startP - The start position along the path, typically from 0 to 1.
endP - The start position along the path, typically from 0 to 1.
duration - The animation duration.
See Also:
Timeline.move(pulpcore.sprite.Sprite, pulpcore.math.Path, double, double, int)

moveAndRotate

public void moveAndRotate(Sprite sprite,
                          double startP,
                          double endP,
                          int duration)
Moves a sprite along this path, rotating the sprite so that it is tangent to the path at all times.

If the path is open (isClosed() returns false), the position is clamped from 0 to 1. Otherwise, if the path is open, the position wraps. For example, for a closed path, moving from 0 to 1.5 is the same as moving from 0 to 1 and then from 0 to 0.5.

Parameters:
sprite - The sprite
startP - The start position along the path, typically from 0 to 1.
endP - The start position along the path, typically from 0 to 1.
duration - The animation duration.
See Also:
Timeline.moveAndRotate(pulpcore.sprite.Sprite, pulpcore.math.Path, double, double, int)

move

public void move(Sprite sprite,
                 double startP,
                 double endP,
                 int duration,
                 Easing easing)
Moves a sprite along this path.

If the path is open (isClosed() returns false), the position is clamped from 0 to 1. Otherwise, if the path is open, the position wraps. For example, for a closed path, moving from 0 to 1.5 is the same as moving from 0 to 1 and then from 0 to 0.5.

Parameters:
sprite - The sprite
startP - The start position along the path, typically from 0 to 1.
endP - The start position along the path, typically from 0 to 1.
duration - The animation duration.
easing - The animation easing.
See Also:
Timeline.move(pulpcore.sprite.Sprite, pulpcore.math.Path, double, double, int, pulpcore.animation.Easing)

moveAndRotate

public void moveAndRotate(Sprite sprite,
                          double startP,
                          double endP,
                          int duration,
                          Easing easing)
Moves a sprite along this path, rotating the sprite so that it is tangent to the path at all times.

If the path is open (isClosed() returns false), the position is clamped from 0 to 1. Otherwise, if the path is open, the position wraps. For example, for a closed path, moving from 0 to 1.5 is the same as moving from 0 to 1 and then from 0 to 0.5.

Parameters:
sprite - The sprite
startP - The start position along the path, typically from 0 to 1.
endP - The start position along the path, typically from 0 to 1.
duration - The animation duration.
easing - The animation easing.
See Also:
Timeline.moveAndRotate(pulpcore.sprite.Sprite, pulpcore.math.Path, double, double, int, pulpcore.animation.Easing)

move

public void move(Sprite sprite,
                 double startP,
                 double endP,
                 int duration,
                 Easing easing,
                 int startDelay)
Moves a sprite along this path.

If the path is open (isClosed() returns false), the position is clamped from 0 to 1. Otherwise, if the path is open, the position wraps. For example, for a closed path, moving from 0 to 1.5 is the same as moving from 0 to 1 and then from 0 to 0.5.

Parameters:
sprite - The sprite
startP - The start position along the path, typically from 0 to 1.
endP - The start position along the path, typically from 0 to 1.
duration - The animation duration.
easing - The animation easing.
startDelay - The animation start delay.
See Also:
Timeline.move(pulpcore.sprite.Sprite, pulpcore.math.Path, double, double, int, pulpcore.animation.Easing, int)

moveAndRotate

public void moveAndRotate(Sprite sprite,
                          double startP,
                          double endP,
                          int duration,
                          Easing easing,
                          int startDelay)
Moves a sprite along this path, rotating the sprite so that it is tangent to the path at all times.

If the path is open (isClosed() returns false), the position is clamped from 0 to 1. Otherwise, if the path is open, the position wraps. For example, for a closed path, moving from 0 to 1.5 is the same as moving from 0 to 1 and then from 0 to 0.5.

Parameters:
sprite - The sprite
startP - The start position along the path, typically from 0 to 1.
endP - The start position along the path, typically from 0 to 1.
duration - The animation duration.
easing - The animation easing.
startDelay - The animation start delay.
See Also:
Timeline.moveAndRotate(pulpcore.sprite.Sprite, pulpcore.math.Path, double, double, int, pulpcore.animation.Easing, int)

moveOnTimeline

public void moveOnTimeline(Timeline timeline,
                           Sprite sprite,
                           double startP,
                           double endP,
                           int duration,
                           Easing easing,
                           int startDelay)
Moves a sprite along this path.

If the path is open (isClosed() returns false), the position is clamped from 0 to 1. Otherwise, if the path is open, the position wraps. For example, for a closed path, moving from 0 to 1.5 is the same as moving from 0 to 1 and then from 0 to 0.5.

Parameters:
sprite - The sprite
startP - The start position along the path, typically from 0 to 1.
endP - The start position along the path, typically from 0 to 1.
duration - The animation duration.
easing - The animation easing.
startDelay - The animation start delay.
See Also:
Timeline.move(pulpcore.sprite.Sprite, pulpcore.math.Path, double, double, int, pulpcore.animation.Easing, int)

moveAndRotateOnTimeline

public void moveAndRotateOnTimeline(Timeline timeline,
                                    Sprite sprite,
                                    double startP,
                                    double endP,
                                    int duration,
                                    Easing easing,
                                    int startDelay)
Moves a sprite along this path, rotating the sprite so that it is tangent to the path at all times.

If the path is open (isClosed() returns false), the position is clamped from 0 to 1. Otherwise, if the path is open, the position wraps. For example, for a closed path, moving from 0 to 1.5 is the same as moving from 0 to 1 and then from 0 to 0.5.

Parameters:
sprite - The sprite
startP - The start position along the path, typically from 0 to 1.
endP - The start position along the path, typically from 0 to 1.
duration - The animation duration.
easing - The animation easing.
startDelay - The animation start delay.
See Also:
Timeline.moveAndRotate(pulpcore.sprite.Sprite, pulpcore.math.Path, double, double, int, pulpcore.animation.Easing, int)

guide

public void guide(Timeline timeline,
                  Sprite sprite,
                  int duration)
Deprecated. 


guide

public void guide(Timeline timeline,
                  Sprite sprite,
                  int duration,
                  Easing easing)
Deprecated. 


guide

public void guide(Timeline timeline,
                  Sprite sprite,
                  int duration,
                  Easing easing,
                  int startDelay)
Deprecated. 


guideBackwards

public void guideBackwards(Timeline timeline,
                           Sprite sprite,
                           int duration)
Deprecated. 


guideBackwards

public void guideBackwards(Timeline timeline,
                           Sprite sprite,
                           int duration,
                           Easing easing)
Deprecated. 


guideBackwards

public void guideBackwards(Timeline timeline,
                           Sprite sprite,
                           int duration,
                           Easing easing,
                           int startDelay)
Deprecated. 


guide

public void guide(Timeline timeline,
                  Sprite sprite,
                  double startP,
                  double endP,
                  int duration)
Deprecated. 


guide

public void guide(Timeline timeline,
                  Sprite sprite,
                  double startP,
                  double endP,
                  int duration,
                  Easing easing)
Deprecated. 


guide

public void guide(Timeline timeline,
                  Sprite sprite,
                  double startP,
                  double endP,
                  int duration,
                  Easing easing,
                  int startDelay)
Deprecated. 


draw

public void draw(CoreGraphics g,
                 boolean drawJoints)
Draws the segments of this path using the current color.

Parameters:
drawJoints - if true, draw rectangles at the joints between line segments

PulpCore

Copyright © 2007-2009 Interactive Pulp, LLC.