Ejemplo n.º 1
0
 @Override
 public void run() {
   // TODO Auto-generated method stub
   int count = 0;
   while (count < 1000) {
     try {
       Thread.sleep(10);
     } catch (InterruptedException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
     b.x += getVX() * time;
     b.y += getVY() * time;
     if (b.x > 500) {
       b.x = 10;
     }
     if (b.x < 0) {
       b.x = 490;
     }
     if (b.y < 0) {
       b.y = 990;
     }
     if (b.y > 1000) {
       b.y = 10;
     }
     count++;
   }
   destroy();
 }
Ejemplo n.º 2
0
  public void addFixture(Shape shape, int offsetX, int offsetY) {
    BodyFixture collFix;

    switch (shape.getClass().getCanonicalName()) {
      case "java.awt.geom.Rectangle2D.Double":
        // create and add fixture
        Rectangle2D.Double newRect = (Rectangle2D.Double) shape;
        Rectangle collisionRect = new Rectangle(newRect.width, newRect.height);
        collFix = new BodyFixture(collisionRect);
        collisionRect.translate(offsetX, offsetY);
        collFix.setDensity(1);
        this.addFixture(collFix);

        // offset shape and add to drawing ahape list
        newRect.x += offsetX;
        newRect.y += offsetY;
        shapeList.add(newRect);
        break;
      case "java.awt.geom.Ellipse2D.Double":
        Ellipse2D.Double newEllipse = (Ellipse2D.Double) shape;
        Ellipse collisionEllipse = new Ellipse(newEllipse.width, newEllipse.height);
        collFix = new BodyFixture(collisionEllipse);
        collisionEllipse.translate(offsetX, offsetY);
        collFix.setDensity(1);
        this.addFixture(collFix);

        // offset shape and add to drawing ahape list
        newEllipse.x += offsetX;
        newEllipse.y += offsetY;
        shapeList.add(newEllipse);
        break;
    }
  }
Ejemplo n.º 3
0
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and ellipse.
  *
  * @return Returns true, if the circle is inside of the image bounds.
  */
 private boolean writeCircleAttributes(IXMLElement elem, SVGFigure f, Ellipse2D.Double ellipse) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType() &&
             ellipse.width == ellipse.height
             ) {
         
         Point2D.Double start = new Point2D.Double(ellipse.x, ellipse.y);
         Point2D.Double end = new Point2D.Double(ellipse.x + ellipse.width, ellipse.y + ellipse.height);
         t.transform(start, start);
         t.transform(end, end);
         ellipse.x = Math.min(start.x, end.x);
         ellipse.y = Math.min(start.y, end.y);
         ellipse.width = Math.abs(start.x - end.x);
         ellipse.height = Math.abs(start.y - end.y);
         
         elem.setAttribute("shape", "circle");
         elem.setAttribute("coords",
                 (int) (ellipse.x + ellipse.width / 2d)+","+
                 (int) (ellipse.y + ellipse.height / 2d)+","+
                 (int) (ellipse.width / 2d)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(ellipse.getBounds());
     } else {
         return writePolyAttributes(elem, f, (Shape) ellipse);
     }
 }
 @Override
 public void render(SVGGraphics2D g2d) {
   // On specifie la couleur dans un premier temps
   g2d.setColor(Util.getColorAwt(this.getDrawPath().getColor()));
   // On specifie le pinceau avec lequel dessiner
   BasicStroke bs = new BasicStroke(this.getDrawPath().getPen().getStroke());
   g2d.setStroke(bs);
   // On dessine le cercle sur le graphics 2D
   Ellipse2D.Double hole = new Ellipse2D.Double();
   hole.width = circle.getRayon();
   hole.height = circle.getRayon();
   hole.x = circle.getPosition().getX();
   hole.y = circle.getPosition().getY();
   g2d.draw(hole);
 }
Ejemplo n.º 5
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;
    Ellipse2D.Double cell = new Ellipse2D.Double(0, 0, DOT_SIZE, DOT_SIZE);
    for (int r = 0; r < MAX_ROWS; r++) {
      for (int c = 0; c < MAX_COLUMNS; c++) {
        if (isOccupied(r, c)) {
          cell.y = DOT_SIZE * r;
          cell.x = DOT_SIZE * c;
          g2.fill(cell);
        }
      }
    }
  }