Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int bolaOlhoD = 100;
- int fundoOlhoD = 250;
- void setup(){
- size(800,800);
- }
- void draw(){
- background(125);
- fill(255);
- fundoOlho();
- fill(0);
- bolaOlho();
- }
- void fundoOlho(){
- strokeWeight(5);
- ellipse(width/2,height/2, fundoOlhoD, fundoOlhoD);
- }
- void bolaOlho(){
- int x = mouseX;
- int y = mouseY;
- int distancia = distancia2D(width/2, height/2, x,y);
- if(distancia > fundoOlhoD/2 - bolaOlhoD/2){
- float angulo = atan2(y-height/2,x-width/2);
- y = height/2 + (int)(sin(angulo)*(fundoOlhoD/2 - bolaOlhoD/2));
- x = width/2 + (int)(cos(angulo)*(fundoOlhoD/2 - bolaOlhoD/2));
- }
- pushMatrix();
- ellipse(x, y, bolaOlhoD,bolaOlhoD);
- popMatrix();
- }
- int distancia1D(int A, int B){
- return abs(A-B);
- }
- int distancia2D(int A_X, int A_Y, int B_X, int B_Y){
- return round(sqrt( pow(distancia1D(A_X,B_X), 2) + pow(distancia1D(A_Y,B_Y), 2) ));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement