幽灵资源网 Design By www.bzswh.com
效果如下:
代码如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <style> *{ margin:0px; padding:0px; } body{ background:#000; } canvas{ position:absolute; width:100%; height:100%; } </style> <body> <canvas id="canvas">您的浏览器不支持,请升级最新的版本!</canvas> <script>window.requestAnimFrame = ( function() { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function( callback ) { window.setTimeout( callback, 1000 / 60 ); }; })(); var can = document.getElementById("canvas"); var cxt = can.getContext("2d"); can.width = window.innerWidth; can.height = window.innerHeight; cxt.lineWidth = 0.3; //初始链接线条显示位置 var mousePosition = { x : 30*can.width/100, y : 30*can.height/100 } //圆形粒子对象参数 var dots = { n : 500,//圆形粒子个数 distance : 50,//圆形粒子之间的距离 d_radius : 80,//粒子距离鼠标点的距离 array : []//保存n个圆形粒子对象 } //创建随机颜色值 function colorValue(min){ return Math.floor(Math.random()*255 + min); } function createColorStyle(r,g,b){ return "rgba("+r+","+g+","+b+", 1)"; } //混合两个圆形粒子的颜色 function mixConnect(c1,r1,c2,r2){//圆的颜色 半径 return (c1*r1+c2*r2)/(r1+r2); }; //生成线条的颜色 function lineColor(dot1,dot2){//获取具体的圆的颜色再计算 var color1 = dot1.color, color2 = dot2.color; var r = mixConnect(color1.r,dot1.radius,color2.r,dot2.radius); var g = mixConnect(color1.g,dot1.radius,color2.g,dot2.radius); var b = mixConnect(color1.b,dot1.radius,color2.b,dot2.radius); return createColorStyle(Math.floor(r),Math.floor(g),Math.floor(b)); } //生成圆形粒子的颜色对象 function Color(min){ min = min || 0; this.r = colorValue(min); this.g = colorValue(min); this.b = colorValue(min); this.style = createColorStyle(this.r,this.g,this.b); } //创建圆形粒子对象 function Dot(){ //圆形粒子随机圆心坐标点 this.x = Math.random()*can.width; this.y = Math.random()*can.height; //x y 方向运动的速度值 this.vx = -0.5 + Math.random(); this.vy = -0.5 + Math.random(); this.radius = Math.random()*5; //this.color = "#ff3333"; this.color = new Color(); } //绘制出圆形粒子 Dot.prototype.draw = function(){ cxt.beginPath(); cxt.fillStyle = this.color.style; cxt.arc(this.x,this.y,this.radius,0,Math.PI*2,false); cxt.fill(); } //添加圆形粒子 function createCircle(){ for (var i=0;i<dots.n ;i++ ) { dots.array.push(new Dot()); } } //绘制出圆形粒子 function drawDots(){ for (var i=0;i<dots.n ;i++ ) { var dot = dots.array[i]; dot.draw(); } } //drawDots(); //移动 function moveDots(){ for (var i=0;i<dots.n ;i++ ){ var dot = dots.array[i]; //当圆形粒子对象碰壁的时候就反弹回来 if (dot.y < 0 || dot.y > can.height) { dot.vx = dot.vx; dot.vy = -dot.vy; }else if (dot.x < 0 || dot.x > can.width) { dot.vx = -dot.vx; dot.vy = dot.vy; } //给圆形粒子圆心坐标加上速度值移动圆形粒子 dot.x += dot.vx; dot.y += dot.vy; } } //链接粒子对象 function connectDots(){ for (var i=0;i<dots.n ; i++) { for ( var j=0;j<dots.n ; j++) { iDot = dots.array[i]; jDot = dots.array[j]; if ((iDot.x - jDot.x) < dots.distance && (iDot.y - jDot.y) < dots.distance && (iDot.x - jDot.x) > -dots.distance && (iDot.y - jDot.y) > -dots.distance) { if ((iDot.x - mousePosition.x) < dots.d_radius && (iDot.y - mousePosition.y) < dots.d_radius && (iDot.x - mousePosition.x) > -dots.d_radius && (iDot.y - mousePosition.y) > -dots.d_radius) { cxt.beginPath(); //cxt.strokeStyle = "yellow"; cxt.strokeStyle = lineColor(iDot,jDot); cxt.moveTo(iDot.x,iDot.y); cxt.lineTo(jDot.x,jDot.y); cxt.closePath(); cxt.stroke(); } } } } } createCircle(); //让圆形粒子不断的移动 function animateDots(){ cxt.clearRect(0,0,can.width,can.height); moveDots(); connectDots() drawDots(); requestAnimFrame(animateDots); } animateDots(); can.onmousemove = function(ev){ var ev = ev || window.event; mousePosition.x = ev.pageX; mousePosition.y = ev.pageY; } can.onmouseout = function(){ mousePosition.x = can.width/2; mousePosition.y = can.height/2; } </script> </body> </html>
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!
幽灵资源网 Design By www.bzswh.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
幽灵资源网 Design By www.bzswh.com
暂无评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。