[Physics Library] Looking to make Cloth particle system crumple to the centre
in
Contributed Library Questions
•
5 months ago
I am very new to the world of processing and have no clue how to do this!
Using the cloth particle system
http://murderandcreate.com/physics/cloth/index.html in the physics library.
I am trying to create a code so that the cloth crumples into the centre of the square, rather than being controlled by the mouse click on the right top corner. I am trying to make something like a piece of paper scrunching so the movement will be quite rigid.
I have already made the code more rigid, and taken away the spring and gravity:
Is it possible to make the centre of gravity in the centre of the cloth?
- import traer.physics.*;
- ParticleSystem physics;
- Particle[][] particles;
- int gridSize = 10;
- //STRENGTH OF HANGING SPRING+GETTING
- float SPRING_STRENGTH = 0.05;
- float SPRING_DAMPING = 0.05;
- void setup()
- {
- size(400, 400);
- smooth();
- fill(0);
- //(SETTING GRAVITY AT 0, RIGIDITY)
- physics = new ParticleSystem(0, 0.1);
- particles = new Particle[gridSize][gridSize];
- float gridStepX = (float) ((width / 2) / gridSize);
- float gridStepY = (float) ((height / 2) / gridSize);
- for (int i = 0; i < gridSize; i++)
- {
- for (int j = 0; j < gridSize; j++)
- {
- particles[i][j] = physics.makeParticle(0.2, j * gridStepX + (width / 4), i * gridStepY + 20, 0.0);
- if (j > 0)
- {
- physics.makeSpring(particles[i][j - 1], particles[i][j], SPRING_STRENGTH, SPRING_DAMPING, gridStepX);
- }
- }
- }
- for (int j = 0; j < gridSize; j++)
- {
- for (int i = 1; i < gridSize; i++)
- {
- physics.makeSpring(particles[i - 1][j], particles[i][j], SPRING_STRENGTH, SPRING_DAMPING, gridStepY);
- }
- }
- particles[0][0].makeFixed();
- particles[0][gridSize - 1].makeFixed();
- }
- void draw()
- {
- physics.tick();
- if (mousePressed)
- {
- particles[0][gridSize - 1].position().set(mouseX, mouseY, 0);
- particles[0][gridSize - 1].velocity().clear();
- }
- noFill();
- background(255);
- for (int i = 0; i < gridSize; i++)
- {
- beginShape();
- curveVertex(particles[i][0].position().x(), particles[i][0].position().y());
- for (int j = 0; j < gridSize; j++)
- {
- curveVertex(particles[i][j].position().x(), particles[i][j].position().y());
- }
- curveVertex(particles[i][gridSize - 1].position().x(), particles[i][gridSize - 1].position().y());
- endShape();
- }
- for (int j = 0; j < gridSize; j++)
- {
- beginShape();
- curveVertex(particles[0][j].position().x(), particles[0][j].position().y());
- for (int i = 0; i < gridSize; i++)
- {
- curveVertex(particles[i][j].position().x(), particles[i][j].position().y());
- }
- curveVertex(particles[gridSize - 1][j].position().x(), particles[gridSize - 1][j].position().y());
- endShape();
- }
- }
- void mouseReleased()
- {
- particles[0][gridSize - 1].velocity().set( (mouseX - pmouseX), (mouseY - pmouseY), 0 );
- }
Thankyou!!!!
1