Maxaxik

Untitled

Jan 29th, 2017
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. function Circle(x, y) {
  2. this.x = x;
  3. this.y = y;
  4. this.r = floor(random(0, 255));
  5. this.g = floor(random(0, 255));
  6. this.b = floor(random(0, 255));
  7. this.radius = 15;
  8. this.minSpeed = 1;
  9. this.maxSpeed = 5;
  10. this.speedX = random(-this.maxSpeed, this.maxSpeed);
  11. this.speedY = random(-this.maxSpeed, this.maxSpeed);
  12. this.timer = 0;
  13.  
  14. this.getColor = function () {
  15. this.r = floor(random(0, 255));
  16. this.g = floor(random(0, 255));
  17. this.b = floor(random(0, 255));
  18. }
  19.  
  20. this.update = function () {
  21. this.timer++
  22. fill(this.r, this.g, this.b);
  23. ellipse(this.x, this.y, this.radius * 2, this.radius * 2);
  24.  
  25. this.x = this.x + this.speedX;
  26. this.y = this.y + this.speedY;
  27.  
  28. if (this.timer == 200) {
  29. this.radius = 30;
  30. }
  31. if (this.timer == 250) {
  32. this.radius = 0;
  33. circles.push(new Circle(width/2, height/2));
  34. }
  35. if (this.timer == 400) {
  36. this.radius = 10;
  37. this.timer = 0;
  38. }
  39.  
  40. if (this.x + this.radius > width) {
  41. this.speedX = random(-this.minSpeed, -this.maxSpeed);
  42. this.getColor();
  43. } else if (this.x - this.radius < 0) {
  44. this.speedX = random(this.minSpeed, this.maxSpeed);
  45. this.getColor();
  46. } else if (this.y + this.radius > height) {
  47. this.speedY = random(-this.minSpeed, -this.maxSpeed);
  48. this.getColor();
  49. } else if (this.y - this.radius < 0) {
  50. this.speedY = random(this.minSpeed, this.maxSpeed);
  51. this.getColor();
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment