java学习之java模拟太阳系简单实现
2017-07-21 21:35
387 查看
项目要求:
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;
oy = (center.y+center.height/2)-b;
Color color =g.getColor();
g.setColor(Color.blue);
g.drawOval((int)ox, (int)oy, (int)owidth, (int)oheight);
g.setColor(color);
}
public Planet(String path,double a, double b, double speed, Star center) {
//super();
super(GameUtil.getImage(path));
this.a = a;
this.b = b;
this.speed = speed;
this.center = center;
this.x = center.x+a;
this.y = center.y;
/*this.img = GameUtil.getImage(path);
this.width = img.getWidth(null);
this.height = img.getHeight(null);*/
}
public Planet(String path,double a, double b, double speed, Star center, boolean satillite) {
// super();
/*this.a = a;
this.b = b;
this.speed = speed;
this.degree = degree;
this.center = center;*/
this(path, a, b, speed, center);
this.satillite = satillite;
}
public Planet() {
super();
}
/*public Planet(Image img, double x, double y) {
super(img, x, y);
}
public Planet(String path, double x, double y) {
super(path, x, y);
}*/
}
代码已经上传到GitHub上嘻嘻,GitHub:https://github.com/Strivema/SolarSystem
代码不是很完善,还请各位大佬指正。
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;
oy = (center.y+center.height/2)-b;
Color color =g.getColor();
g.setColor(Color.blue);
g.drawOval((int)ox, (int)oy, (int)owidth, (int)oheight);
g.setColor(color);
}
public Planet(String path,double a, double b, double speed, Star center) {
//super();
super(GameUtil.getImage(path));
this.a = a;
this.b = b;
this.speed = speed;
this.center = center;
this.x = center.x+a;
this.y = center.y;
/*this.img = GameUtil.getImage(path);
this.width = img.getWidth(null);
this.height = img.getHeight(null);*/
}
public Planet(String path,double a, double b, double speed, Star center, boolean satillite) {
// super();
/*this.a = a;
this.b = b;
this.speed = speed;
this.degree = degree;
this.center = center;*/
this(path, a, b, speed, center);
this.satillite = satillite;
}
public Planet() {
super();
}
/*public Planet(Image img, double x, double y) {
super(img, x, y);
}
public Planet(String path, double x, double y) {
super(path, x, y);
}*/
}
代码已经上传到GitHub上嘻嘻,GitHub:https://github.com/Strivema/SolarSystem
代码不是很完善,还请各位大佬指正。
相关文章推荐
- Java基础课程学习总结,使用LinkedList简单模拟队列数据结构和堆栈数据结构的实现
- 使用java简单模拟ping和telnet的实现
- java俄罗斯方块简单实现,新手适合学习
- Spring学习--面向抽象编程(模拟Spring的简单实现)
- 用Java实现简单的 O/R Mapping 模拟
- java学习之路——简单的工厂模式实现
- 使用java简单模拟ping和telnet的实现
- 黑马程序员-JAVA学习之用多线程实现简单UDP聊天程序
- JAVA学习笔记29——模拟实现ArrayList
- Java 反射学习(四)反射技术开发框架原理简单实现
- JAVA学习笔记30——模拟实现LinkedList
- 关于java打印功能的最简单实现的学习笔记
- 利用JAVA数组模拟集合实现简单的对象数组的添加
- 感知机学习算法的原始形式的java简单实现
- 使用java简单模拟ping和telnet的实现
- spring学习笔记6--简单模拟实现AOP(cglib版)
- JAVA学习第六十课 — UDP协议 &基于多线程模拟简单的QQ聊天程序
- 使用java简单模拟ping和telnet的实现
- RabbitMQ学习及实践2---介绍及简单Java实现
- [转]使用java简单模拟ping和telnet的实现