Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- var coRestitution = 0.018;
- var coFriction = 0.01;
- class Particle {
- constructor(x, y) {
- this.pos = createVector(x, y);
- this.vel = createVector(random(-10, 10), random(-10, 10));
- this.acc = createVector(0, 0);
- this.targetPos = createVector(width / 2, height / 2);
- this.lerpSpeed = random(0.05, 0.1);
- //255, 120, 20, 70
- this.r = 200; //random(255);
- this.g = 120; //random(255);
- this.b = 20; //random(255);
- this.rad = random(2, 3.5);
- }
- moveWithLerp() {
- this.pos = p5.Vector.lerp(this.pos, this.targetPos, this.lerpSpeed);
- }
- applyForce(f) {
- this.acc.add(f)
- }
- update() {
- this.vel.add(this.acc);
- this.pos.add(this.vel);
- this.acc.mult(0);
- }
- display() {
- push();
- translate(this.pos.x, this.pos.y);
- noStroke();
- //stroke(0);
- //strokeWeight(1);
- fill(this.r, this.g, this.b);
- blendMode(ADD);
- ellipse(0, 0, this.rad * 2, this.rad * 2);
- pop();
- }
- checkBoundaries() {
- var force = createVector(0, 0);
- //x
- if (this.pos.x < 0 + this.rad) {
- this.pos.x = 0 + this.rad;
- this.vel.x = -this.vel.x * 0.3;
- } else if (this.pos.x > width - this.rad) {
- this.pos.x = width - this.rad;
- this.vel.x = -this.vel.x * 0.3;
- }
- // y
- if (this.pos.y < 0 + this.rad) {
- this.pos.y = 0 + this.rad;
- this.vel.y = -this.vel.y * 0.3;
- } else if (this.pos.y > height - this.rad) {
- this.pos.y = height - this.rad;
- this.vel.y = -this.vel.y * 0.3;
- }
- }
- /*
- checkCollision(other) {
- var distance = this.pos.dist(other.pos);
- if (distance < this.rad + other.rad) {
- // this
- var force = p5.Vector.sub(other.pos, this.pos);
- force.normalize();
- force.mult(-1);
- force.mult(other.vel.mag());
- this.applyForce(force);
- this.vel.mult(coRestitution);
- var friction = p5.Vector.mult(this.vel, -1);
- friction.normalize();
- friction.mult(coFriction);
- friction.limit(this.vel.mag());
- other.applyForce(friction);
- // other
- var force = p5.Vector.sub(this.pos, other.pos);
- force.normalize();
- force.mult(-1);
- force.mult(this.vel.mag());
- other.applyForce(force);
- other.vel.mult(coRestitution);
- var friction = p5.Vector.mult(other.vel, -1);
- friction.normalize();
- friction.mult(coFriction);
- friction.limit(other.vel.mag());
- other.applyForce(friction);
- }
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement