太阳系运转小demo

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title></title>
<!--<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>-->
<style type="text/css">
* {
padding: 0;
margin: 0;
}

</style>

</head>

<body>
<canvas id="myCanvas" width="1000" height="1000" style="background: #000;"></canvas>

<script type="text/javascript">
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
//时间参数,单位为天

function drawTrack() {
for(var i=0;i<=8;i++){
ctx.beginPath();
ctx.arc(500,500,i*30,0,360,false);
ctx.closePath();
ctx.strokeStyle = "#fff";
ctx.stroke();
}
}

function star(x,y,radius,cycle,sColor,eColor){
this.x = x;
this.y = y;
this.radius = radius;
this.cycle = cycle;
this.color = null;
this.sColor = sColor;
this.eColor = eColor;
this.time = 0;
this.draw = function(){
ctx.save();
ctx.translate(500,500);
ctx.rotate(this.time*(360/this.cycle)*Math.PI/180);
ctx.beginPath();
ctx.arc(this.x,this.y,this.radius,0,360,false);
ctx.closePath();
this.color = ctx.createRadialGradient(this.x,this.y,0,this.x,this.y,this.radius);
this.color.addColorStop(0,this.sColor);
this.color.addColorStop(1,this.eColor);
ctx.fillStyle = this.color;
ctx.fill();
ctx.restore();
this.time+=1;
}
}

drawTrack();

var sun = new star(0,0,10,0,"#f00","#f90");
var earth = new star(0,-30,5,87.70,"#a69697","#5c3e40");
var gold = new star(0,-90,5,4332,"#f7f9e3","#5c4533");

function move(){
ctx.clearRect(0,0,1000,1000);
drawTrack();
sun.draw();
gold.draw();
earth.draw();
}


setInterval(move,10);
</script>
</body>

</html>

转载于:https://www.cnblogs.com/-cj-blog/p/5178036.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值