星球 变量名 公转周期 光色 暗色
水星 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;
//创建一个渐变色空对象
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;
}
} function Sun(){//太阳1
DrawStart.call(this,0,0,20,0,"#f00","#f90");
}
function Mercury(){//水星2
DrawStart.call(this,0,-50,10,87.70,"#A69697","#5c3e40");
}
function Venus(){//金星3
DrawStart.call(this,0,-100,10,224.71,"#c4bbac","#1f1315");
}
function Earth(){//地球4
DrawStart.call(this,0,-150,10,365.224,"#78b1e8","#050c12");
}
function Mars(){//火星5
DrawStart.call(this,0,-200,10,686.98,"#cec9b6","#76422d");
}
function Jupiter(){//木星6
DrawStart.call(this,0,-250,10,4332.589,"#c0a48e","#322");
}
function Saturn(){//土星7
DrawStart.call(this,0,-300,10,10759.5,"#f7f9e3","#5c4533");
}
function Uranus(){//天王星8
DrawStart.call(this,0,-350,10,30799.95,"#a7e1e5","#19243a");
}
function Neptune(){//天王星9
DrawStart.call(this,0,-400,10,60152.95,"#0661b2","#1E3b73");
} var s=new Sun();// var m=new Mercury();//
var v=new Venus();//
var e=new Earth();//
var ma=new Mars();//
var j=new Jupiter();//
var sa=new Saturn();//
var ur=new Uranus();//
var ne=new Neptune();// 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);

最新文章

  1. Codeforces CF#628 Education 8 C. Bear and String Distance
  2. 【转】前端工程筹建NodeJs+gulp+bower
  3. UVa(11292),贪心水题
  4. Chapter Configuration
  5. FileUpload控件「批次上传 / 多档案同时上传」的范例--以「流水号」产生「变量名称」
  6. Spring Boot 入门
  7. 使用typedef语句定义数组类型
  8. Android 照相功能
  9. 一个JQuery发送ajax请求
  10. a标签链接到当前页内指定位置
  11. java面向对象知识整理(一)
  12. springboot+spring security +oauth2.0 demo搭建(password模式)(认证授权端与资源服务端分离的形式)
  13. 蓝桥杯——X星球居民问题
  14. C# 语法五 单例类、单例模式
  15. SSM项目POST中文乱码解决方案
  16. 基于matplotlib的数据可视化 - 笔记
  17. IE8 select 动态下拉遇到的问题
  18. (文章转载)MCI编程
  19. java翻译到mono C#实现系列(1) 重写返回键按下的事件
  20. Git 的origin和master分析(转)

热门文章

  1. C#项目中怎样创建和使用类和类库
  2. jsp笔记总结
  3. Azure .Net应用架构原型
  4. 6LowPan 开发之开山篇
  5. JSON简介[转]
  6. MYSQL 调优和使用必读
  7. 监听器(Listener)学习(二)
  8. Codeforces 280C Game on tree【概率DP】
  9. Java8中计算日期时间差
  10. Spring-Java事物回滚失效处理