Advertisement
Guest User

Aula22

a guest
Jun 25th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. void setup() {
  2.   size(600, 600);
  3.   noStroke();
  4. }
  5.  
  6. void draw() {
  7.   background(255);
  8.  
  9.   float x = mouseX-width/2;
  10.   float y = mouseY-height/2;
  11.   float[] vA = new float[2];
  12.   float[] vB = new float[2];
  13.  
  14.   vA = coordenadasPolares(atan2(y, x), 20);
  15.   vB = coordenadasPolares(atan2(y, x), 30);
  16.  
  17.   if (distancia2D(width/2, mouseX, height/2, mouseY) > 50) {
  18.  
  19.     fill(30, 170, 18);
  20.     ellipse(width/2, height/2, 140, 140);
  21.     fill(0);
  22.     ellipse(vB[0]+ width/2, vB[1]+ height/2, 40, 40);
  23.   } else {
  24.  
  25.     fill(30, 170, 18);
  26.     ellipse(width/2, height/2, 140, 140);
  27.     fill(0);
  28.     ellipse(mouseX, mouseY, 40, 40);
  29.   }
  30. }
  31.  
  32.  
  33. float distancia2D(float x1, float x2, float y1, float y2) {
  34.   float d = sqrt(pow((x2-x1), 2) + pow((y2-y1), 2));    
  35.   return d;
  36. }
  37.  
  38.  
  39. float[] coordenadasPolares(float ang, float raio) {  
  40.   float vC[] = new float[2];
  41.   vC[0] = raio*cos( (ang));
  42.   vC[1] = raio*sin( (ang));
  43.   return vC;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement