How to draw Liquid fun particles in Processing

Apologies if I have asked this question already but I don't think it was submitted so...

I think what I am trying to do is simple but it's pretty hard to find any documentation... All I want to do is to see particles on the screen using the liquidfun library although to find examples of how to use this is not straightforward.

Can anyone just show me the code for drawing liquidfun particles on a screen in Processing....so far I have got:

   import shiffman.box2d.*;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.joints.*;
import org.jbox2d.collision.shapes.*;
import org.jbox2d.collision.shapes.Shape;
import org.jbox2d.dynamics.*;
import org.jbox2d.dynamics.contacts.*;
import org.jbox2d.particle.ParticleGroupDef;
import org.jbox2d.particle.ParticleGroup;
import org.jbox2d.particle.ParticleSystem;
import org.jbox2d.particle.ParticleType;
import org.jbox2d.particle.ParticleDef;
import org.jbox2d.particle.ParticleColor;
import org.jbox2d.collision.shapes.CircleShape;
import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.BodyType;

Box2DProcessing box2d;
PS particle;
ParticleGroup pg ;
ParticleGroupDef pd;
ParticleSystem ps;
ParticleColor partcol;
//BodyDef bd;

void setup() {

  size(1640, 1360);
  noStroke();
  box2d = new Box2DProcessing(this);
  box2d.createWorld();
   BodyDef bd = new BodyDef();
   Body ground = box2d.world.createBody(bd);
   ChainShape shape= new ChainShape();
   Vec2 [] box={new Vec2(0, 0),new Vec2(400, 0),new Vec2(400, 400),new Vec2(0, 400)};

        shape.createLoop(box, 4);
        ground.createFixture(shape, 0.0f);

    ps=new ParticleSystem(box2d.world);
    ps.setParticleRadius(0.025f);
    ps.setParticleDamping(0.2f);
    particle =new PS();
    partcol=new ParticleColor();   
}
void draw() {
  noLoop();
  for (int i=0;i<pg.getParticleCount()-2270;i++){
  particle.display();
  } 
}



class PS {  
    PS() {    
    //the definition for the particle group
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(0.8f, 1.0f, new Vec2(-1.2f, 1.01f), 255);
      //shape.m_p.set(0, 30);
      shape.m_radius = 20; 
      ParticleGroupDef pd=new ParticleGroupDef();
      pd.flags = ParticleType.b2_waterParticle;
      pd.shape = shape; 
      pg=ps.createParticleGroup(pd); 
    }

        void display() {
           print(" "+pg.getParticleCount()+" ");
       }
  }

but I don't know how to actually see the particles on the screen.

Tagged:

Answers

Sign In or Register to comment.