Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- class Ball{
- constructor() {
- this.pos = createVector();
- this.vel = createVector();
- this.acc = createVector();
- this.mass = 4;
- this.rad = this.mass * 2;
- this.r = random(255);
- this.b = random(255);
- this.g = random(255);
- this.a = 80;
- }
- position(x, y) {
- this.pos = createVector(x, y);
- return this;
- }
- velocity(x, y) {
- this.vel = createVector(x, y);
- return this;
- }
- colour(r, g, b, a) {
- this.r = r;
- this.b = b;
- this.g = g;
- this.a = a;
- return this;
- }
- move() {
- this.pos.x += random(-0.5, 0.5);
- }
- update(){
- this.vel.add(this.acc);
- this.pos.add(this.vel);
- this.acc.mult(0);
- }
- display() {
- push();
- translate(this.pos.x, this.pos.y);
- fill(this.r, this.b, this.g, this.a);
- ellipse(0, 0, this.rad *2, this.rad * 2);
- pop();
- }
- applyForce(f) {
- //f.div(this.mass);
- this.acc.add(f);
- }
- }
Add Comment
Please, Sign In to add comment