让图像在Java中以圆圈形式飞行 [英] Let an image fly in a circle in Java
本文介绍了让图像在Java中以圆圈形式飞行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要让图像在一个圆圈中飞行,我现在只是卡在一个部分上。
为了计算积分,我需要使用毕达哥拉斯来计算高度(B点)。
I need to let an image fly in a cirle, i'm now only stuck on one part. For calculating the points it needs to go im using pythagoras to calculate the height (point B).
现在使用sqrt函数我的错误是我无法将double转换为int。
这是我的代码:
Now when using the sqrt function I the the error that I can't convert a double to an int. Here's my code :
package vogel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
public class vogel extends Component {
private int x;
private int r;
private int b;
BufferedImage img;
public vogel() {
try {
img = ImageIO.read(new File("F:/JAVA/workspace/School/src/vogel/vogel.png"));
} catch (IOException e) {
}
r = 6;
}
@Override
public void paint(Graphics g) {
for(int i = -r; i <= r; i++) {
x = i;
b = Math.sqrt(r^2 - x^2);
g.drawImage(img, x, b, this);
}
}
public static void main(String[] args) {
JFrame f = new JFrame("Boot");
f.setSize(1000,1000);
f.add(new vogel());
f.setVisible(true);
for (int number = 1; number <= 1500000; number++) {
f.repaint();
try {
Thread.sleep(50);
} catch (InterruptedException e) {}
}
}
}
希望你们其中一个人可以帮助我
Hope one of you guys can help me out
推荐答案
施展价值。 E.G。
b = (int)Math.sqrt(r^2 - x^2);
这篇关于让图像在Java中以圆圈形式飞行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文