/** * 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); } }
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; } }
@Override public void plotSymbol() { int row, col; Hexagon thisHex; Ellipse2D.Double thisEllipse; double x, y; int i; double[] radii = {10.85, 8.97, 7.10, 5.22, 3.31, 1.43}; // Hexagons for (row = 0; row < 33; row++) { for (col = 0; col < 30; col++) { if (grid[row][col]) { thisHex = new Hexagon(); x = (2.46 * col) + 1.23; if ((row & 1) != 0) { x += 1.23; } y = (2.135 * row) + 1.43; thisHex.setCentre(x, y); hex.add(thisHex); } } } // Circles for (i = 0; i < 6; i++) { thisEllipse = new Ellipse2D.Double(); thisEllipse.setFrameFromCenter(35.76, 35.60, 35.76 + radii[i], 35.60 + radii[i]); target.add(thisEllipse); } }
/** * Paint the clock * * @param c a component * @param g graphic object * @param x * @param y */ public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2 = (Graphics2D) g; Ellipse2D.Double circle = new Ellipse2D.Double(); circle.setFrameFromCenter(250, 250, 400, 400); g2.draw(circle); Line2D.Double hHand = new Line2D.Double( 250, 250, 250 + HOUR_HAND_LENGTH * Math.sin(Math.PI * (double) hour / 6), 250 - HOUR_HAND_LENGTH * Math.cos(Math.PI * (double) hour / 6)); Line2D.Double mHand = new Line2D.Double( 250, 250, 250 + MIN_HAND_LENGTH * Math.sin(Math.PI * (double) min / 30), 250 - MIN_HAND_LENGTH * Math.cos(Math.PI * (double) min / 30)); Line2D.Double sHand = new Line2D.Double( 250, 250, 250 + SEC_HAND_LENGTH * Math.sin(Math.PI * (double) sec / 30), 250 - SEC_HAND_LENGTH * Math.cos(Math.PI * (double) sec / 30)); g2.draw(hHand); g2.draw(mHand); g2.draw(sHand); }
public void update() { _circle.setFrame( _circle.getX() + (_speed * (Math.cos(Math.toRadians(_angle))) / 100), _circle.getY() - (_speed * (Math.sin(Math.toRadians(_angle))) / 100) + _gravity, 10, 10); _gravity += 0.06; }
@Override public boolean contains(int x, int y) { int xx = (SHADOW_SIZE - 6); int yy = (SHADOW_SIZE - 6); int w = getWidth() - xx * 2; int h = getHeight() - yy * 2; int arc = 15; java.awt.geom.Ellipse2D.Double rec = new java.awt.geom.Ellipse2D.Double(xx, yy, w, h); // System.out.println("cont"+x+" "+y+" "+rec.contains(x, y)); return rec.contains(x, y); }
@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); }
@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); } } } }
@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(); }
public void paintIcon(Component component, Graphics graphics, int x, int y) { Graphics2D g2d = ((Graphics2D) graphics); RenderingHints hints = g2d.getRenderingHints(); g2d.setRenderingHints(UIColors.iconRH); Shape c; if (pi != null) { pi.paintIcon(component, graphics, x, y); } else { c = new Ellipse2D.Double(x, y, w, h); GradientPaint gp = new GradientPaint(x, y, c1, x + w, y + h, c2, false); g2d.setPaint(gp); g2d.fill(c); } // c = new RoundRectangle2D.Double(x + Math.round(w / 3.0), y, Math.round(w / 3.0), h, 2, 2); g2d.setColor(UIColors.applyAlpha(c1, 175)); Ellipse2D.Double e = new Ellipse2D.Double(); e.setFrame(x + w / 2.0, y + h / 2.0, w / 2.0, h / 2.0); g2d.fill(e); e.setFrame(x, y, w / 2.0, h / 2.0); g2d.fill(e); g2d.setRenderingHints(hints); }
public boolean intersects(BigAsteroid as) { return (as.circle.intersects(b.getBounds2D())); }
public boolean bounce(Rectangle2D.Double rect, boolean isPaddle) { int _oldAngle = _angle; double x = _circle.getCenterX(); double y = _circle.getCenterY(); if (isPaddle) { if (_circle.intersects(rect)) { _gravity = -4; if ((_circle.getY() + 10) >= rect.getY() && _circle.getX() + 5 >= rect.getX() && _circle.getX() + 5 <= rect.getX() + rect.getWidth() && _circle.intersects(rect)) { _angle = 135 - (int) (90.0 * ((x - rect.getX()) / rect.getWidth())); } else if (rect.getX() - x <= 5) { _angle = 150; } else if (rect.getX() + rect.getWidth() - _circle.getX() <= 5) { _angle = 30; } } } else { if (_circle.intersects(rect)) { if (x >= rect.getX() + .1 && x <= rect.getX() + rect.getWidth() + .1) _angle = 0 - _angle; else if (y >= rect.getY() + .1 && y <= rect.getY() + rect.getWidth() + .1) if (_angle > 180) _angle = 540 - _angle; else _angle = 180 - _angle; } } if (_circle.getX() + (_speed * (Math.cos(Math.toRadians(_angle))) / 100) < 0 && !_intersects) { if (_angle > 180) _angle = 540 - _angle; else _angle = 180 - _angle; return false; } if (_circle.getY() - (_speed * (Math.sin(Math.toRadians(_angle))) / 100) < 0 && !_intersects) { _angle = 0 - _angle; _gravity = 0; return false; } if (_circle.getX() + _circle.getWidth() + (_speed * (Math.cos(Math.toRadians(_angle))) / 100) > 800 && !_intersects) { if (_angle > 180) _angle = 180 + 180 - (_angle - 180); else _angle = 180 - _angle; return false; } if (_circle.getX() + _circle.getWidth() + (_speed * (Math.cos(Math.toRadians(_angle))) / 100) > 800 || _circle.getY() < 0 || _circle.getX() < 0) _intersects = true; else _intersects = false; return _angle != _oldAngle; }