Html
    Css
    Js
1
<canvas id="canvas" width="1000" height="1000"></canvas>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
#canvas{display: block;background-color:#000;margin:0 auto;}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var canvas = document.getElementById("canvas");
var cxt = canvas.getContext('2d');
var time = 0;
var EarchRotate = 0;
var MoonX = 0;
var MoonY = 0;
//
function starRoute(){
for(var i=0; i<=8; i++){
cxt.save();
cxt.translate(500,500);
cxt.strokeStyle = '#fff';
cxt.beginPath();
cxt.arc(0,0,i*55,0,2*Math.PI,false);
cxt.closePath();
cxt.stroke();
cxt.restore();
}
}
//Start(js)
function Star(name,x,y,r,startColor,endColor,revolution){
this.name = name; //
this.x = x; // x,y
this.y = y;
this.r = r; // r
this.startColor = startColor; // start,end
this.endColor = endColor;
this.revolution = revolution;// revolution
}
Star.prototype = {
constructor : Star,
drawStar : function(){
cxt.save();
cxt.translate(500,500);
//
var gradient = cxt.createRadialGradient(this.x,this.y,0,this.x,this.y,this.r);
gradient.addColorStop(0,this.startColor);
gradient.addColorStop(1,this.endColor);
cxt.fillStyle = gradient;
cxt.beginPath();
if(this.name == ''){
//,moon
EarchRotate = time*360/this.revolution*Math.PI/180;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
↑上面代码改变,会自动显示代码结果 jQuery调用版本:1.11.3
 立即下载

canvas星球轨迹

0