Пример #1
0
 /**
  * Draws a Circle object on the GrapherPanel as a series of 1 pixel wide lines contained in the
  * Circle's sides variable.
  *
  * @param The Circle to paint.
  */
 private void paintCircle(Circle c) {
   g.setColor(Color.GREEN);
   g.drawOval(
       (int) (c.getCenter().getX() - c.getRadius()),
       (int) (c.getCenter().getY() - c.getRadius()),
       (int) (c.getRadius() * 2),
       (int) (c.getRadius() * 2));
 }
Пример #2
0
  public void drawAll(Graphics g) {
    Circle currentCircle;

    for (int i = 0; i < circles.size(); i++) {
      currentCircle = (Circle) (circles.get(i));
      currentCircle.draw(g);
    }
  }
Пример #3
0
  // -----------------------------------------------------------------
  //  Draws this panel by requesting that each circle draw itself.
  // -----------------------------------------------------------------
  public void paintComponent(Graphics page) {
    super.paintComponent(page);

    circle1.draw(page);
    circle2.draw(page);
    circle3.draw(page);
    circle4.draw(page);
    circle5.draw(page);
  }
 private Point autoRecognize(final BufferedImage image) {
   final CircleHoughTransform cht =
       new CircleHoughTransform(image, backgroundColor, minRadius, maxRadius, 1);
   cht.performHoughTransform();
   final Circle circle = cht.findOpenCircle(threshold);
   if (circle != null) {
     return new Point(circle.x(), circle.y());
   } else {
     return null;
   }
 }
Пример #5
0
  public void removeNearestCircle(int x1, int y1) {
    Circle circ;
    double minDist = Double.MAX_VALUE;
    int minDisIndex = -1;
    for (int i = 0; i < circles.size(); i++) {
      circ = (Circle) (circles.get(i));
      if (circ.distanceTo(x1, y1) < minDist) {
        minDist = circ.distanceTo(x1, y1);
        minDisIndex = i;
      }
    }

    if (minDisIndex >= 0 && minDist < 300) {
      circles.removeElementAt(minDisIndex);
    }
  }
Пример #6
0
  /** getCellsBinary */
  private void createCells() {
    ConstraintDefinition constraint = model.createConstraintDefinition(template);
    // int count = template.parameterCount();
    ActivityDefinitonCell[] cells = new ActivityDefinitonCell[constraint.parameterCount()];
    // ActivityDefinition [] params = new ActivityDefinition [count];
    double total = 0;
    int c = 0;
    for (Parameter parameter : constraint.getParameters()) {

      ActivityDefinition activityDefinition = model.addActivityDefinition();
      activityDefinition.setName(parameter.getName());
      // params[i] = activityDefinition;
      constraint.addBranch(parameter, activityDefinition);

      ActivityDefinitonCell activityDefinitionCell =
          view.getActivityDefinitionCell(activityDefinition);
      total = activityDefinitionCell.getWidth() + 10;
      cells[c++] = activityDefinitionCell;
    }

    double radius = total / 2 + 100;
    Point[] points = Circle.getPoints(radius, cells.length);

    for (int i = 0; i < cells.length; i++) {
      ActivityDefinitonCell cell = cells[i];
      int x = points[i].x + (new Double(cell.getWidth() / 2)).intValue();
      int y = points[i].y + (new Double(cell.getHeight() / 2)).intValue();
      cell.setPosition(new Point(x, y));
    }
    model.addConstraintDefiniton(constraint);
  }
Пример #7
0
  public void update(Graphics g) {
    if (offimage == null) {
      offimage = createImage(getWidth(), getHeight());
      offg = offimage.getGraphics();
    }
    Graphics2D g2d = (Graphics2D) offg;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    circleList.add(new Circle(getWidth(), getHeight()));
    for (Circle circle : circleList) {
      circle.grow();
      g2d.setColor(circle.color);
      g2d.fillOval(
          circle.x - circle.radius, circle.y - circle.radius, circle.radius * 2, circle.radius * 2);
      if (circle.radius > 100) {
        circleList.remove(circle);
      }
    }

    g.drawImage(offimage, 0, 0, this);
  }
  @Override
  public void mouseDragged(MouseEvent e, CS355Drawing model, Color c) {

    // Get shape at saved index from model and verify it is a circle
    Shape shape = model.getShape(this.index);
    if (!(shape instanceof cs355.model.drawing.Circle)) {
      GUIFunctions.printf(
          "Invalid shape - expected cs355.model.drawing.Circle at index %d", this.index);
      return;
    }

    // Cast the shape to a circle and save the new coordinates
    Circle circle = (Circle) shape;

    // Initialize new center coordinates to initial coordinates
    Point2D.Double center = new Point2D.Double();
    center.setLocation(this.initialCoordinates);

    // Get current pointer coordinates
    Point2D.Double currentCoordinates = new Point2D.Double();
    currentCoordinates.setLocation(e.getPoint());

    // Find difference between pointer and initial coordinates to get correct orientation
    double xDifference = currentCoordinates.getX() - initialCoordinates.getX();
    double yDifference = currentCoordinates.getY() - initialCoordinates.getY();

    // Get radius
    double radius = Math.min(Math.abs(xDifference), Math.abs(yDifference)) / 2.0;

    // Get unit vectors for the differences to preserve sign
    double xDirection = xDifference / Math.abs(xDifference);
    double yDirection = yDifference / Math.abs(yDifference);

    // Calculate position of the center of the circle
    center.x = this.initialCoordinates.getX() + (xDirection * radius);
    center.y = this.initialCoordinates.getY() + (yDirection * radius);

    // Set the new parameters
    circle.setCenter(center);
    circle.setRadius(radius);
  }
Пример #9
0
  public void dupliquer() {
    for (Shape s : shapeSelect) {
      Point p = new Point(s.getOrigin());
      p.y += 100;

      if (s instanceof Rectangle) {
        Rectangle r = (Rectangle) s;
        shapes.add(new Rectangle(p, r.getWidth(), r.getHeight(), r.getColor()));
        cpt++;
        notifyObservers();
      }

      if (s instanceof Circle) {
        Circle c = (Circle) s;
        shapes.add(new Circle(p, c.getRadius(), c.getColor()));
        cpt++;
        notifyObservers();
      }
    }

    shapeSelect.clear();
    this.repaint();
  }