项目要求:
1. 实现宇宙太空和太阳的显示
2. 实现地球的轨道运行
3. 实现月球的轨道
4. 实现其他行星的轨道运行
package ray.solar;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import ray.util.GameUtil;
public class Planet extends Star{
double a;
double b;
double speed;
double degree;
Star center;
boolean satillite;
@Override
public void draw(Graphics g) {
//super.draw(g);
/*g.drawImage(img, (int)x, (int)y,null);*/
super.draw(g);
if(!satillite){
drawTrace(g);
}
move();
}
public void move(){
x = (center.x+center.width/2)+a*Math.cos(degree);
y = (center.y+center.height/2)+b*Math.sin(degree);
degree +=speed;
}
public void drawTrace(Graphics g){
double ox,oy,owidth,oheight;
owidth = 2*a;
oheight = 2*b;
ox = (center.x+center.width/2)-a;

这篇博客介绍了一个使用Java编程实现的太阳系模拟项目,涵盖了显示太阳、地球轨道运行、月球轨道以及其他行星轨道的基本功能。虽然代码仍有改进空间,但已展现出初步的宇宙动态效果。
最低0.47元/天 解锁文章
1134

被折叠的 条评论
为什么被折叠?



