GradientPaint旋转

时间:2012-01-09 20:32:31

标签: rotation gradient affinetransform

我有一个围绕自身一端旋转的形状,用渐变颜料着色。

GradientPaint turretShade = new GradientPaint(Math.round(x+((1.0/2.0)*le)),Math.round(y+((1.0/2.0)*le)),green,
                                                Math.round(x+((1.0/2.0)*le)), Math.round(y+((1.0/2.0)*le)+(1.0/10.0)*le)
                                                ,new Color(0x1A3C12));
g2d.setPaint(turretShade);


Rectangle2D rect = new Rectangle2D.Double(0,-(0.5/10.0)*le,(3.0/4.0)*le,(1.0/10.0)*le);
g.clearRect(0,0,1000,1000);
AffineTransform transform = new AffineTransform();
transform.translate(x+((1.0/2.0)*le),y+((1.0/2.0)*le)+(0.5/10.0)*le);
transform.rotate(Math.toRadians(turretang));
Shape rotateRect = transform.createTransformedShape(rect);
g2d.fill(rotateRect);
transform.translate(0,0);

我遇到的问题是,当我旋转形状时,它会移出设定的渐变。有关如何使用形状旋转渐变的想法吗?

0 个答案:

没有答案