html5太阳系,初学html5太阳系

var cxt=document.getElementById('canvas').getContext('2d')

function draw(){

for(var i=0;i<8;i++){

cxt.beginPath();

cxt.strokeStyle="gray";

cxt.closePath();

cxt.arc(500,500,(i+1)*50,0,360,false);

cxt.closePath();

cxt.stroke();

}

}

draw();

function Star(x,y,radius,cycle,scolor,ecolor){

this.x=x;

this.y=y;

this.radius=radius;

this.cycle=cycle;

this.scolor=scolor;

this.ecolor=ecolor;

this.color=null;

this.time=0;

this.draw=function(){

cxt.save();

cxt.translate(500,500);

cxt.rotate(this.time*(360/this.cycle)*Math.PI/180);

cxt.beginPath();

cxt.arc(this.x,this.y,this.radius,0,360,false);

cxt.closePath();

this.color=cxt.createRadialGradient(this.x,this.y,0,this.x,this.y,this.radius);

this.color.addColorStop(0,this.scolor);

this.color.addColorStop(1,this.ecolor);

cxt.fillStyle=this.color;

cxt.fill();

cxt.restore();

this.time+=1;

}

}

function Sun(){

Star.call(this,0,0,20,0,"#ff0000","#ff9900");

}

var sun=new Sun();

function di(){

Star.call(this,0,-50,10,87,"#A69697","#5C3E40");

}

var di=new di();

function water(){

Star.call(this,0,-100,10,224.701,"#C4BBAC","#1F1315");

}

var water=new water();

function jin(){

Star.call(this,0,-150,10,365.2422,"#78B1E8","#050C12");

}

var jin=new jin();

function huo(){

Star.call(this,0,-200,10,686.98,"#CEC9B6","#76422D");

}

var huo=new huo();

function mu(){

Star.call(this,0,-250,10,4332.589,"#C0A48E","#322222");

}

var mu=new mu();

function tu(){

Star.call(this,0,-300,10,10759.5,"#F7F9E3","#5C4533");

}

var tu=new tu();

function hai(){

Star.call(this,0,-350,10,30799.095,"#A7E1E5","#19243A");

}

var hai=new hai();

function ming(){

Star.call(this,0,-400,10,164.8*365,"#0661B2","#1E3B73");

}

var ming=new ming();

function move(){

cxt.clearRect(0,0,1000,1000)

draw();

ming.draw();

sun.draw();

di.draw();

water.draw();

jin.draw();

huo.draw();

mu.draw();

tu.draw();

hai.draw();

}

setInterval(move,10);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值