Guest User

Untitled

a guest
Oct 16th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. "use strict";
  2.  
  3. class Ball{
  4. constructor() {
  5. this.pos = createVector();
  6. this.vel = createVector();
  7. this.acc = createVector();
  8.  
  9. this.mass = 4;
  10. this.rad = this.mass * 2;
  11. this.r = random(255);
  12. this.b = random(255);
  13. this.g = random(255);
  14. this.a = 80;
  15. }
  16.  
  17. position(x, y) {
  18. this.pos = createVector(x, y);
  19. return this;
  20. }
  21.  
  22. velocity(x, y) {
  23. this.vel = createVector(x, y);
  24. return this;
  25. }
  26.  
  27. colour(r, g, b, a) {
  28. this.r = r;
  29. this.b = b;
  30. this.g = g;
  31. this.a = a;
  32. return this;
  33. }
  34.  
  35. move() {
  36. this.pos.x += random(-0.5, 0.5);
  37. }
  38.  
  39.  
  40. update(){
  41. this.vel.add(this.acc);
  42. this.pos.add(this.vel);
  43. this.acc.mult(0);
  44.  
  45. }
  46.  
  47. display() {
  48. push();
  49. translate(this.pos.x, this.pos.y);
  50. fill(this.r, this.b, this.g, this.a);
  51. ellipse(0, 0, this.rad *2, this.rad * 2);
  52. pop();
  53. }
  54.  
  55. applyForce(f) {
  56. //f.div(this.mass);
  57. this.acc.add(f);
  58. }
  59.  
  60.  
  61. }
Add Comment
Please, Sign In to add comment