Advertisement
ramomjcs

Q01 - PG

Mar 17th, 2021
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. PVector location; // Location of shape
  2. PVector velocity; // Velocity of shape
  3. PVector gravity; // Gravity acts at the shape's acceleration
  4.  
  5. float qtdFrames = 0; //contador de frames
  6.  
  7. void setup() {
  8. size(640,360);
  9. location = new PVector(30,height-140-30);
  10. velocity = new PVector(4.9,10);
  11. gravity = new PVector(0,0.5);
  12. //frameRate(10);
  13. }
  14.  
  15. void draw() {
  16. qtdFrames++;
  17. //println("frameRate", frameRate); //qtd de frames por segundo
  18. background(225,225,225);
  19. // Add velocity to the location.
  20. location.add(velocity);
  21. // Add gravity to velocity
  22. velocity.add(gravity);
  23.  
  24.  
  25. // Bounce off edges
  26. if ((location.x > width-30) || (location.x < 30)) {
  27. velocity.x = velocity.x * -1;
  28. //println(qtdFrames, "Frames"); //qtd de frames total para bater na parede
  29. //println(qtdFrames/frameRate, "Segundos"); //tempo em segundos para bater na parede
  30. qtdFrames = 0;
  31. }
  32. if (location.y > height-140-30) { //105
  33. // We're reducing velocity ever so slightly
  34. // when it hits the bottom of the window
  35. velocity.y = velocity.y * -0.95;
  36. location.y = height-140-30;
  37. }
  38.  
  39. // Display circle at location vector
  40. stroke(255);
  41. strokeWeight(0);
  42. fill(0);
  43. ellipse(location.x,location.y,60,60);
  44. line(0,220,640,220);
  45. color c = color(175, 100, 220); // Define color 'c'
  46. fill(c); // Use color variable 'c' as fill color
  47. rect(0, 220, 640, 220);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement