The friction acting on a particle is the same , no matter the size

I have set the value of friction acting on a particle based on its size, yet it appears as if the small ones and the large ones come to a halt at the same rate.I plan on having the large circles come to a halt much quicker than the smaller ones.

so i decided to use to multiply the friction vector to the size of the circle.

ball = [];

function setup() {
  height = 500;
  width = 500;
  createCanvas(width, height);
  b = new particle();
  gravity = createVector(0, 0.1);
  wind = createVector(random(-1, 1), random(1, 0.05));
  surfaceFriction = 0.8;
}

function mousePressed() {

  b = new particle(mouseX, mouseY);
  ball.push(b);

}

function draw() {
  background(222);
  for (i = 0; i < ball.length; i++) {

    ball[i].show();
    ball[i].netForce(gravity);
    ball[i].netForce(wind);
    ball[i].motion();
    ball[i].edgeCheck();

  }

}

function particle(x, y) {

  this.loc = createVector(x, y);
  this.vel = createVector(0, 0);
  this.gravity = createVector(0, 0.1);
  this.mass = random(1, 40);
  this.friction = createVector(0, 0);

  this.frictionForce = function() // responsible for friction
  {
    this.friction = copy(this.vel);
    this.friction.normalize();
    this.friction.mult(-1);
  //this.friction.mag(this.mass);
    this.friction.mult(this.mass);




  }





  this.netForce = function(f) {
    this.vel.add(f);
  }



  this.show = function() {
    fill(125, 125, 255);
    circle(this.loc.x, this.loc.y, this.mass);
  }

  this.edgeCheck = function() {
    if (this.loc.y >= height) {
      this.loc.y = height;
      this.vel.y = this.vel.y * -1;
      this.vel.add(this.friction);
    }
    if (this.loc.x >= width) {
      this.loc.x = width;
      this.vel.x = this.vel.x * -1;
      this.vel.add(this.friction);
    }

    if (this.loc.x <= 0) {
      this.loc.x = 0;
      this.vel.x = this.vel.x * -1;
      this.vel.add(this.friction);
    }


  }

  this.motion = function() {
    this.loc.add(this.vel);

  }



}

Sorry,
i forgot to call the function friction while drawing and had to make a few other arithmetic changes in the code.It works as expected now.:grinning:

1 Like