Text Particle Systems
一.简介
在一些企业广告或者网站需要一些动态文字特效的时候,往往有下面这几种选择:
1.Flash制作的文字特效
2.制作一个动态的GIF
3.Javascript+dom+css
4.SVG

二.javascript+Canvas文字特效
这篇我为大家介绍第五种,也是最强大的一种,上面四种都有局限性。
我使用的是javascript+Canvas,当然我们依然用Jscex,为什么Canvas制作文字特效最强大??
因为Canvas支持像素级别操作,它不仅可以宏观上制作一些文字特效,也可以深入实现文字粒子系统特效----Text Particle Systems。
当然Canvas的像素级别操作还广泛用于图片处理等更多领域,在HTML5实验室http://www.cnblogs.com/iamzhanglei/archive/2011/11/06/2237870.html里也有了好多案例··
三.特效实现
我们现在黑色背景下写一个“心”字:
|
1
2
3
4
5
6
7
|
var tex = "心";cxt.fillStyle = "rgba(0,0,0,1)";cxt.fillRect(0, 0, 430, 400);cxt.fillStyle = "rgba(255,255,255,1)"cxt.font = "bolder 400px 宋体";cxt.textBaseline = 'top';cxt.fillText(tex, 20, 20); |
然后我们遍历所有的像素点,并把画上了字的像素点放进一个数组里面:
|
1
2
3
4
5
6
7
8
|
for (y = 1; y < 400; y += 10) { for (x = 1; x < 400; x += 10) { imageData = cxt.getImageData(20 + x, 20 + y, 1, 1); if (imageData.data[0] > 170) { ps.push({ px: 20 + x, py: 20 + y }); } }} |
然后我们,在每个点上画一个小球,并随机生成X和Y方向的速度:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
for (i in ps) { var ball = { x: ps[i].px, y: ps[i].py, r: 2, vx: getRandomNumber(-10, 10), vy: getRandomNumber(0, 100) }; balls.push(ball);}cxt.fillStyle = "#fff";for (i in balls) { cxt.beginPath(); cxt.arc(balls[i].x, balls[i].y, balls[i].r, 0, Math.PI * 2, true); cxt.closePath(); cxt.fill();} |
我们再模拟一个重力场和非弹性碰撞,加上Jscex 制作动画效果:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
var dropAsync = eval(Jscex.compile("async", function () { while (true) { if (breakTag) { break; } cxt.fillStyle = "rgba(0, 0, 0, .3)"; cxt.fillRect(0, 0, canvas.width, canvas.height); cxt.fillStyle = "#fff"; for (i in balls) { cxt.beginPath(); cxt.arc(balls[i].x, balls[i].y, balls[i].r, 0, Math.PI * 2, true); cxt.closePath(); cxt.fill(); balls[i].y += balls[i].vy * cyc / 1000; balls[i].x += balls[i].vx * cyc / 1000; if (balls[i].r + balls[i].y >= canvas.height) { if (balls[i].vy > 0) { balls[i].vy *= -0.7; } } else { balls[i].vy += a; } } $await(Jscex.Async.sleep(cyc)); }})) |
Text Particle Systems的更多相关文章
- Custom Sublime Text Build Systems For Popular Tools And Languages
Sublime Text is currently the text editor of choice for a number of developers in the open-source co ...
- Cesium中级教程8 - Introduction to Particle Systems 粒子系统入门
Cesium中文网:http://cesiumcn.org/ | 国内快速访问:http://cesium.coinidea.com/ What is a particle system? 什么是粒子 ...
- 粒子系统模块(Particle System Modules40)
粒子系统模块(Particle System Modules40) 粒子系统模块(忍者飞镖) 粒子系统(忍者飞镖)(Particle System (Shuriken)) 用模块描述粒子一段时间内的行 ...
- Particle Playground 3.03 - 粒子特效王者
<ignore_js_op> <ignore_js_op> <ignore_js_op> <ignore_js_op> <ignore_js_op ...
- Cesium中级教程9 - Advanced Particle System Effects 高级粒子系统效应
Cesium中文网:http://cesiumcn.org/ | 国内快速访问:http://cesium.coinidea.com/ 要了解粒子系统的基础知识,请参见粒子系统入门教程. Weathe ...
- Vectoroid
Use cases Drawing (sketch, illustrations, cartooning, etc). Diagramming (any sort of chart with obje ...
- Qt3D 5.9 and future
2017-05 http://blog.qt.io/blog/2017/05/24/qt3d/ Qt3D future 5.9 Use Qt Quick or QPainter to render i ...
- PhoenixFD插件流体模拟——UI布局【Output】详解
Liquid Output 流体输出 本文主要讲解Output折叠栏中的内容.原文地址:https://docs.chaosgroup.com/display/PHX3MAX/Liquid+Outp ...
- Unity3D用户手册
Unity Manual 用户手册 Welcome to Unity. 欢迎使用Unity. Unity is made to empower users to create the best int ...
随机推荐
- OpenCV iOS开发(一)——安装(转)
OpenCV是一个开源跨平台的的计算机视觉和机器学习库,可以用来做图片视频的处理.图形识别.机器学习等应用.本文将介绍OpenCV iOS开发中的Hello World起步. 安装 OpenCV安装的 ...
- eclipse使用git提交本地项目,提交至远程github上
准备工作: 目的:eclipse使用git提交本地项目,提交至远程github上 eclipse版本:eclipse4.5 64位 jdk版本:jdk-1.7 64位 项目类型:maven web项 ...
- mysql拼接字符串和过滤字符的方法
数据 id value 1 aa<p>QL实木颗粒</p> 2 bb<p>QL实木颗粒</p> ...
- 扩展GeoServer数据源
今天我们来讲讲怎么扩展GeoServer(简称GS)的数据源.大家都知道,GS支持多种数据源,而且都提供了友好的界面供操作.下面我们就来简单介绍一下,如何把自定义的数据源增加到GS中,让我们可以在统一 ...
- github get 请求指定页面的代码
https://raw.githubusercontent.com/dragon8github/wx-h5/master/push.sh
- 关闭危害的端口DOS命令(转载)
rem ipseccmd -w REG -p "HFUT_SECU" -r "Block UDP/137" -f *+0:137:UDP -n BLOCK -x ...
- CentOS 6 下升级安装Mysql 5.5 完整步骤
使用系统CentOS 6.2本来已经系统自带安装了mysql 5.1,但是奈何5.1不支持utf8mb4字符集(详见:http://blog.csdn.net/shootyou/article/det ...
- 邁向 RHCE 之路 (Day26) - Apache 網頁伺服器
本篇將在 SELinux 安全機制及 IPTables 防火牆開啟的環境下實作,分別實作簡單網頁服務及虛擬主機 Virtual Host 設定,最後則是實作網頁中需要保護網頁時可以透過 .htacce ...
- angular.js 动态插入删除dom节点
angular.js 是新一代web开发框架,它轻松在web前端实现了MVC模式,相比 jquery 模式,这种新玩意竟然不需要开发者直接去操作dom . 作为前端开发而不去操作dom ,这简直是一个 ...
- Android Study 之 初识ButterKnife(8.5.1)及简单运用
LZ-Says:突然间不知道说什么好,祝大家编码无bug吧~ 前言 话说,Android开发的兄弟们都知道,每次初始化控件,设置对应的事件.写的那点过程多并且恶心.我们先一块回想下不堪的以前~ 那些年 ...