Guest User

Untitled

a guest
Feb 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. myCircle ball;
  2.  
  3. void setup(){
  4. size(200, 200);
  5. ellipseMode(CENTER);
  6. fill(255);
  7. ball = new myCircle(width / 4, height / 2, 1, 1, width/20, 1.05);
  8. }
  9.  
  10. void draw(){
  11. background(0);
  12. ball.display();
  13. }
  14.  
  15. class myCircle{
  16. int xDir, yDir;
  17. float speed, diam, xPos, yPos;
  18.  
  19. myCircle(float x, float y, int xDir, int yDir, float dia, float velocity){
  20. xPos = x;
  21. yPos = y;
  22. this.xDir = xDir;
  23. this.yDir = yDir;
  24. diam = dia;
  25. speed = velocity;
  26. }
  27.  
  28. void display(){
  29. if(xPos <= 0 + (diam/2) || xPos >= width - (diam/2)){
  30. xDir *= -1;
  31. }
  32.  
  33. if(yPos - (diam/2)<= 0 || yPos >= height - (diam/2)){
  34. yDir *= -1;
  35. }
  36.  
  37. xPos += speed * xDir;
  38. yPos += speed * yDir;
  39. ellipse(xPos, yPos, diam, diam);
  40. }
  41. }
Add Comment
Please, Sign In to add comment