Guest User

Untitled

a guest
Oct 16th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. "use strict";
  2. var balls = [];
  3. var i;
  4. var blower;
  5. function setup() {
  6. createCanvas(900, 560);
  7. for (var i = 0; i < 40; ++i) {
  8. balls[i] = new Ball()
  9. .position(random(0, 900), random(360, 361))
  10. }
  11. }
  12.  
  13. function draw() {
  14. background('#AED6F1');
  15. fill('#3498DB');
  16. rect(0, 360, 900, 200);
  17. noStroke();
  18.  
  19.  
  20. //Balls
  21. for (var i = 0; i < balls.length; ++i){
  22. balls[i].move();
  23. balls[i].display();
  24. }
  25.  
  26. var blower = new Blower();
  27.  
  28. //blow up
  29. var f1 = createVector(0, -1);
  30.  
  31. //gravity
  32. var f2 = createVector(0, 1);
  33.  
  34. //fuli
  35. var f3 = createVector(0, -0.2);
  36.  
  37. if (mouseY > 360 && mouseY < 560) {
  38. blower.update_pos(mouseX);
  39. for (var i = 0; i < balls.length; ++i){
  40. //blowed up
  41. if (balls[i].pos.x > blower.x1 && balls[i].pos.x < blower.x4){
  42. balls[i].applyForce(f1);
  43. }
  44. else{
  45. //drop down
  46. if (balls[i].pos.y < 360){
  47. balls[i].applyForce(f2);
  48. }
  49. //come up
  50. if (balls[i].pos.y > 361) {
  51. balls[i].applyForce(f3);
  52. }
  53. }
  54. balls[i].update();
  55. balls[i].display();
  56.  
  57. }
  58. }
  59. blower.display();
  60.  
  61. }
  62.  
  63. class Blower{
  64. constructor(){
  65. this.x1 = 0;
  66. this.y1 = 460;
  67. this.x2 = 20;
  68. this.y2 = 560;
  69. this.x3 = 40;
  70. this.y3 = 560;
  71. this.x4 = 60;
  72. this.y4 = 460;
  73. }
  74.  
  75. update_pos(center_x) {
  76. this.x1 = center_x - 30;
  77. this.x2 = center_x - 10;
  78. this.x3 = center_x + 10;
  79. this.x4 = center_x + 30;
  80. }
  81.  
  82.  
  83. display(){
  84. fill('#F7DC6F');
  85. quad(this.x1,this.y1,this.x2,this.y2,this.x3,this.y3,this.x4,this.y4);
  86. }
  87.  
  88. }
Add Comment
Please, Sign In to add comment