一.简介

在一些企业广告或者网站需要一些动态文字特效的时候,往往有下面这几种选择:

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的更多相关文章

  1. 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 ...

  2. Cesium中级教程8 - Introduction to Particle Systems 粒子系统入门

    Cesium中文网:http://cesiumcn.org/ | 国内快速访问:http://cesium.coinidea.com/ What is a particle system? 什么是粒子 ...

  3. 粒子系统模块(Particle System Modules40)

    粒子系统模块(Particle System Modules40) 粒子系统模块(忍者飞镖) 粒子系统(忍者飞镖)(Particle System (Shuriken)) 用模块描述粒子一段时间内的行 ...

  4. Particle Playground 3.03 - 粒子特效王者

    <ignore_js_op> <ignore_js_op> <ignore_js_op> <ignore_js_op> <ignore_js_op ...

  5. Cesium中级教程9 - Advanced Particle System Effects 高级粒子系统效应

    Cesium中文网:http://cesiumcn.org/ | 国内快速访问:http://cesium.coinidea.com/ 要了解粒子系统的基础知识,请参见粒子系统入门教程. Weathe ...

  6. Vectoroid

    Use cases Drawing (sketch, illustrations, cartooning, etc). Diagramming (any sort of chart with obje ...

  7. 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 ...

  8. PhoenixFD插件流体模拟——UI布局【Output】详解

    Liquid Output 流体输出  本文主要讲解Output折叠栏中的内容.原文地址:https://docs.chaosgroup.com/display/PHX3MAX/Liquid+Outp ...

  9. Unity3D用户手册

    Unity Manual 用户手册 Welcome to Unity. 欢迎使用Unity. Unity is made to empower users to create the best int ...

随机推荐

  1. js处理url

    需求:用js获得url的电话号码和状态 针对url地址:http://www.deikang.com/index.php?tel=15811296111&status=1&id=100 ...

  2. 解决Sping 框架 Controller@Value获取不到值

    原因:要获取 int.properties 中的数据 但是 一直拿不到值 如下代码 使用这种方式注入 *.properties文件 <!-- 引入配置文件 --> <context: ...

  3. __packed字节对齐

    比如: typedef __packed struct READ_Command{    u_char code;    u_int addr;    u_char len;} READ_Comman ...

  4. servlet响应解析

    response对象可以设置一些响应信息 1)设置状态码 response.setStatus(int) 2)设置响应头信息.定时刷新或者间隔 n 秒后跳转 response.setHeader(&q ...

  5. Redis(十五):哨兵Sentinel

    Redis哨兵 Redis 的 Sentinel 系统用于管理多个 Redis 服务器(instance), 该系统执行以下三个任务: 监控(Monitoring): Sentinel 会不断地检查你 ...

  6. 响应式布局框架 Pure-CSS 5.0 示例中文版-中

    8. 表单 Form 在 form 标签中添加 .pure-form 类,可生成单行表单(inline) 效果图: 代码: <form class="pure-form"&g ...

  7. 优化神器 beamoff

    http://files.cnblogs.com/files/yipu/beamoff.zip csdn上有下载:http://download.csdn.net/download/bytige/83 ...

  8. cocos2d-x的win32编译环境

    1>     检查或配置VS 1.1>头文件 [c/c++]->附加包含目录 1.2>依赖库 [链接器]->[输入]->[附加依赖项] 2>     可能出现 ...

  9. SNP密度分布模式

    1. window=100k,step=2k 统计每个window的snp密度,然后用mixtools的normalmixEM(两个组分的混合模型)统计snp的分布模式. R command: lib ...

  10. log4cplus基本用法

    说起日志系统,不得不提大名鼎鼎的Log4j.特别是使用Java的人们,能够说是无人不知无人不晓无人不用. Log4j以其简单的使用方式(引入一个jar包.一行代码就可以调用).灵活(可通过配置文件任意 ...