本文整理汇总了Java中java.awt.Graphics2D.rotate方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.rotate方法的具体用法?Java Graphics2D.rotate怎么用?Java Graphics2D.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Graphics2D
的用法示例。
在下文中一共展示了Graphics2D.rotate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: eval
import java.awt.Graphics2D; //导入方法依赖的package包/类
public BufferedImage eval() throws Exception {
final BufferedImage src = sop.getImage(null);
if (size == null) fixSize();
// remain opaque if our parent image is
final BufferedImage dst = ImageUtils.createCompatibleImage(
size.width, size.height, src.getTransparency() != BufferedImage.OPAQUE
);
final Graphics2D g = dst.createGraphics();
g.rotate(Math.PI/2.0*angle, src.getWidth()/2.0, src.getHeight()/2.0);
g.drawImage(src, 0, 0, null);
g.dispose();
return dst;
}
示例2: paintRotated
import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void paintRotated(Graphics g, int x, int y, Direction dir, Icon icon, Component dest) {
if (!(g instanceof Graphics2D) || dir == Direction.EAST) {
icon.paintIcon(dest, g, x, y);
return;
}
Graphics2D g2 = (Graphics2D) g.create();
double cx = x + icon.getIconWidth() / 2.0;
double cy = y + icon.getIconHeight() / 2.0;
if (dir == Direction.WEST) {
g2.rotate(Math.PI, cx, cy);
} else if (dir == Direction.NORTH) {
g2.rotate(-Math.PI / 2.0, cx, cy);
} else if (dir == Direction.SOUTH) {
g2.rotate(Math.PI / 2.0, cx, cy);
} else {
g2.translate(-x, -y);
}
icon.paintIcon(dest, g2, x, y);
g2.dispose();
}
示例3: drawInstance
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawInstance(InstancePainter painter, boolean isGhost) {
Graphics2D g = (Graphics2D) painter.getGraphics().create();
Location loc = painter.getLocation();
g.translate(loc.getX(), loc.getY());
Direction from = painter.getAttributeValue(StdAttr.FACING);
int degrees = Direction.EAST.toDegrees() - from.toDegrees();
double radians = Math.toRadians((degrees + 360) % 360);
g.rotate(radians);
GraphicsUtil.switchToWidth(g, Wire.WIDTH);
if (!isGhost && painter.getShowState()) {
g.setColor(painter.getPort(0).getColor());
}
g.drawLine(0, 0, 5, 0);
GraphicsUtil.switchToWidth(g, 1);
if (!isGhost && painter.shouldDrawColor()) {
BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
g.setColor(Value.repeat(Value.TRUE, width.getWidth()).getColor());
}
g.drawPolygon(new int[] { 6, 14, 6 }, new int[] { -8, 0, 8 }, 3);
g.dispose();
}
示例4: rotate
import java.awt.Graphics2D; //导入方法依赖的package包/类
public static BufferedImage rotate(BufferedImage img, double angle)
{
double sin = Math.abs(Math.sin(Math.toRadians(angle))),
cos = Math.abs(Math.cos(Math.toRadians(angle)));
int w = img.getWidth(null), h = img.getHeight(null);
int neww = (int) Math.floor(w*cos + h*sin),
newh = (int) Math.floor(h*cos + w*sin);
BufferedImage bimg = new BufferedImage(neww, newh, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g = bimg.createGraphics();
g.translate((neww-w)/2, (newh-h)/2);
g.rotate(Math.toRadians(angle), w/2, h/2);
g.drawRenderedImage(img, null);
g.dispose();
return bimg;
}
示例5: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paint(Graphics gr) {
panel.setSize(getSize().height, getSize().width);
Graphics2D g = (Graphics2D) gr;
g.translate(0, getHeight());
g.rotate(Math.PI + Math.PI / 2);
panel.paintMe(g);
}
示例6: drawFMS
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawFMS(Graphics2D g, double zoom, EarthquakeItem eq) {
g.scale(1. / zoom, 1. / zoom);
BufferedImage img = eq.getFMSImage();
switch (mapType) {
case MapApp.SOUTH_POLAR_MAP:
g.rotate( Math.toRadians( eq.eq.lon )) ;
break;
case MapApp.NORTH_POLAR_MAP:
g.rotate( -Math.toRadians( eq.eq.lon )) ;
break;
default:
break;
}
g.translate(-img.getWidth() / 2, -img.getHeight() / 2);
g.drawImage(img, null, null);
}
示例7: drawRotatedText
import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void drawRotatedText(final Graphics2D g, final double x, final double y, final int angle, final String text) {
final Graphics2D g2 = (Graphics2D) g.create();
g2.rotate(Math.toRadians(angle), x, y);
RenderEngine.drawText(g2, text, x, y);
g2.dispose();
}
示例8: drawTanx
import java.awt.Graphics2D; //导入方法依赖的package包/类
@SuppressWarnings("unused")
private void drawTanx(GeneralPath gp, Graphics2D g2d) {
for (double i = 0.000001; i <= 8 * Math.PI; i += 0.0001 * Math.PI) {
gp.lineTo(20 * i, 100 * -Math.tan(i));
}
g2d.draw(gp);
// 将当前画笔以原点为中心,旋转180度,画奇函数(关于原点对称)
g2d.rotate(Math.PI);
g2d.draw(gp);
}
示例9: drawSinx
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawSinx(GeneralPath gp, Graphics2D g2d) {
for (double i = 0.000001; i <= 8 * Math.PI; i += 0.0001 * Math.PI) {
gp.lineTo(20 * i, 100 * -Math.sin(i));
}
g2d.draw(gp);
g2d.rotate(Math.PI);
g2d.draw(gp);
}
示例10: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void draw(final BufferedImage from,final Image to) {
final Graphics2D g2d = (Graphics2D) to.getGraphics();
g2d.setComposite(AlphaComposite.Src);
g2d.setColor(Color.ORANGE);
g2d.fillRect(0, 0, to.getWidth(null), to.getHeight(null));
g2d.rotate(Math.toRadians(45));
g2d.clip(new Rectangle(41, 42, 43, 44));
g2d.drawImage(from, 50, 50, Color.blue, null);
g2d.dispose();
}
示例11: paint
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void paint(Graphics2D g, Bounds[] filter, double scaleX,
double scaleY) {
int k = 0;
for (int i = 0; i < components.length; i++)
if (components[i] != null) {
if (filter.length <= k)
return;
Component component = components[i];
Bounds bounds = this.bounds[i];
if (bounds.equals(filter[k])) {
if (bounds instanceof QBounds) {
QBounds qBounds = (QBounds) bounds;
k++;
Point2D point = qBounds.getLocation();
g.translate(point.getX(), point.getY());
if (qBounds.getRotation() != 0)
g.rotate(qBounds.getRotation());
g.scale(scaleX, scaleY);
component.paint(g, bounds, this);
g.scale(1 / scaleX, 1 / scaleY);
if (qBounds.getRotation() != 0)
g.rotate(-qBounds.getRotation());
g.translate(-point.getX(), -point.getY());
}
}
}
}
示例12: RenderEllipseRotated
import java.awt.Graphics2D; //导入方法依赖的package包/类
public static synchronized void RenderEllipseRotated(Graphics g, Vector2 position, Vector2 size, float degrees, float rotation, Color c)
{
Graphics2D g2d = (Graphics2D)g;
AffineTransform old = g2d.getTransform();
g2d.rotate(rotation, position.x + (size.x/2), position.y + (size.y/2));
g2d.setColor(c);
g2d.fillArc((int)position.x, (int)position.y, (int)size.x, (int)size.y, 0, (int)degrees);
g2d.setTransform(old);
}
示例13: draw
import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void draw(Graphics2D g) {
float wrap = (float)map.getWrap();
//get the limits of the displayed map
Rectangle2D rect = map.getClipRect2D();
double xmin = rect.getMinX();
double xmax = rect.getMaxX();
Projection proj = map.getProjection();
Point2D.Double pt = new Point2D.Double();
pt.x = getStartLon();
pt.y = getStartLat();
Point2D.Double p_start = (Point2D.Double) proj.getMapXY(pt);
if( wrap>0f ) {
while( p_start.x <= xmin ){p_start.x+=wrap;}
while( p_start.x >= xmax ){p_start.x-=wrap;}
}
pt.x = getEndLon();
pt.y = getEndLat();
Point2D.Double p_end = (Point2D.Double) proj.getMapXY(pt);
if( wrap>0f ) {
while( p_end.x <= xmin ){p_end.x+=wrap;}
while( p_end.x > wrap + xmin ){p_end.x-=wrap;}
}
//draw the shortest line - either p_start.x to p_end.x or the x+wrap values.
if ( ((p_start.x - p_end.x) * (p_start.x - p_end.x)) >
((p_start.x - (p_end.x + wrap)) * (p_start.x - (p_end.x + wrap))) ) {p_end.x += wrap;}
if ( ((p_start.x - p_end.x) * (p_start.x - p_end.x)) >
(((p_start.x + wrap) - p_end.x) * ((p_start.x + wrap) - p_end.x)) ) {p_start.x += wrap;}
if (lineNum == 1) g.setColor( Color.RED );
else g.setColor( Color.black );
double zoom = map.getZoom();
g.setStroke( new BasicStroke( 2f/(float)zoom ));
double arr_size = 6./zoom;
double sq_size = 6./zoom;
double dx = p_end.x - p_start.x, dy = p_end.y - p_start.y;
double angle = Math.atan2(dy, dx);
double len = Math.sqrt(dx*dx + dy*dy);
AffineTransform at = g.getTransform();
g.translate(p_start.x, p_start.y);
g.rotate(angle);
//draw the line
g.draw(new Line2D.Double(0, 0, len, 0));
//draw the arrow
Path2D arrow = new Path2D.Double();
double xpts[] = {len/3d, len/3d-arr_size, len/3d-arr_size, len/3d};
double ypts[] = {0, -arr_size, arr_size, 0};
arrow.moveTo(xpts[0], ypts[0]);
arrow.lineTo(xpts[1], ypts[1]);
arrow.lineTo(xpts[2], ypts[2]);
arrow.closePath();
if (lineNum == 1) g.setColor( Color.ORANGE );
else g.setColor( Color.ORANGE );
g.fill(arrow);
if (lineNum == 1) g.setColor( Color.RED );
else g.setColor( Color.black );
//draw squares at the end points
Rectangle2D startSq = new Rectangle2D.Double(0d-sq_size/2d, 0d-sq_size/2d, sq_size, sq_size);
Rectangle2D endSq = new Rectangle2D.Double(len-sq_size/2d, 0d-sq_size/2d, sq_size, sq_size);
g.fill(startSq);
g.fill(endSq);
g.setTransform(at);
}
示例14: drawDominantArrow
import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
* When is select a Dominat point is draw an arrow from the dominant
* @param g The graphic object
* @param dominant The vector with the dominant points
* @param dominates The vector with the dominates points
*/
public void drawDominantArrow(Graphics2D g, Vector<Point2D> dominant, Vector<Point2D> dominates) {
DPoint p;
DPoint p2;
boolean first = true;
for (int i = 0; i < dominates.size(); i++) {
p = (DPoint) dominates.get(i);
if (p.isSelect()) {
for (int k = dominant.size() - 1; k >= 0; k--) {
p2 = (DPoint) dominant.get(k);
if (p2.isSelect()) {
g.setColor(Color.MAGENTA);
//Draw Arrow
//The angle is calculete throw the rotator point
DPoint rotator = new DPoint(p2.getX() - p.getX(), p2.getY() - p.getY());
double angle = rotator.polarAngle();
//The thestination point in not into the point but near the point
int xPoint = (int) (p.getX() * scale) + tran_x + (int) (pointSize * Math.cos(angle));
int yPoint = tran_y - (int) (p.getY() * scale) - (int) (pointSize * Math.sin(angle));
g.drawLine(xPoint, yPoint, (int) (p2.getX() * scale) + tran_x, tran_y - (int) (p2.getY() * scale));
//The rotation turn the arrow in the right position
g.rotate(-angle, xPoint, yPoint);
g.drawLine(xPoint, yPoint, xPoint + 4 + pointSize, yPoint - pointSize);
g.drawLine(xPoint, yPoint, xPoint + 4 + pointSize, yPoint + pointSize);
g.rotate((2 * Math.PI) + angle, xPoint, yPoint);
//Draw Label on the first arrow (only)
if (first) {
first = false;
g.setColor(new Color(152, 61, 168));
int fontSize = 7 + pointSize;
Font f = new Font("Arial", Font.PLAIN, fontSize);
g.setFont(f);
double x = (p.getX() + p2.getX()) / 2;
double y = (p.getY() + p2.getY()) / 2;
g.drawString("Dominating", (int) (x * scale) + tran_x + 7, tran_y - 3 - (int) (y * scale));
}
}
}
}
}
}
示例15: paintBase
import java.awt.Graphics2D; //导入方法依赖的package包/类
private void paintBase(InstancePainter painter) {
GateAttributes attrs = (GateAttributes) painter.getAttributeSet();
Direction facing = attrs.facing;
int inputs = attrs.inputs;
int negated = attrs.negated;
Object shape = painter.getGateShape();
Location loc = painter.getLocation();
Bounds bds = painter.getOffsetBounds();
int width = bds.getWidth();
int height = bds.getHeight();
if (facing == Direction.NORTH || facing == Direction.SOUTH) {
int t = width;
width = height;
height = t;
}
if (negated != 0) {
width -= 10;
}
Graphics g = painter.getGraphics();
Color baseColor = g.getColor();
if (shape == AppPreferences.SHAPE_SHAPED && paintInputLines) {
PainterShaped.paintInputLines(painter, this);
} else if (negated != 0) {
for (int i = 0; i < inputs; i++) {
int negatedBit = (negated >> i) & 1;
if (negatedBit == 1) {
Location in = getInputOffset(attrs, i);
Location cen = in.translate(facing, 5);
painter.drawDongle(loc.getX() + cen.getX(), loc.getY() + cen.getY());
}
}
}
g.setColor(baseColor);
g.translate(loc.getX(), loc.getY());
double rotate = 0.0;
if (facing != Direction.EAST && g instanceof Graphics2D) {
rotate = -facing.toRadians();
Graphics2D g2 = (Graphics2D) g;
g2.rotate(rotate);
}
if (shape == AppPreferences.SHAPE_RECTANGULAR) {
paintRectangular(painter, width, height);
} else if (shape == AppPreferences.SHAPE_DIN40700) {
paintDinShape(painter, width, height, inputs);
} else { // SHAPE_SHAPED
if (negateOutput) {
g.translate(-10, 0);
paintShape(painter, width - 10, height);
painter.drawDongle(5, 0);
g.translate(10, 0);
} else {
paintShape(painter, width, height);
}
}
if (rotate != 0.0) {
((Graphics2D) g).rotate(-rotate);
}
g.translate(-loc.getX(), -loc.getY());
painter.drawLabel();
}