一.简介

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

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. c# 操作Word总结

    在医疗管理系统中为保存患者的体检和治疗记录,方便以后的医生或其他人查看.当把数据保存到数据库中,需要新建很多的字段,而且操作很繁琐,于是想到网页的信息创建到一个word文本中,在显示的时,可以在线打开 ...

  2. 迭代器类vector::iterator 和 vector::reverse_iterator 的实现、迭代器类型、常用的容器成员

    一.迭代器 迭代器是泛型指针 普通指针可以指向内存中的一个地址 迭代器可以指向容器中的一个位置 STL的每一个容器类模版中,都定义了一组对应的迭代器类.使用迭代器,算法函数可以访问容器中指定位置的元素 ...

  3. numpy 文件存取 npy、npz

    转处:http://blog.csdn.net/pipisorry/article/details/39088003 NumPy提供了多种文件操作函数方便我们存取数组内容. 文件存取的格式:二进制和文 ...

  4. AHK GUI开发示例

    GUI.AHK Gui, Add, Text, gAllSearchA W120, 搜索引擎类: Gui, Add, Checkbox, gMySubroutine Checked HwndMyEdi ...

  5. Java compiler level does not match the version of the installed Java project fac

    Java compiler level does not match the version of the installed Java project fac 问题一: 问:项目图标报错,Probl ...

  6. Unity3D动画面板编辑器状态属性对照表

    不推荐用AnimationUtility.SetEditorCurve问题很多,推荐AnimationCurve.AddKey.通过AnimationUtility.GetAllCurves可以获得编 ...

  7. 安装wxWidgets遭遇的两大关卡

    早就想体验wxWidgets.这学期的C++课,课时还算充裕.关键是弟子们的实践能跟得上,我希望能让他们也浅尝一把GUI开发. MFC能够选.但既然IDE都用CodeBlocks了.还是选wxWidg ...

  8. redis储存中文,客服端读取出现乱码

    [root@cache03 ~]# redis-cli -h 192.168.1.112 -p 6379 192.168.1.112:6379> set chen 陈林 OK 192.168.1 ...

  9. Getting Started with Amazon EC2 (1 year free AWS VPS web hosting)

    from: http://blog.coolaj86.com/articles/getting-started-with-amazon-ec2-1-year-free-aws-vps-web-host ...

  10. linux 编译kernel与svn版本冲突解决方法 [drivers/gpu/mali/mali/common/mali_kernel_core.o] 错误 1

    问题: 系统正常编译linux系统kernel,安装svn后,kernel编译出错. 错误: CHK     include/linux/version.h  CHK     include/gene ...