Java绘图算法

使用Java实现如图效果,围绕一点不断的旋转,当前扫描的区域用渐变颜色来渲染.请用最节能的方法实现,求高手们帮忙..谢谢.
补充一点,扫描区域是要可以自由设置大小的.

最节能就是把6个图片轮流画一次,不过你要把这六个图片弄成资源,然后就当作普通图来画,这是最简单的方法,如果你要全部自己弄,这6个图很难创建出来,你图里有渐变效果,这个渐变的值不知道是多少。我给一个画渐变园的类给你。如果要自己画可能有点用。
public class PaintTest {

public static void main(String[] args) {
JFrame frame = new PaintTestFrame();
frame.show();
}
}

class PaintTestFrame extends JFrame implements ActionListener {

public PaintTestFrame() {
setTitle("PaintTest");
setSize(400, 400);
addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

Container contentPane = getContentPane();
canvas = new PaintPanel();
contentPane.add(canvas, "Center");

JPanel buttonPanel = new JPanel();
ButtonGroup group = new ButtonGroup();

colorButton = new JRadioButton("Color", true);
buttonPanel.add(colorButton);
group.add(colorButton);
colorButton.addActionListener(this);

gradientPaintButton = new JRadioButton("Gradient Paint", false);
buttonPanel.add(gradientPaintButton);
group.add(gradientPaintButton);
gradientPaintButton.addActionListener(this);

texturePaintButton = new JRadioButton("Texture Paint", false);
buttonPanel.add(texturePaintButton);
group.add(texturePaintButton);
texturePaintButton.addActionListener(this);

contentPane.add(buttonPanel, "North");
}

public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
if (source == colorButton) {
canvas.setColor();
} else if (source == gradientPaintButton) {
canvas.setGradientPaint();
} else if (source == texturePaintButton) {
canvas.setTexturePaint();
}
}
private PaintPanel canvas;
private JRadioButton colorButton;
private JRadioButton gradientPaintButton;
private JRadioButton texturePaintButton;
}

class PaintPanel extends JPanel {

public PaintPanel() {
Image image = Toolkit.getDefaultToolkit().getImage("java2s.gif");
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(image, 0);
try {
tracker.waitForID(0);
} catch (InterruptedException e) {
}
bufferedImage = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = bufferedImage.createGraphics();
g2.drawImage(image, 0, 0, null);

setColor();
}

public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setPaint(paint);
Ellipse2D circle = new Ellipse2D.Double(0, 0, getWidth(), getHeight());
g2.fill(circle);
}

public void setColor() {
paint = Color.red; // Color implements Paint
repaint();
}

public void setGradientPaint() {
paint = new GradientPaint(0, 0, Color.red, (float) getWidth(),
(float) getHeight(), Color.blue);
repaint();
}

public void setTexturePaint() {
Rectangle2D anchor = new Rectangle2D.Double(0, 0, 2 * bufferedImage.getWidth(), 2 * bufferedImage.getHeight());
paint = new TexturePaint(bufferedImage, anchor);
repaint();
}
private Paint paint;
private BufferedImage bufferedImage;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-11-06
我觉得不用java最好。
做好相应的动画,在java中播放效率最高吧?
Flash做这个花不了5分钟!
如果非要用java做,第三方API我是不知道的,使用swing或AWT我知道有个线性渐变类,但你要的是扇形,扇形可以看做是若干条渐变弧构成的,所以现有的线性渐变类不能用。
倒是可以有种近似模拟算法。
1.设计个类。这个类根据初始半径、角度、起始半径颜色、结束半径颜色构造个近似渐变扇形。
具体方法:将扇形的角等分为若干份,计算出由起始色到结束色中间的各颜色插入值,分别以不同过渡中间色绘制若干扇形,以拼成整个扇形。
2.设计一个变换,能以某点为圆心,以指定角度旋转。这个利用三角函数运算,取起始扇形的颜色数据生成的旋转后的图像数据。
3.将不同角度旋转后的图像绘制在Graphics上。
第2个回答  2009-11-05
那个扇形区域 先用一个对象做好 然后每次角度变一下 显示出来就行了
第3个回答  2009-11-05
给你介绍个软件包吧
jfreechart 里面有很多图形
www.jfree.org
相似回答