首页>代码>java swing动画模拟太阳系行星运行动画特效>/SolarSystem/src/cn/xia/solar/Planet.java
package cn.xia.solar;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;

import cn.xia.util.GameUtil;

public class Planet extends Star{
	//除了图片坐标 行星沿着某个椭圆运行:长轴,短轴,速度,角度; 绕着某个Star.
	double longAxis;
	double shortAxis;
	double speed;
	double degree;
	Star center;
	boolean satellite;



	public Planet(Star center,String imgpath, double longAxis, double shortAxis, double speed,boolean satellite) {
		this(center, imgpath, longAxis, shortAxis, speed);
		this.satellite = satellite;
	}

	public Planet(Star center,String imgpath, double longAxis, double shortAxis, double speed) {
		super(GameUtil.getImage(imgpath));
		this.center = center;
		this.x=center.x+longAxis;
		this.y=center.y;

		this.longAxis = longAxis;
		this.shortAxis = shortAxis;
		this.speed = speed;

		this.width = img.getWidth(null);
		this.height = img.getHeight(null);

	}

	public void draw(Graphics g){
		//g.drawImage(img,(int)x,(int)y,null);
		super.draw(g);
		//沿着椭圆轨迹飞行
		if(!satellite){
			//drawTrace(g);

		}
		move();
	}

	public void move(){
		x=(center.x+15) + longAxis*Math.cos(degree);
		y=(center.y+15) + shortAxis*Math.sin(degree);

		degree +=speed;
	}

	public void drawTrace(Graphics g){
		double ovalX,ovalY,ovalWidth,ovalHeigth;

		ovalWidth=longAxis*2;
		ovalHeigth= shortAxis*2;
		ovalX=center.x-longAxis+15;
		ovalY=center.y-shortAxis+15;
		Color c = g.getColor();
		g.setColor(Color.blue);
		g.drawOval((int)ovalX, (int)ovalY, (int)ovalWidth, (int)ovalHeigth);
		g.setColor(c);
	}


	public Planet(String imgpath, double x, double y) {
		super(imgpath, x, y);
	}
	public Planet(Image img, double x, double y) {
		super(img, x, y);
	}

}
最近下载更多
lczbossd  LV1 2023年11月21日
qq1434100519  LV1 2023年11月1日
lx1216  LV1 2023年10月7日
微信网友_6575311013466112  LV1 2023年7月24日
xiaokang1  LV9 2023年6月3日
azuldsf  LV1 2023年2月20日
1151062880  LV1 2022年11月11日
liuhuaxiang  LV1 2022年10月1日
wanshubin  LV1 2022年10月1日
微信网友_6134148373270528  LV1 2022年9月15日
最近浏览更多
lczbossd  LV1 2023年11月21日
qq1434100519  LV1 2023年11月1日
EFWAGGFAWGR 2023年10月19日
暂无贡献等级
lx1216  LV1 2023年10月7日
微信网友_6575311013466112  LV1 2023年7月24日
xiaokang1  LV9 2023年6月3日
茶永军 2023年5月23日
暂无贡献等级
暂无贡献等级
逍遥2020  LV11 2023年3月29日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友