Advertisement
bethdps

Olho

Jan 25th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. int bolaOlhoD = 100;
  2. int fundoOlhoD = 250;
  3.  
  4. void setup(){
  5.   size(800,800);
  6. }
  7.  
  8. void draw(){
  9.   background(125);
  10.   fill(255);
  11.   fundoOlho();
  12.   fill(0);
  13.   bolaOlho();
  14. }
  15.  
  16. void fundoOlho(){
  17.   strokeWeight(5);
  18.   ellipse(width/2,height/2, fundoOlhoD, fundoOlhoD);
  19. }
  20.  
  21. void bolaOlho(){
  22.  
  23.   int x = mouseX;
  24.   int y = mouseY;
  25.  
  26.   int distancia = distancia2D(width/2, height/2, x,y);
  27.  
  28.   if(distancia > fundoOlhoD/2 - bolaOlhoD/2){
  29.      float angulo = atan2(y-height/2,x-width/2);
  30.      
  31.      y =  height/2 + (int)(sin(angulo)*(fundoOlhoD/2 - bolaOlhoD/2));
  32.      x = width/2 + (int)(cos(angulo)*(fundoOlhoD/2 - bolaOlhoD/2));
  33.   }
  34.  
  35.  
  36.  
  37.   pushMatrix();
  38.   ellipse(x, y, bolaOlhoD,bolaOlhoD);
  39.   popMatrix();
  40. }
  41.  
  42. int distancia1D(int A, int B){
  43.   return abs(A-B);
  44. }
  45.  
  46. int distancia2D(int A_X, int A_Y, int B_X, int B_Y){
  47.   return round(sqrt( pow(distancia1D(A_X,B_X), 2) + pow(distancia1D(A_Y,B_Y), 2) ));
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement