예제 #1
0
 public Circulo(Ponto p, int r) {
   if (p == null) throw new NullPointerException("Ponto é null");
   if (r < 0) throw new IllegalArgumentException("Raio é negativo");
   setX(p.getX());
   setY(p.getY());
   setRaio(r);
 }
예제 #2
0
  public static void main(String[] args) {
    Ponto p1 = new Ponto();
    p1.setX(1);
    p1.setY(0);

    System.out.println(p1);

    Circulo c1 = new Circulo();
    c1.setPonto(p1);
    c1.setRaio(3);

    System.out.println(c1);

    Retangulo r1 = new Retangulo();
    r1.setPonto(p1);
    r1.setAltura(1);
    r1.setBase(2);

    System.out.println(r1);

    Quadrado q1 = new Quadrado();
    q1.setPonto(p1);
    q1.setLado(3);

    System.out.println(q1);
  }
예제 #3
0
파일: Ponto.java 프로젝트: udobranco/kcs
  /**
   * function to calculate the distance between two 3d points
   *
   * @param p point to calculate the distance to.
   * @return
   */
  public double distance(Ponto p) {

    double dx = this.getX() - p.getX();
    double dy = this.getY() - p.getY();
    double dz = this.getZ() - p.getZ();
    return Math.sqrt(dx * dx + dy * dy + dz * dz);
  }
예제 #4
0
 @Override
 public String toString() {
   String output = "\nid: " + id + "\ncodigo-linha: " + codigoLinha;
   output += "\nPontos de Ida: ";
   for (Iterator<Ponto> iterator = pontosIda.iterator(); iterator.hasNext(); ) {
     Ponto p = iterator.next();
     output += p.toString();
   }
   output += "\nPontos de Volta: ";
   for (Iterator<Ponto> iterator = pontosVolta.iterator(); iterator.hasNext(); ) {
     Ponto p = iterator.next();
     output += p.toString();
   }
   return output;
 }
  public static void main(String[] args) {

    Ponto ponto = new Ponto(10, 5);

    System.out.println("Valores originais");
    System.out.println("X: " + ponto.getX() + " Y: " + ponto.getY());

    ponto.setX(2);
    ponto.setY(3);
    System.out.println("Valores modificados");
    System.out.println("X: " + ponto.getX() + " Y: " + ponto.getY());

    System.out.println("Efetuado restore...");

    ponto.restore();
    System.out.println("X: " + ponto.getX() + " Y: " + ponto.getY());
  }
예제 #6
0
 @Override
 public void run() {
   this.y = (float) point.Y;
   this.x = (float) point.X;
   Socket sock = null;
   String message;
   try (Socket socket = new Socket("localhost", RequestSender.PORT);
       PrintStream pr = new PrintStream(socket.getOutputStream());
       BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream())); ) {
     pr.println(x + ";" + y + ";" + r);
     message = br.readLine();
   } catch (UnknownHostException e) {
     point.setGreyColor();
     return;
   } catch (IOException e) {
     return;
   }
   switch (message) {
     case "0":
       {
         point.setRedColor();
         if (point.isInKontur) {
           point.needAnimation = true;
         } else {
           point.needAnimation = false;
         }
         point.isInKontur = false;
       }
       break;
     case "1":
       {
         point.setBlueColor();
         point.isInKontur = true;
         point.needAnimation = false;
       }
       break;
     default:
       {
         point.setGreyColor();
       }
       break;
   }
 }
예제 #7
0
  public void draw() {
    t++;
    if (cam.available()) {
      prevFrame.copy(cam, 0, 0, cam.width, cam.height, 0, 0, cam.width, cam.height);
      // prevFrame.updatePixels();
      cam.read();
    }

    // cam.loadPixels();
    // prevFrame.loadPixels();
    loadPixels();

    ArrayList<Ponto> motionAtual = new ArrayList<Ponto>();
    for (int x = 0; x < cam.width; x++) {
      for (int y = 0; y < cam.height; y++) {
        int loc = x + y * cam.width;
        int current = cam.pixels[loc];
        int previous = prevFrame.pixels[loc];

        float r1 = red(current);
        float g1 = green(current);
        float b1 = blue(current);
        float r2 = red(previous);
        float g2 = green(previous);
        float b2 = blue(previous);
        float diff = dist(r1, g1, b1, r2, g2, b2);

        // How different are the colors?
        if (diff > threshold) {
          Ponto atual = new Ponto(current, loc);
          motionAtual.add(atual);
        } else {
          pixels[loc] = color(0);
        }
      }
    }

    if (t > rastroSize) { // after x draws
      rastros.add(motionAtual);
      if (rastros.size() == rastroSize) { // array completo? excluir rastro 0
        rastros.remove(0);
      }

      // aplicar rastro
      for (int x = 0; x < rastros.size(); x++) {
        ArrayList<Ponto> motion = rastros.get(x);
        // para cada motion
        for (int y = 0; y < motion.size(); y++) {
          // para cada ponto
          Ponto ponto = motion.get(y);

          //                  Float R = (new Float(-x*x*10 +255) / rastroSize) * 255;
          //					Float G = (new Float(-(x-rastroSize/2)*(x-rastroSize/2)*10+255) / rastroSize) *
          // 105;
          //					Float B = (new Float(-(x-rastroSize)*(x-rastroSize)*20+255) / rastroSize) * 55;
          //					Float A = R;
          //					Float cor = (new Float(x)/rastros.size())*255;

          int a = 255 / (x + 1);
          // System.out.println(a);

          pixels[ponto.getPosition()] = color(0, 0, 156, a); // Math.round(ponto.getCor());
        }
      }
    }

    updatePixels();

    if (debug) {
      text("rastros: " + rastroSize, 10, 30);
      text("contexto: " + threshold, 10, 60);
    }
  }
예제 #8
0
  public void desenhaReta(Cor c, Imagem img) {
    img.SetPixel(p0, c);
    img.SetPixel(p1, c);

    int x, y, erro, deltaX, deltaY;
    erro = 0;
    x = p0.x;
    y = p0.y;
    deltaX = p1.x - p0.x;
    deltaY = p1.y - p0.y;

    if ((Math.abs(deltaY) >= Math.abs(deltaX) && p0.y > p1.y)
        || (Math.abs(deltaY) < Math.abs(deltaX) && deltaY < 0)) {
      x = p1.x;
      y = p1.y;
      deltaX = p0.x - p1.x;
      deltaY = p0.y - p1.y;
    }
    if (deltaX >= 0) {
      if (Math.abs(deltaX) >= Math.abs(deltaY)) {

        for (int i = 1; i < Math.abs(deltaX); i++) {
          if (erro < 0) {
            x++;
            ponto.x = x;
            ponto.y = y;
            img.SetPixel(ponto, c);
            erro += deltaY;
          } else {
            x++;
            y++;
            ponto.x = x;
            ponto.y = y;
            img.SetPixel(ponto, c);
            erro += deltaY - deltaX;
          }
        }
      } else {

        for (int i = 1; i < Math.abs(deltaY); i++) {
          if (erro < 0) {
            x++;
            y++;
            ponto.x = x;
            ponto.y = y;
            img.SetPixel(ponto, c);
            erro += deltaY - deltaX;
          } else {
            y++;
            ponto.x = x;
            ponto.y = y;
            img.SetPixel(ponto, c);
            erro -= deltaX;
          }
        }
      }
    } else {
      if (Math.abs(deltaX) >= Math.abs(deltaY)) {

        for (int i = 1; i < Math.abs(deltaX); i++) {
          if (erro < 0) {
            x--;
            ponto.x = x;
            ponto.y = y;
            img.SetPixel(ponto, c);
            erro += deltaY;
          } else {
            x--;
            y++;
            ponto.x = x;
            ponto.y = y;
            img.SetPixel(ponto, c);
            erro += deltaY + deltaX;
          }
        }
      } else {

        for (int i = 1; i < Math.abs(deltaY); i++) {
          if (erro < 0) {
            x--;
            y++;
            ponto.x = x;
            ponto.y = y;
            img.SetPixel(ponto, c);
            erro += deltaY + deltaX;
          } else {
            y++;
            ponto.x = x;
            ponto.y = y;
            img.SetPixel(ponto, c);
            erro += deltaX;
          }
        }
      }
    }
  }
예제 #9
0
 public void move(Ponto p) {
   setX(p.getX());
   setY(p.getY());
 }
예제 #10
0
 public Circulo(int dia, Ponto p) {
   this(p.getX(), p.getY(), dia / 2);
 }