Guest User

Untitled

a guest
Oct 17th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. int x=200;
  2. int y=200;
  3. int r =30;
  4. boolean dentro = false;
  5. void setup(){
  6. size(400,400);
  7. ellipseMode(RADIUS);
  8. }
  9. void mousePressed(){
  10. dentro = dist(mouseX, mouseY, x, y) <= r;
  11. }
  12. void mouseDragger(){
  13. if (dentro){
  14. int dx = mouseX-pmouseX;
  15. int dy = mouseY-pmouseY;
  16. x+=dx;
  17. y+=dy;
  18. }
  19. }
  20. void draw(){
  21. ellipse (x,y,r,r);
  22. }-----------
  23. class Bola{
  24. int x;
  25. int y;
  26. Bola(int a, int b){
  27. this.x=a;
  28. this.y=b;
  29. ellipse (a,b,10,10);
  30. }
  31. boolean dentro(int cX, int cY){
  32. return( dist(cX, cY, this.x, this.y) <= 10);
  33. }
  34. void desenha(){
  35. ellipse (this.x,this.y,10,10);
  36. }
  37. }
  38.  
  39. Bola b[] = new Bola[2];
  40. int sel =-1;
  41. void setup(){
  42. size(400,400);
  43. ellipseMode(RADIUS);
  44. b[0] = new Bola(30,30);
  45. b[1] = new Bola(100,100);
  46. }
  47. void mousePressed(){
  48. for(int i=0; i<b.length;i++){
  49. if(b[i].dentro(mouseX,mouseY)){
  50. sel =i;
  51. break;
  52. }
  53. }
  54. if(sel==-1){
  55. b= (Bola[]) append(b, new Bola(mouseX,mouseY));
  56. }
  57. }
  58. void mouseDragged(){
  59. if(sel!=-1){
  60. int dx = mouseX-pmouseX;
  61. int dy = mouseY-pmouseY;
  62. b[sel].x+=dx;
  63. b[sel].y+=dy;
  64. }
  65. }
  66. void draw(){
  67. for(int i =0;i<b.length;i++){
  68. background(125);
  69. b[i].desenha();
  70. }
  71. }
Add Comment
Please, Sign In to add comment