Hi, i hope i will get some help as this is driving me crazy for some days now. After my question if i should use traer or toxis verlet physics. Big thanks to PhiLho for answering! I will go with traer physics for this project.
My main goal is to create little objects built out of particles. Every Object should be the instance of a class.
So i first tried to create a class with this simple Ring. But it is not working . No matter what i do i get different kind of errors. I am not sure if i have to create different kind of particle systems to make it work or where to put the tick, etc... like i said, i tried different szenarios but i always got a different kind of error. Only thing that worked was when i put everything in the class, also the particle system itself. but i guess then its impossible to make them appeal ech other what is my next problem. Next step would be to make them react to each other so that they appeal or repel each other.
so if anybody has made a sketch where he creates some objects out of traer particles and put them into classes, i would be thankful for any hints or tipps
this is a simpel test sketch with only one object without classes:
Code:import traer.physics.*;
Particle mouse;
ParticleSystem physics;
Particle[] ball;
Spring[] s;
void setup(){
size( 400, 400 );
ellipseMode( CENTER );
noStroke();
//Create ParticleSystem
physics = new ParticleSystem( 0, 0.1 );
//Create Particles
mouse = physics.makeParticle();
mouse.makeFixed();
ball = new Particle[10];
s = new Spring[10];
//create Balls and Mouse Attraction
for(int i=0; i< ball.length; i++){
ball[i] = physics.makeParticle( 1.0, random(width),random(height ), 0 );
physics.makeAttraction( mouse, ball[i], 3000, 50 );
}
for(int i=0; i< ball.length; i++){
for(int j=i+1; j< ball.length; j++){
physics.makeAttraction( ball[i], ball[j], -4500, 50 );
}
}
//Create Springs with strength, damping, restLength
for(int i=0; i< ball.length-1; i++){
s[i] = physics.makeSpring( ball[i], ball[i+1], 0.4, 0.1,4);
}
s[9] = physics.makeSpring( ball[0], ball[ball.length-1], 0.4, 0.1, 4);
}
void draw(){
physics.tick();
background( 255 );
mouse.position().set( mouseX, mouseY, 0 );
ellipse(mouse.position().x(),mouse.position().y(),15,15);
fill(0);
for ( int i = 0; i < ball.length; i++ ){
ellipse(ball[i].position().x(),ball[i].position().y(),5,5);
}
stroke(0);
for(int i=0; i< ball.length-1; i++){
line( ball[i].position().x(), ball[i].position().y(), ball[i+1].position().x(), ball[i+1].position().y() );
}
line( ball[0].position().x(), ball[0].position().y(), ball[ball.length -1].position().x(), ball[ball.length -1].position().y() );
}
this is the code where i tried to put it into classes and it seems to work, but how is it possible to let them interact with each other or the mouse now?
Code:import traer.physics.*;
Circle[] circle = new Circle[5];
void setup(){
size( 400, 400 );
ellipseMode( CENTER );
noStroke();
for (int i=0; i<circle.length; i++){
circle[i] = new Circle(random(width), random(height));
}
}
void draw(){
background( 255 );
for (int i=0; i<circle.length; i++){
circle[i].render();
}
}
class Circle{
float x;
float y;
Particle[] ball;
Spring[] s;
ParticleSystem physics;
Circle(float _x, float _y){
x = _x;
y = _y;
//Create ParticleSystem
physics = new ParticleSystem( 0, 0.1 );
ball = new Particle[10];
s = new Spring[10];
//create Balls and Mouse Attraction
for(int i=0; i< ball.length; i++){
ball[i] = physics.makeParticle( 1.0, x + random( -30, 30 ),y + random( -30, 30 ), 0 );
}
for(int i=0; i< ball.length; i++){
for(int j=i+1; j< ball.length; j++){
physics.makeAttraction( ball[i], ball[j], -4500, 50 );
}
}
//Create Springs with strength, damping, restLength
for(int i=0; i< ball.length-1; i++){
s[i] = physics.makeSpring( ball[i], ball[i+1], 0.4, 0.1,4);
}
s[9] = physics.makeSpring( ball[0], ball[ball.length-1], 0.4, 0.1, 4);
}
void render(){
fill(0);
physics.tick();
for ( int i = 0; i < ball.length; i++ ){
ellipse(ball[i].position().x(),ball[i].position().y(),5,5);
}
stroke(0);
for(int i=0; i< ball.length-1; i++){
line( ball[i].position().x(), ball[i].position().y(), ball[i+1].position().x(), ball[i+1].position().y() );
}
line( ball[0].position().x(), ball[0].position().y(), ball[ball.length -1].position().x(), ball[ball.length -1].position().y() );
}
}