gizmoball.board
Class ExtenderGizmo

java.lang.Object
  extended by gizmoball.board.Gizmo
      extended by gizmoball.board.ExtenderGizmo

public class ExtenderGizmo
extends Gizmo

This class represents an extender gizmo that extends the abstract Gizmo class. The extender can be in two modes: stationary and in motion. Once the extender is in motion, it changes its shape as follows: It starts out as a square, expands horizontally to max of xSpanOfMotion, contracts to a square, expands vertically to max of ySpanOfMotion, and contracts to a square again. The extender will follow that motion until it is in stationary mode.

Author:
Michal Wexler

Field Summary
 
Fields inherited from class gizmoball.board.Gizmo
color, connections, name, reverseConnections
 
Constructor Summary
ExtenderGizmo(java.lang.String name, java.awt.Color color, Vect upperLeft, double squareLength, double xSpanOfMotion, double ySpanOfMotion, double velocity, double pausingTime, java.lang.Boolean isStationary)
          constructs a new ExtenderGizmo object.
 
Method Summary
 void action()
          executes the action of the extender which switches the state(stationary/motion) of the extender.
 Polygon getEnclosingPolygon()
          returns the enclosing polygon of the extender (the whole area that the extender occupies at least at one point during its motion cycle.
 double getExpansionSpeed(LineSegment ls)
          returns the speed in which the side is expanding, ie the speed at which it changes its length.
 Polygon getFutureShape(double dt)
          returns the shape that the extender will have after dt time from now without changing the actual state of the extender.
 double getPausingTime()
          returns the pausing time between expansion/contraction transitions
 Polygon getShape()
          returns the current shape of the extender.
 Vect getUpperLeft()
          returns the location of the upper left corner of the square (the upper-left point of the extender's shape at its smallest size).
 double getVelocity()
          returns the velocity of the extender.
 Vect getVelocity(Circle c)
          returns the velocity of one of the vertices of the extender.
 Vect getVelocity(LineSegment ls)
          returns the velocity of one of the sides of the extender.
 double getXSpanOfMotion()
          returns the horizontal span of motion of the extender.
 double getYSpanOfMotion()
          returns the vertical span of motion of the extender.
 double height()
          returns the current height of the extender.
 boolean isContractingX()
          returns a boolean stating whether the extender is contracting horizontally.
 boolean isContractingY()
          returns a boolean stating whether the extender is contracting vertically.
 boolean isExpandingX()
          returns a boolean stating whether the extender is expanding horizontally.
 boolean isExpandingY()
          returns a boolean stating whether the extender is expanding vertically.
 java.lang.Boolean isStationary()
          returns a boolean that indicates if the extender is in motion (changes its shape) or stationary.
 void setVelocity(double vel)
          sets the speed of expansion/contraction.
 double timeTo()
          returns the time until a transition between states occurs.
 void updateExtender(double dt)
          updates the shape of the extender to the shape that the extender should have after dt time.
 double width()
          returns the current width of the extender.
 
Methods inherited from class gizmoball.board.Gizmo
getColor, getName, getTriggeredGizmos, getTriggeringGizmos, setColor, triggerConnections
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExtenderGizmo

public ExtenderGizmo(java.lang.String name,
                     java.awt.Color color,
                     Vect upperLeft,
                     double squareLength,
                     double xSpanOfMotion,
                     double ySpanOfMotion,
                     double velocity,
                     double pausingTime,
                     java.lang.Boolean isStationary)
constructs a new ExtenderGizmo object.

Parameters:
name - the name of the ExtenderGizmo
color - the color of the ExtenderGizmo
upperLeft - the location of the upper-left corner of the square shape
squareLength - the length of the sides of the square
xSpanOfMotion - the maximum horizontal expansion, which means that the max width of the extender is 2*xSpanOfMotion + squareLength
ySpanOfMotion - the maximum vertical expansion, which means that the max height of the extender is 2*ySpanOfMotion + squareLength
velocity - the speed of the extender when its in motion
pausingTime - the pausing time between expansion/contraction transitions
isStationary - a boolean representing the mode of the extender(stationary/in motion)
Method Detail

getShape

public Polygon getShape()
returns the current shape of the extender.

Overrides:
getShape in class Gizmo
Returns:
the current shape of the extender

getVelocity

public double getVelocity()
returns the velocity of the extender.

Returns:
the velocity of the extender

setVelocity

public void setVelocity(double vel)
sets the speed of expansion/contraction.

Parameters:
vel - the new velocity

isExpandingX

public boolean isExpandingX()
returns a boolean stating whether the extender is expanding horizontally.

Returns:
true if the extender is expanding horizontally

isExpandingY

public boolean isExpandingY()
returns a boolean stating whether the extender is expanding vertically.

Returns:
true if the extender is expanding vertically

isContractingX

public boolean isContractingX()
returns a boolean stating whether the extender is contracting horizontally.

Returns:
true if the extender is contracting horizontally

isContractingY

public boolean isContractingY()
returns a boolean stating whether the extender is contracting vertically.

Returns:
true if the extender is contracting vertically

width

public double width()
returns the current width of the extender.

Returns:
the current width of the extender

height

public double height()
returns the current height of the extender.

Returns:
the current height of the extender

getVelocity

public Vect getVelocity(Circle c)
returns the velocity of one of the vertices of the extender.

Parameters:
c - a circle which its center is at the location of one of the vertices of the extender's shape
Returns:
the velocity of the specified vertex

getVelocity

public Vect getVelocity(LineSegment ls)
returns the velocity of one of the sides of the extender.

Parameters:
ls - a line segment representing one of the sides of the extender's shape
Returns:
the velocity of the specified side

getExpansionSpeed

public double getExpansionSpeed(LineSegment ls)
returns the speed in which the side is expanding, ie the speed at which it changes its length.

Parameters:
ls - a line segment representing one of the sides of the extender's shape
Returns:

getUpperLeft

public Vect getUpperLeft()
returns the location of the upper left corner of the square (the upper-left point of the extender's shape at its smallest size).

Returns:
the location of the upper left corner of the square

getEnclosingPolygon

public Polygon getEnclosingPolygon()
returns the enclosing polygon of the extender (the whole area that the extender occupies at least at one point during its motion cycle.

Returns:
the enclosing polygon of the extender

getXSpanOfMotion

public double getXSpanOfMotion()
returns the horizontal span of motion of the extender.

Returns:
the horizontal span of motion of the extender

getYSpanOfMotion

public double getYSpanOfMotion()
returns the vertical span of motion of the extender.

Returns:
the vertical span of motino of the extender

getPausingTime

public double getPausingTime()
returns the pausing time between expansion/contraction transitions

Returns:
the pausing time

isStationary

public java.lang.Boolean isStationary()
returns a boolean that indicates if the extender is in motion (changes its shape) or stationary.

Returns:
true if the extender is stationary

timeTo

public double timeTo()
returns the time until a transition between states occurs.

Returns:
the time until a transition between states occurs

getFutureShape

public Polygon getFutureShape(double dt)
returns the shape that the extender will have after dt time from now without changing the actual state of the extender.

Parameters:
dt - time
Returns:
the shape that the extender will have after dt time from now

updateExtender

public void updateExtender(double dt)
updates the shape of the extender to the shape that the extender should have after dt time.

Parameters:
dt - time

action

public void action()
executes the action of the extender which switches the state(stationary/motion) of the extender.

Overrides:
action in class Gizmo