fisica
Class FBlob

java.lang.Object
  extended by fisica.FBody
      extended by fisica.FBlob

public class FBlob
extends FBody

Represents a blob body that can be added to a world. Blobs are soft bodies that are composed of vertices and tries to maintain constant the volume the vertices enclose. Blobs can be created by adding vertices using the vertex method in a similar way to FPoly:

 FBlob myBlob = new FBlob();
 myBlob.vertex(40, 10);
 myBlob.vertex(50, 20);
 myBlob.vertex(60, 30);
 myBlob.vertex(60, 40);
 myBlob.vertex(50, 50);
 myBlob.vertex(40, 60);
 myBlob.vertex(30, 70);
 myBlob.vertex(20, 60);
 myBlob.vertex(10, 50);
 myBlob.vertex(10, 40);
 myBlob.vertex(20, 30);
 myBlob.vertex(30, 20);
 myBlob.vertex(40, 10);
 world.add(myBlob);
 
 
or it may be initialized using the method setAsCircle to set the initial shape as a circle:
 FBlob myBlob = new FBlob();
 myBlob.setAsCircle(40);
 world.add(myBlob);
 
 

See Also:
FBox, FCircle, FPoly, FLine

Constructor Summary
FBlob()
          Constructs a blob body that can be added to a world.
 
Method Summary
 void addForce(float fx, float fy)
          Add a force applied on the center of the body.
 void addTorque(float t)
          Add a rotation force (a torque) to the body.
 void attachImage(processing.core.PImage img)
          Attach an image to the object.
 void dettachImage()
          Dettach any image that has been attached to the object.
 void draw(processing.core.PApplet applet)
           
 void draw(processing.core.PGraphics applet)
          This method is called when calling world.draw().
 float getImageAlpha()
          Get the opacity with which to draw the attached image.
 float getVertexSize()
          Returns the size of the circular vertices of the blob.
 boolean isDrawable()
          Get whether the object must be drawn or not.
 void setAsCircle(float size)
          Sets the initial shape of the blob to a circle.
 void setAsCircle(float x, float y, float size)
          Sets the initial shape of the blob to a circle.
 void setAsCircle(float x, float y, float size, int vertexCount)
          Sets the initial shape of the blob to a circle.
 void setAsCircle(float size, int vertexCount)
          Sets the initial shape of the blob to a circle.
 void setBullet(boolean d)
          Set whether the body is a bullet.
 void setDamping(float damping)
          Sets the damping of the springs used to maintain the volume defined by the vertices constant.
 void setDensity(float d)
          Set the density of the body.
 void setDrawable(boolean val)
          Set whether the object must be drawn or not.
 void setFill(float g)
          Set the fill color of the object.
 void setFill(float g, float a)
          Set the fill color of the object.
 void setFill(float r, float g, float b)
          Set the fill color of the object.
 void setFill(float r, float g, float b, float a)
          Set the fill color of the object.
 void setFillColor(int col)
          Set the fill color of the object.
 void setFrequency(float frequency)
          Sets the frequency of the springs used to maintain the volume defined by the vertices constant.
 void setFriction(float d)
          Set the friction of the body.
 void setImageAlpha(float alpha)
          Set the opacity with which to draw the attached image.
 void setNoFill()
          Set that the object must be drawn without fill.
 void setNoStroke()
          Set that the object must be drawn without stroke.
 void setRestitution(float d)
          Set the restitution of the body.
 void setStroke(float g)
          Set the stroke color of the object.
 void setStroke(float g, float a)
          Set the stroke color of the object.
 void setStroke(float r, float g, float b)
          Set the stroke color of the object.
 void setStroke(float r, float g, float b, float a)
          Set the stroke color of the object.
 void setStrokeColor(int col)
          Set the stroke color of the object.
 void setStrokeWeight(float col)
          Set the stroke weight of the object.
 void setVertexSize(float size)
          Sets the size of the circular vertices of the blob.
 void vertex(float x, float y)
          Adds a vertex to the initial shape of the blob.
 
Methods inherited from class fisica.FBody
addForce, adjustAngularVelocity, adjustPosition, adjustRotation, adjustVelocity, getAngularVelocity, getContacts, getGroupIndex, getRotation, getTouching, getVelocityX, getVelocityY, getX, getY, isResting, isSensor, isStatic, isTouchingBody, resetForces, setAngularDamping, setAngularVelocity, setCategoryBits, setFilterBits, setForce, setGrabbable, setGroupIndex, setPosition, setRotatable, setRotation, setSensor, setStatic, setStaticBody, setVelocity
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FBlob

public FBlob()
Constructs a blob body that can be added to a world. It creates an empty blob, before adding the blob to the world use vertex or setAsCircle to define the initial shape of the blob.

Method Detail

vertex

public void vertex(float x,
                   float y)
Adds a vertex to the initial shape of the blob. This method must be called before adding the body to the world.

Parameters:
x - x coordinate of the vertex to be added
y - y coordinate of the vertex to be added

setAsCircle

public void setAsCircle(float x,
                        float y,
                        float size,
                        int vertexCount)
Sets the initial shape of the blob to a circle. This method removes all the previous vertices tha may have been added by the use of the vertex. This method must be called before adding the body to the world.

Parameters:
x - x coordinate of the position of the circle
y - y coordinate of the position of the circle
size - size of the circle
vertexCount - number of vertices of the circle

setAsCircle

public void setAsCircle(float x,
                        float y,
                        float size)
Sets the initial shape of the blob to a circle. This method removes all the previous vertices tha may have been added by the use of the vertex. This method must be called before adding the body to the world.

Parameters:
x - x coordinate of the position of the circle
y - y coordinate of the position of the circle
size - size of the circle

setAsCircle

public void setAsCircle(float size)
Sets the initial shape of the blob to a circle. This method removes all the previous vertices tha may have been added by the use of the vertex. This method must be called before adding the body to the world.

Parameters:
size - size of the circle

setAsCircle

public void setAsCircle(float size,
                        int vertexCount)
Sets the initial shape of the blob to a circle. This method removes all the previous vertices tha may have been added by the use of the vertex. This method must be called before adding the body to the world.

Parameters:
size - size of the circle
vertexCount - number of vertices of the circle

getVertexSize

public float getVertexSize()
Returns the size of the circular vertices of the blob. This method must be called before the body is added to the world.

Returns:
size of the circular vertices of the blob

setVertexSize

public void setVertexSize(float size)
Sets the size of the circular vertices of the blob. This method must be called before the body is added to the world.

Parameters:
size - size of the circular vertices of the blob

setFrequency

public void setFrequency(float frequency)
Sets the frequency of the springs used to maintain the volume defined by the vertices constant.

Parameters:
frequency - the frequency of the springs of the constant volume joint

setDamping

public void setDamping(float damping)
Sets the damping of the springs used to maintain the volume defined by the vertices constant.

Overrides:
setDamping in class FBody
Parameters:
damping - the damping of the springs of the constant volume joint
See Also:
FBody.setAngularDamping(float)

addForce

public void addForce(float fx,
                     float fy)
Description copied from class: FBody
Add a force applied on the center of the body.

Overrides:
addForce in class FBody
Parameters:
fx - the x coordinate of the force
fy - the y coordinate of the force
See Also:
FBody.addTorque(float), FBody.addForce(float,float,float,float)

addTorque

public void addTorque(float t)
Description copied from class: FBody
Add a rotation force (a torque) to the body.

Overrides:
addTorque in class FBody
Parameters:
t - the value of the torque
See Also:
FBody.addForce(float,float), FBody.addForce(float,float,float,float)

setDensity

public void setDensity(float d)
Description copied from class: FBody
Set the density of the body. The density will determine the total mass of the body and thus it's behavior with respect to collisions, bounces, inertia, joints,... When the density is set, the mass of the body is recalculated automatically given it's area. Note that a density of 0.0 corresponds to a mass of 0.0 independently of the area and the body will be considered static.

Overrides:
setDensity in class FBody
Parameters:
d - the density of the body

setFriction

public void setFriction(float d)
Description copied from class: FBody
Set the friction of the body. The friction determines the ratio of the reaction force tangent to a contact, when the body collides with another body. Basically it can be seen as a coefficient that will control how the body gets slown down when the body slides against another body. The friction of a contact of two bodies in a collision is calculated from the friction values of the 2 bodies involved.

Overrides:
setFriction in class FBody
Parameters:
d - a positive value. A value of 0 means no friction and thus the body will not be slown down if no other forces are applied

setRestitution

public void setRestitution(float d)
Description copied from class: FBody
Set the restitution of the body. The restitution determines the ratio of the reaction force normal to a contact, when the body collides with another body. Basically it can be seen as a coefficient that will control the strength with which the body bounces back from a collision. The resititution of a contact of two bodies in a collision is calculated as the maximum of the restitution values of the 2 bodies involved.

Overrides:
setRestitution in class FBody
Parameters:
d - a positive value. A value of 0 means no bounce after a collision, and a value of 1 means bounce with it's full speed from a collision

setBullet

public void setBullet(boolean d)
Description copied from class: FBody
Set whether the body is a bullet. Bullet bodies are computationally more expensive but more accurate in their movement. Use this only with fast objects.

Overrides:
setBullet in class FBody
Parameters:
d - if true the body will be a bullet

setNoStroke

public void setNoStroke()
Set that the object must be drawn without stroke.

See Also:
setStroke(float), setStroke(float,float), setStroke(float,float,float), setStroke(float,float,float,float)

setNoFill

public void setNoFill()
Set that the object must be drawn without fill.

See Also:
setFill(float), setFill(float,float), setFill(float,float,float), setFill(float,float,float,float)

setFillColor

public void setFillColor(int col)
Set the fill color of the object. This method must be used in conjunction with Processing's color(). In most cases users will find it more convenient to use the versions of setFill(float), setFill(float,float), setFill(float,float,float) or setFill(float,float,float,float)

Parameters:
col - a Processing color type. e.g. myBody.setFillColor(color(20,100,30,90));
See Also:
setNoFill(), setFill(float), setFill(float,float), setFill(float,float,float), setFill(float,float,float,float)

setStrokeColor

public void setStrokeColor(int col)
Set the stroke color of the object. This method must be used in conjunction with Processing's color(). In most cases users will find it more convenient to use the versions of setStroke(float), setStroke(float,float), setStroke(float,float,float) or setStroke(float,float,float,float)

Parameters:
col - a Processing color type. e.g. myBody.setStrokeColor(color(20,100,30,90));
See Also:
setNoStroke(), setStroke(float), setStroke(float,float), setStroke(float,float,float), setStroke(float,float,float,float)

setStrokeWeight

public void setStrokeWeight(float col)
Set the stroke weight of the object.

Parameters:
col - weight value in pixels
See Also:
setStroke(float), setStroke(float,float), setStroke(float,float,float), setStroke(float,float,float,float)

setDrawable

public void setDrawable(boolean val)
Set whether the object must be drawn or not.

Parameters:
val - if true the object will be drawn, else it will not
See Also:
isDrawable()

draw

public void draw(processing.core.PGraphics applet)
This method is called when calling world.draw(). This method may be overriden to allow custom drawing of the object.

Parameters:
applet - the applet onto which the object must be drawn.

draw

public void draw(processing.core.PApplet applet)

attachImage

public void attachImage(processing.core.PImage img)
Attach an image to the object. This method allows to draw an image onto the screen instead of calling the draw(PApplet) method.

Parameters:
img - the PImage to attach to the object.

dettachImage

public void dettachImage()
Dettach any image that has been attached to the object.

See Also:
attachImage(PImage)

getImageAlpha

public float getImageAlpha()
Get the opacity with which to draw the attached image.

Returns:
the opacity, a value from 0.0 to 1.0 with which to draw the attached image
See Also:
attachImage(PImage), setImageAlpha(float)

setImageAlpha

public void setImageAlpha(float alpha)
Set the opacity with which to draw the attached image.

Parameters:
alpha - the opacity, a value from 0.0 to 1.0 with which to draw the attached image
See Also:
attachImage(PImage), getImageAlpha()

isDrawable

public boolean isDrawable()
Get whether the object must be drawn or not.

Returns:
drawable if true the object will be drawn, else it will not
See Also:
setDrawable(boolean)

setFill

public void setFill(float g)
Set the fill color of the object.

Parameters:
g - gray value
See Also:
setFill(float), setFill(float,float), setFill(float,float,float), setFill(float,float,float,float)

setFill

public void setFill(float g,
                    float a)
Set the fill color of the object.

Parameters:
g - gray value
a - alpha (opacity) value
See Also:
setFill(float), setFill(float,float), setFill(float,float,float), setFill(float,float,float,float)

setFill

public void setFill(float r,
                    float g,
                    float b)
Set the fill color of the object.

Parameters:
r - red value
g - green value
b - blue value
See Also:
setFill(float), setFill(float,float), setFill(float,float,float), setFill(float,float,float,float)

setFill

public void setFill(float r,
                    float g,
                    float b,
                    float a)
Set the fill color of the object.

Parameters:
r - red value
g - green value
b - blue value
a - alpha (opacity) value
See Also:
setFill(float), setFill(float,float), setFill(float,float,float), setFill(float,float,float,float)

setStroke

public void setStroke(float g)
Set the stroke color of the object.

Parameters:
g - gray value
See Also:
setStroke(float), setStroke(float,float), setStroke(float,float,float), setStroke(float,float,float,float)

setStroke

public void setStroke(float g,
                      float a)
Set the stroke color of the object.

Parameters:
g - gray value
a - alpha (opacity) value
See Also:
setStroke(float), setStroke(float,float), setStroke(float,float,float), setStroke(float,float,float,float)

setStroke

public void setStroke(float r,
                      float g,
                      float b)
Set the stroke color of the object.

Parameters:
r - red value
g - green value
b - blue value
See Also:
setStroke(float), setStroke(float,float), setStroke(float,float,float), setStroke(float,float,float,float)

setStroke

public void setStroke(float r,
                      float g,
                      float b,
                      float a)
Set the stroke color of the object.

Parameters:
r - red value
g - green value
b - blue value
a - alpha (opacity) value
See Also:
setStroke(float), setStroke(float,float), setStroke(float,float,float), setStroke(float,float,float,float)


processing library fisica by Ricard Marxer. (c) 2009