html5应用canvas绘图太阳系实际效果

日期:2021-02-25 类型:科技新闻 

关键词:ps网页版在线制作,静态网页制作方法,微云网页版,怎么制作一个网页,django网页模板

星球 自变量名 公转周期 光色 暗色 水星 Mercury 87.70 #a69697 #5c3e40 金星 Venus 224.701.70 #c4bbac #1f1315 地球 Earth 365.2422 #78b1e8 #050c12 火花 Mars 686.98 #cec9b6 #76422d 木星 Jupiter 4332.589 #c0a48e #322 土星 Saturn 10759.95 #f7f9e3 #5c4553 天王星 Uranus 30799.095 #a7e115 #19243a 海王星 Neptune 60152.95 #0661b2 #1E3b73

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

拷贝编码
编码以下:

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

function DrawTrack(){
for(var i=0;i<8;i++){
cxt.beginPath();
cxt.arc(500,500,(i+1)*50,0,360,false);
cxt.closePath();
cxt.strokeStyle="#fff";
cxt.stroke();
}
}
function DrawStart(x,y,radius,cycle,sColor,eColor){
//画出星球必须哪些特性

//星球的座标点
this.x=x;
this.y=y;
//星球的半径
this.radius=radius;
//星球的色调(刚开始色,完毕色)
this.sColor=sColor;
this.eColor=eColor;
//建立1个渐变色色空目标
this.color=null;
this.time=0;
//公共性周期
this.cycle=cycle;
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;
}
}</p> <p> function Sun(){//太阳1
DrawStart.call(this,0,0,20,0,"#f00","#f90");
}
function Mercury(){//水星2
DrawStart.call(this,0,⑸0,10,87.70,"#A69697","#5c3e40");
}
function Venus(){//金星3
DrawStart.call(this,0,⑴00,10,224.71,"#c4bbac","#1f1315");
}
function Earth(){//地球4
DrawStart.call(this,0,⑴50,10,365.224,"#78b1e8","#050c12");
}
function Mars(){//火花5
DrawStart.call(this,0,⑵00,10,686.98,"#cec9b6","#76422d");
}
function Jupiter(){//木星6
DrawStart.call(this,0,⑵50,10,4332.589,"#c0a48e","#322");
}
function Saturn(){//土星7
DrawStart.call(this,0,⑶00,10,10759.5,"#f7f9e3","#5c4533");
}
function Uranus(){//天王星8
DrawStart.call(this,0,⑶50,10,30799.95,"#a7e1e5","#19243a");
}
function Neptune(){//天王星9
DrawStart.call(this,0,⑷00,10,60152.95,"#0661b2","#1E3b73");
}

var s=new Sun();//1

var m=new Mercury();//2
var v=new Venus();//3
var e=new Earth();//4
var ma=new Mars();//5
var j=new Jupiter();//6
var sa=new Saturn();//7
var ur=new Uranus();//8
var ne=new Neptune();//9

setInterval(function(){
cxt.clearRect(0,0,1000,1000);
DrawTrack();
s.draw();
m.draw();
v.draw();
e.draw();
ma.draw();
j.draw();
sa.draw();
ur.draw();
ne.draw();
},10);

上一篇:HTML5中Localstorage的应用实例教程 返回下一篇:没有了