1.canvas 文字粒子特效插件

HTML

<canvas id="dot" style="background:linear-gradient(to bottom, #fff, #ddd);">
        <p>your browser not support canvas</p>
</canvas>

css

 

*{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            overflow: hidden;
  }

 

js

 

(function(window,factory){if(typeof define==="function"&&define.amd){define(factory)}else{if(typeof module==="object"&&module.exports){module.exports=factory()}else{window.Dot=factory()}}}(typeof window!=="undefined"?window:this,function(){var Dot=function(selector,userOptions){var options={cW:1367,cH:500,numDot:100,radDot:15,isRangeRad:true,dotColor:"#FFFFFF",isLine:true,lineDist:75,lineColor:"#FFFFFF",bounce:1,opacity:0.5,isTouch:false,vxRange:2,vyRange:2,isWallCollisionTest:true,isBallCollisionTest:true};var oDots=[],canvas=null,ctx=null,oDotA=null,oDotB=null,W=null,H=null;var mergeOptions=function(userOptions,options){Object.keys(userOptions).forEach(function(key){options[key]=userOptions[key]})};var colorToRGB=function(color,alpha){if(typeof color==="string"&&color[0]==="#"){color=window.parseInt(color.slice(1),16)}alpha=(alpha===undefined)?1:alpha;var r=color>>16&255,g=color>>8&255,b=color>>4&255,a=(alpha<0)?0:((alpha>1)?1:alpha);if(a===1){return"rgb("+r+","+g+","+b+")"}else{return"rgba("+r+","+g+","+b+","+a+")"}};var captureMouse=function(element){var mouse={x:0,y:0};element.addEventListener("mousemove",function(event){var x,y;if(event.pageX||event.pageY){x=event.pageX;y=event.pageY}else{x=event.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;y=event.clientY+document.body.scrollTop+document.documentElement.scrollTop}x-=element.offsetLeft;y-=element.offsetTop;mouse.x=x;mouse.y=y},false);return mouse};var ran=function(min,max){var val=max-min;return parseInt((Math.random()*val+min).toFixed(2))};var Practicle=function(color,radius,alpha){this.x=0;this.y=0;this.vx=0;this.vy=0;this.radius=radius;this.rotation=0;this.mass=1;this.scaleX=1;this.scaleY=1;this.name="";this.color=colorToRGB(color,alpha)};Practicle.prototype.draw=function(ctx){ctx.save();ctx.translate(this.x,this.y);ctx.rotate(this.rotation);ctx.scale(this.scaleX,this.scaleY);ctx.fillStyle=this.color;ctx.strokeStyle=this.color;ctx.beginPath();ctx.arc(0,0,this.radius,0,Math.PI*2,false);ctx.closePath();ctx.fill();ctx.restore()};var makeDots=function(){for(var i=0;i<options.numDot;i++){if(options.isRangeRad){options.radDot=Math.floor(ran(2,options.radDot))}var oDot=new Practicle(options.dotColor,options.radDot,options.opacity);oDot.x=ran(0,W);oDot.y=ran(0,H);oDot.vx=Math.random()*(options.vxRange)-options.vxRange/2;oDot.vy=Math.random()*(options.vyRange)-options.vyRange/2;oDots.push(oDot)}};var draw=function(oDot){oDot.draw(ctx)};var move=function(oDot){oDot.x+=oDot.vx;oDot.y+=oDot.vy;checkWall(oDot)};var checkWall=function(oDot){if(options.isWallCollisionTest){if(oDot.x+oDot.radius>W){oDot.x=W-oDot.radius;oDot.vx*=-(options.bounce)}else{if(oDot.x-oDot.radius<0){oDot.x=oDot.radius;oDot.vx*=-(options.bounce)}}if(oDot.y+oDot.radius>H){oDot.y=H-oDot.radius;oDot.vy*=-(options.bounce)}else{if(oDot.y-oDot.radius<0){oDot.y=oDot.radius;oDot.vy*=-(options.bounce)}}}else{if(oDot.x-oDot.radius>W){oDot.x=0}else{if(oDot.x+oDot.radius<0){oDot.x=W}}if(oDot.y-oDot.radius>H){oDot.y=0}else{if(oDot.y+oDot.radius<0){oDot.y=H}}}};var rotate=function(x,y,sin,cos,reverse){return{x:(reverse)?(x*cos+y*sin):(x*cos-y*sin),y:(reverse)?(y*cos-x*sin):(y*cos+x*sin)}};var checkCollision=function(oDot0,oDot1){var dx=oDot1.x-oDot0.x,dy=oDot1.y-oDot0.y,dist=Math.sqrt(dx*dx+dy*dy);if(dist<oDot0.radius+oDot1.radius){var angle=Math.atan2(dy,dx),sin=Math.sin(angle),cos=Math.cos(angle);var pos0={x:0,y:0};var pos1=rotate(dx,dy,sin,cos,true);var vel0=rotate(oDot0.vx,oDot0.vy,sin,cos,true);var vel1=rotate(oDot1.vx,oDot1.vy,sin,cos,true);var vxTotal=vel0.x-vel1.x;vel0.x=((oDot0.mass-oDot1.mass)*vel0.x+2*oDot1.mass*vel1.x)/(oDot0.mass+oDot1.mass);vel1.x=vxTotal+vel0.x;var absV=Math.abs(vel0.x)+Math.abs(vel1.x),overlap=(oDot0.radius+oDot1.radius)-Math.abs(pos0.x-pos1.x);pos0.x+=vel0.x/absV*overlap;pos1.x+=vel1.x/absV*overlap;var pos0F=rotate(pos0.x,pos0.y,sin,cos,false);var pos1F=rotate(pos1.x,pos1.y,sin,cos,false);oDot1.x=oDot0.x+pos1F.x;oDot1.y=oDot0.y+pos1F.y;oDot0.x=oDot0.x+pos0F.x;oDot0.y=oDot0.y+pos0F.y;var vel0F=rotate(vel0.x,vel0.y,sin,cos,false);var vel1F=rotate(vel1.x,vel1.y,sin,cos,false);oDot0.vx=vel0F.x;oDot0.vy=vel0F.y;oDot1.vx=vel1F.x;oDot1.vy=vel1F.y}};var drawLine=function(oDot0,oDot1){var dx=oDot1.x-oDot0.x,dy=oDot1.y-oDot0.y,dist=Math.sqrt(dx*dx+dy*dy);if(dist<options.lineDist){ctx.save();ctx.strokeStyle=colorToRGB(options.lineColor,(options.opacity-0.4)<=0?0.1:options.opacity-0.4);ctx.beginPath();ctx.moveTo(oDot0.x,oDot0.y);ctx.lineTo(oDot1.x,oDot1.y);ctx.closePath();ctx.stroke();ctx.restore()}};var execute=function(){oDots.forEach(move);for(var i=0;i<options.numDot-1;i++){oDotA=oDots[i];for(var j=i+1;j<options.numDot;j++){oDotB=oDots[j];options.isBallCollisionTest&&checkCollision(oDotA,oDotB);options.isLine&&drawLine(oDotA,oDotB)}}oDots.forEach(draw)};if(!window.requestAnimationFrame){window.requestAnimationFrame=(window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(callback){return window.setTimeout(callback,1000/60)
    })}var initDot=function(selector,userOptions){mergeOptions(userOptions,options);canvas=document.getElementById(selector),ctx=canvas.getContext("2d");W=options.cW;H=options.cH;canvas.width=W;canvas.height=H;makeDots();(function drawFrame(){window.requestAnimationFrame(drawFrame);ctx.clearRect(0,0,W,H);execute()}())};initDot(selector,userOptions)};return Dot}));

    // instance
    Dot("dot", {
        cW: 2000,
        cH: 400,
        lineDist:150,
        dotColor:'#444444',
        lineColor:'#aaaaaa',
        numDot:65
    });

 

说明:

属性类型默认值描述
cWNumber1367canvas宽度
cHNumber500canvas高度
numDotNumber100粒子数目
radDotNumber3粒子半径
isRangeRadBooleantrue是否随机粒子半径(给定的radDot范围内)
dotColorString”#FFFFFF“粒子填充颜色
lineDistNumber75连线距离
lineColorString"#FFFFFF"连线颜色
bounceNumber1反弹系数
opacityNumber0.5透明度
isTouchBooleanfalse是否与鼠标发生交互
vxRangeNumber2粒子x方向速度
vyRangeNumber2粒子y方向速度
isWallCollisionTestBooleantrue是否与边界碰撞检测
isBallCollisionTestBooleantrue球体间是否发生碰撞检测

 

转载于:https://www.cnblogs.com/cfsgogo/p/6650942.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园整体解决方案是响应国家教育信息化政策,结合教育改革和技术创新的产物。该方案以物联网、大数据、人工智能和移动互联技术为基础,旨在打造一个安全、高效、互动且环保的教育环境。方案强调从数字化校园向智慧校园的转变,通过自动数据采集、智能分析和按需服务,实现校园业务的智能化管理。 方案的总体设计原则包括应用至上、分层设计和互联互通,确保系统能够满足不同用户角色的需求,并实现数据和资源的整合与共享。框架设计涵盖了校园安全、管理、教学、环境等多个方面,构建了一个全面的校园应用生态系统。这包括智慧安全系统、校园身份识别、智能排课及选课系统、智慧学习系统、精品录播教室方案等,以支持个性化学习和教学评估。 建设内容突出了智慧安全和智慧管理的重要性。智慧安全管理通过分布式录播系统和紧急预案一键启动功能,增强校园安全预警和事件响应能力。智慧管理系统则利用物联网技术,实现人员和设备的智能管理,提高校园运营效率。 智慧教学部分,方案提供了智慧学习系统和精品录播教室方案,支持专业级学习硬件和智能化网络管理,促进个性化学习和教学资源的高效利用。同时,教学质量评估中心和资源应用平台的建设,旨在提升教学评估的科学性和教育资源的共享性。 智慧环境建设则侧重于基于物联网的设备管理,通过智慧教室管理系统实现教室环境的智能控制和能效管理,打造绿色、节能的校园环境。电子班牌和校园信息发布系统的建设,将作为智慧校园的核心和入口,提供教务、一卡通、图书馆等系统的集成信息。 总体而言,智慧校园整体解决方案通过集成先进技术,不仅提升了校园的信息化水平,而且优化了教学和管理流程,为学生、教师和家长提供了更加便捷、个性化的教育体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值