MrThoe

Processing Beginner Code

Jan 23rd, 2020
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. /** Project 1: My Bouncing Ball
  2. * @Author: Allen Thoe
  3. * @Date: 1/21/2020
  4. */
  5. //DECLARE VARIABLES--> Type name;
  6. float x, y, d;
  7. float Vx, Vy;
  8.  
  9. void setup(){
  10. size(600,600);
  11. strokeWeight(4);
  12. x = 200;
  13. Vx = random(-5,5);
  14. Vy = random(-5,5);
  15. y = 300;
  16. d = 60;
  17. textSize(40);
  18. }
  19.  
  20. void draw(){
  21. background(r,g,b);
  22. fill(0,195, 255);
  23. stroke(155, 0, 255);
  24. ellipse(x, y, d, d);
  25. moveBall(); //CALL the moveBall() function
  26. bounce();
  27. }
  28.  
  29. //Function MoveBall will update the location of the ball
  30. void moveBall(){
  31. x = x + Vx;
  32. y = y + Vy;
  33. }
  34.  
  35. void bounce(){
  36. //HITS LEFT OR RIGHT WALL
  37. if(x < 0 || x > width){
  38. Vx = -Vx;
  39. //r = random(255);
  40. //g = random(255);
  41. //b = random(255);
  42. }
  43. //HITS UP OR DOWN WALL
  44. if(y < 0 || y > height){
  45. Vy = -Vy;
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment