英文字母html,利用HTML5实现英文字母ABCD动画特效
特效描述:利用HTML5实现 英文字母 ABCD 动画特效。利用HTML5实现英文字母ABCD动画特效
代码结构
1. HTML代码
function foreach(array, callback) {
for(let ind=0; ind
callback(array[ind],ind);
}
}
function rand(min,max) {
return Math.floor(Math.random()*(max-min+1)+min);
}
class Dot {
constructor(canvas,position) {
this.canvas = canvas;
this.context = this.canvas.getContext('2d');
this.color = '#fff';
this.position = {x:position.x,y:position.y};
this.originalPosition = {x:position.x,y:position.y};
this.reachPosition = {x:position.x, y:position.y};
this.randomValue = rand(5,10);
this.glitch = false;
this.size = 1;
this.mouse = {x:0,y:0};
this.counter = 0;
}
update() {
this.glitch = rand(0,200) < this.randomValue;
let easing = this.randomValue / 50;
this.position.x += ( this.reachPosition.x - this.position.x ) * easing;
this.position.y += ( this.reachPosition.y - this.position.y ) * easing;
let sin = Math.sin(this.counter * easing / 10);
this.position.x += sin;
this.size = sin > 1 ? sin : 1;
this.counter++;
this.draw();
}
draw() {
this.context.beginPath();
this.context.fillStyle = this.color;
this.context.arc(this.position.x,this.position.y,this.size,0,Math.PI*2);
this.context.fill();
this.context.closePath();
}
}
class Letter {
constructor(canvas, text) {
this.canvas = canvas;
this.context = this.canvas.getContext('2d');
this.size = '200px';
this.color = 'rgb(0,255,0)';
this.text = text;
this.mouse = {x:0,y:0};
this.position = [];
}
update() { }
getPixel() {
this.position = [];
this.context.clearRect(0,0,this.canvas.width,this.canvas.height);
this.draw();
let datas = this.context.getImageData(0, 0, this.canvas.width, this.canvas.height);
let x = 0;
let y = 0;
for (let i=0;i
if(datas.data[i] == 0 && datas.data[i+1] == 255 && datas.data[i+2] == 0) {
this.position.push({x:x,y:y});
}
x++;
if(x >= this.canvas.width) {
x = 0;
y++;
}
this.context.putImageData(datas,0,i);
}
return this.position;
}
draw() {
this.context.beginPath();
this.context.fillStyle = this.color;
this.context.font = this.size + ' Gerstner, Arial, sans-serif';
this.context.fillText(this.text, (this.canvas.width / 2), (this.canvas.height / 2));
this.context.textAlign = "center";
this.context.textBaseline = "middle";
this.context.fill();
this.context.closePath();
}
}
class Scene {
constructor(opt) {
this.canvas = document.querySelector(opt.canvas);
this.context = this.canvas.getContext('2d');
this.number = 25;
this.counter = 0;
this.mouse = {
position:{x:0,y:0},
plan: {x:0,y:0}
};
this.render = this.render.bind(this);
this._mouseMove = this._mouseMove.bind(this);
this._resize = this._resize.bind(this);
window.addEventListener('mousemove',this._mouseMove);
window.addEventListener('resize',this._resize);
this.init(opt);
this.currentLetter = this.letters[0];
this.interval = setInterval( () => {
this.counter++;
if(this.counter >= this.letters.length) this.counter = 0;
this.currentLetter = this.letters[this.counter];
},1000);
this.render();
}
init(opt) {
this.canvas.width = opt.width;
this.canvas.height = opt.height;
this.dots = [];
this.letters = [];
let size = { width:this.canvas.width/this.number, height:this.canvas.height/this.number };
for(let x=1; x
for(let y=1; y
this.dots.push(new Dot(this.canvas,{ x: size.width * x, y: size.height * y }));
}
}
let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for(let letter in alphabet) {
this.letters.push(new Letter(this.canvas,alphabet[letter]));
}
}
render() {
this.context.clearRect(0,0,this.canvas.width, this.canvas.height);
if( this.currentLetter.position.length == 0 ) {
this.currentLetter.getPixel();
}
foreach( this.dots, (dot, ind) => {
dot.mouse = this.mouse;
dot.update();
let divideBy = Math.floor(this.currentLetter.position.length / (this.dots.length - 1));
let position = this.currentLetter.position[ind * divideBy];
if(!position) return false;
dot.reachPosition = { x: position.x, y: position.y };
});
requestAnimationFrame(this.render);
}
_mouseMove(e) {
let width = (this.canvas.width / 2);
let height = (this.canvas.height / 2);
this.mouse.position = {
x: e.clientX,
y: e.clientY
}
this.mouse.plan.x = -((width - e.clientX) / width);
this.mouse.plan.y = (height - e.clientY) / height;
}
_resize(e) {
let opt = {width:window.innerWidth,height:window.innerHeight};
this.init(opt);
}
}
new Scene({
canvas:'#stage',
width:window.innerWidth,
height:window.innerHeight
})
英文字母html,利用HTML5实现英文字母ABCD动画特效相关推荐
- html5绘制草,利用html5实现canvas海底水草动画特效
特效描述:利用html5实现 canvas海底水草动画特效.利用html5实现canvas海底水草动画特效 代码结构 1. HTML代码 var canvas, ctx, width, height, ...
- html 闪电的动态效果图,利用HTML5实现Canvas空中闪电动画特效
特效描述:利用HTML5实现 Canvas 空中闪电 动画特效.利用HTML5实现Canvas空中闪电动画特效 代码结构 1. 引入JS 2. HTML代码 /*=================== ...
- html5 实现波浪效果图,利用HTML5实现Canvas流动的波浪特效
特效描述:利用HTML5实现 Canvas 流动的 波浪特效.利用HTML5实现Canvas流动的波浪特效 代码结构 1. 引入JS 2. HTML代码 'use strict'; var gui = ...
- html 5抽奖特效,利用HTML5实现Canvas大转盘抽奖特效
特效描述:利用HTML5实现 Canvas 大转盘 抽奖特效.利用HTML5实现Canvas大转盘抽奖特效 代码结构 1. 引入JS 2. HTML代码 当前浏览器版本过低,请使用其他浏览器尝试 va ...
- html5手电筒样式,利用HTML5实现SVG模拟手电筒照明特效
特效描述:利用HTML5实现 SVG 模拟手电筒 照明特效.利用HTML5%20实现SVG模拟手电筒照明特效 代码结构 1. HTML代码 xmlns="http://www.w3.org/ ...
- html5如何写出圆背景,利用HTML5实现Canvas虚幻圆点背景特效
特效描述:利用HTML5实现 Canvas 虚幻圆点 背景特效.利用HTML5实现Canvas虚幻圆点背景特效 代码结构 1. 引入JS 2. HTML代码 (function($){ var can ...
- html5 照片汇聚logo,利用HTML5实现Canvas粒子汇聚文字特效
特效描述:利用HTML5实现 Canvas 粒子汇聚 文字特效.利用HTML5实现Canvas粒子汇聚文字特效 代码结构 1. HTML代码 jQuery Chinaz // WRITTEN BY T ...
- 面条html5,利用HTML5 Canvas实现一碗面条特效
特效描述:利用HTML5 Canvas实现一碗面条特效.利用HTML5 Canvas实现一碗面条特效 代码结构 1. HTML代码 // Initiate Canvas let can = docum ...
- HTML画布太阳代码,利用HTML5实现Canvas水面下太阳特效
特效描述:利用HTML5实现 Canvas 水面下 太阳特效.利用HTML5实现Canvas水面下太阳特效 代码结构 1. 引入JS 2. HTML代码 void main() { gl_Positi ...
最新文章
- smack连接openfire
- HTML如何实现单元格自动编号,如何在Excel中自动为列编号?
- 安卓手机能用吗_手机才用两年卡的不行,是手机问题吗,想问手机最长能用几年?...
- Git生成ssh密钥
- POJ 3414 Pots(BFS + 打印路径)
- 商业计划书-智能导盲仗
- android 用gridview,Android GridView的使用
- mysql 超级管理员权限_取得超级管理员权限
- 请上传android安装包,如何上传APP到各大安卓应用市场
- C++的O2、O3到底是个什么鬼
- Android 面试中高级上
- tipask 修改,临时的(暂没进行很好的全面考虑,为上线用)
- APP、网站等注册、登录、改密等发送验证码短信的接入流程---创蓝253云通讯
- 自动给ssh输入密码(python使用pty模块,或者script命令)
- 高程计算机编程序,卡西欧CASIO系列编程计算器在公路测量中的应用.doc
- CodeForces Ania and Minimizing 1230B
- 高中计算机多媒体技术应用教案,高中信息技术 多媒体技术应用教案 教科版选修.pdf...
- 《PHP和MySQL WEB开发》第六章笔记
- 计算机vb知识点,2020年全国计算机二级VB复习知识点:常用内部函数
- php网页中出现问号,HTML_地址栏中的问号有什么作用,之前我们曾经解释?过链接地址 - phpStudy...
热门文章
- 编码员,程序员,黑客,开发人员和计算机科学家走进维恩图
- 七倍压电路图_倍压整流电路图大全(九款倍压整流电路设计原理图详解) - 全文...
- Elixir GenServer
- Selenium中级 | 在Selenium中模拟键盘操作
- yum install时提示This system is not registered with an entitlement server
- 4K显示屏Win10下软件字体太小解决方法
- 程序员财富自由之路 自媒体篇 | 3000字干货分享
- Linux终端一直输出login,Linux tty pty console区别
- Conflux 进阶课 | 初始阶段通证发行数量
- springboot/vue前后端分离后台管理系统增删改查