html5使用canvas绘制太阳系效果
canvas
html5
这篇文章主要介绍了html5使用canvas绘制太阳系效果,需要的朋友可以参考下:
<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; } }</p> <p> 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();//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视频教程!
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章
刺客信条阴影:贝壳谜语解决方案
3 周前
By DDD
Windows 11 KB5054979中的新功能以及如何解决更新问题
2 周前
By DDD
在哪里可以找到原子中的起重机控制钥匙卡
3 周前
By DDD
刺客信条阴影 - 如何找到铁匠,解锁武器和装甲定制
1 个月前
By DDD
<🎜>:死铁路 - 如何完成所有挑战
3 周前
By DDD

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)
