h5酷炫粒子java代码_html5粒子效果文字特效
特效描述:html5 粒子效果 文字特效。html5粒子效果文字特效
代码结构
1. HTML代码
BLUR = false;
PULSATION = true;
PULSATION_PERIOD = 600;
PARTICLE_RADIUS = 4;
/* disable blur before using blink */
BLINK = false;
GLOBAL_PULSATION = false;
QUALITY = 2; /* 0 - 5 */
/* set false if you prefer rectangles */
ARC = true;
/* trembling + blur = fun */
TREMBLING = 0; /* 0 - infinity */
FANCY_FONT = "Arial";
BACKGROUND = "#000";
BLENDING = true;
/* if empty the text will be a random number */
var TEXT;
num = 0;
TEXTArray = ["周磊", "深爱", "闫蒙", "直到", "永远"];
QUALITY_TO_FONT_SIZE = [10, 12, 40, 50, 100, 350];
QUALITY_TO_SCALE = [20, 6, 4, 2, 0.9, 0.5];
QUALITY_TO_TEXT_POS = [10, 20, 60, 100, 370, 280];
window.onload = function () {
document.body.style.backgroundColor = BACKGROUND;
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var W = canvas.width;
var H = canvas.height;
var tcanvas = document.createElement("canvas");
var tctx = tcanvas.getContext("2d");
tcanvas.width = W;
tcanvas.height = H;
total_area = W * H;
total_particles = 928;
single_particle_area = total_area / total_particles;
area_length = Math.sqrt(single_particle_area);
var particles = [];
for (var i = 1; i <= total_particles; i++) {
particles.push(new particle(i));
}
function particle(i) {
this.r = Math.round(Math.random() * 255 | 0);
this.g = Math.round(Math.random() * 255 | 0);
this.b = Math.round(Math.random() * 255 | 0);
this.alpha = 1;
this.x = (i * area_length) % W;
this.y = (i * area_length) / W * area_length;
/* randomize delta to make particles sparkling */
this.deltaOffset = Math.random() * PULSATION_PERIOD | 0;
this.radius = 0.1 + Math.random() * 2;
}
var positions = [];
function new_positions() {
TEXT = TEXTArray[num];
if (num < TEXTArray.length - 1) {
num++;
} else {
num = 0;
}
//alert(TEXT);
tctx.fillStyle = "white";
tctx.fillRect(0, 0, W, H)
//tctx.fill();
tctx.font = "bold " + QUALITY_TO_FONT_SIZE[QUALITY] + "px " + FANCY_FONT;
//tctx.textAlign='center';//文本水平对齐方式
//tctx.textBaseline='middle';
//tctx.strokeStyle = "black";
tctx.fillStyle = "#f00";
//tctx.strokeText(TEXT,30, 50);
tctx.fillText(TEXT, 20, 60);
image_data = tctx.getImageData(0, 0, W, H);
pixels = image_data.data;
positions = [];
for (var i = 0; i < pixels.length; i = i + 2) {
if (pixels[i] != 255) {
position = {
x: (i / 2 % W | 0) * QUALITY_TO_SCALE[QUALITY] | 0,
y: (i / 2 / W | 0) * QUALITY_TO_SCALE[QUALITY] | 0
}
positions.push(position);
}
}
get_destinations();
}
function draw() {
var now = Date.now();
ctx.globalCompositeOperation = "source-over";
if (BLUR) ctx.globalAlpha = 0.1;
else if (!BLUR && !BLINK) ctx.globalAlpha = 1.0;
ctx.fillStyle = BACKGROUND;
ctx.fillRect(0, 0, W, H)
if (BLENDING) ctx.globalCompositeOperation = "lighter";
for (var i = 0; i < particles.length; i++) {
p = particles[i];
/* in lower qualities there is not enough full pixels for all of them - dirty hack*/
if (isNaN(p.x)) continue
ctx.beginPath();
ctx.fillStyle = "rgb(" + p.r + ", " + p.g + ", " + p.b + ")";
ctx.fillStyle = "rgba(" + p.r + ", " + p.g + ", " + p.b + ", " + p.alpha + ")";
if (BLINK) ctx.globalAlpha = Math.sin(Math.PI * mod * 1.0);
if (PULSATION) { /* this would be 0 -> 1 */
var mod = ((GLOBAL_PULSATION ? 0 : p.deltaOffset) + now) % PULSATION_PERIOD / PULSATION_PERIOD;
/* lets make the value bouncing with sinus */
mod = Math.sin(mod * Math.PI);
} else var mod = 1;
var offset = TREMBLING ? TREMBLING * (-1 + Math.random() * 2) : 0;
var radius = PARTICLE_RADIUS * p.radius;
if (!ARC) {
ctx.fillRect(offset + p.x - mod * radius / 2 | 0, offset + p.y - mod * radius / 2 | 0, radius * mod,
radius * mod);
} else {
ctx.arc(offset + p.x | 0, offset + p.y | 0, radius * mod, Math.PI * 2, false);
ctx.fill();
}
p.x += (p.dx - p.x) / 10;
p.y += (p.dy - p.y) / 10;
}
}
function get_destinations() {
for (var i = 0; i < particles.length; i++) {
pa = particles[i];
particles[i].alpha = 1;
var distance = [];
nearest_position = 0;
if (positions.length) {
for (var n = 0; n < positions.length; n++) {
po = positions[n];
distance[n] = Math.sqrt((pa.x - po.x) * (pa.x - po.x) + (pa.y - po.y) * (pa.y - po.y));
if (n > 0) {
if (distance[n] <= distance[nearest_position]) {
nearest_position = n;
}
}
}
particles[i].dx = positions[nearest_position].x;
particles[i].dy = positions[nearest_position].y;
particles[i].distance = distance[nearest_position];
var po1 = positions[nearest_position];
for (var n = 0; n < positions.length; n++) {
var po2 = positions[n];
distance = Math.sqrt((po1.x - po2.x) * (po1.x - po2.x) + (po1.y - po2.y) * (po1.y - po2.y));
if (distance <= 5) {
positions.splice(n, 1);
}
}
} else {
//particles[i].alpha = 0;
}
}
}
function init() {
new_positions();
setInterval(draw, 30);
setInterval(new_positions, 2000);
}
init();
};
body {
background: #000;
text-align: center;
font-family: "simhei"
}
canvas {
margin: auto;
position: absolute;
left: 0;
right:0;
top: 0;
bottom: 0;
}
h5酷炫粒子java代码_html5粒子效果文字特效相关推荐
- java怎么设计好看的界面,javaswing酷炫界面 java swing界面设计
java swing怎样开发出漂亮的界面 Swing 支持切换界面风格啊 默认的是Metal风格,确实不好看 你可以切换为Windows风格,看起来和Windows上的程序就是一样滴了,还可以切换为苹 ...
- 酷炫纯CSS代码实现时空穿梭动效
效果展示: 使用场景,可以用于大数据大屏背景,或者是穿越动画的过渡,下载地址在文章末尾 项目目录结构: html部分: <!doctype html> <html> & ...
- 酷炫特效登陆界面html代码,酷炫的登录表单动画效果
一款酷炫的登录表单动画效果,输入用户信息之后点击登录按钮(表单验证可自行添加),按钮立即变成圆环旋转的加载动画,数秒钟后颜色填充整个窗口并切换到登录后的用户界面,里面有一些消息提示和日期显示效果. 查 ...
- 年会酷炫抽奖,绚丽3D照片墙效果,html抽奖功能,canvas星空 流星效果
年会酷炫抽奖,绚丽3D照片墙效果,html抽奖功能,canvas星空 流星效果,抽奖功能完善,中奖人员不会再次中奖,适合10-200人抽奖活动 源码下载地址:https://download.csdn ...
- php 鼠标经过 图片,jq实现酷炫的鼠标经过图片翻滚效果_jquery
短短的十多行代码就实现了一个酷炫的图片翻滚代码,要实现这个效果并不难,只要思路对了,一切都好办,不多说了,直接上代码看效果! html结构: *{ margin:0; padding:0;} .lis ...
- Android 酷炫的3d立体圆柱动画效果实现
最近在drrible上看到一个超酷炫的效果,立体圆柱缓慢上升:https://dribbble.com/shots/7077455-Spending-analytics 然后准备实现一波,做之前在网上 ...
- 安卓开发20:动画之Animation 详细使用-主要通过java代码实现动画效果
AlphaAnimation 透明效果实现: activity_main.xml中仅仅是一个简单的图片,下面的例子都会使用这个xml: <RelativeLayout xmlns:android ...
- 循环队列真的没那么难,就那么几个注意点,附Java代码及运行效果
1. 队列 队列是一种常见的线性数据结构,满足先进先出(First In First Out),简称为FIFO,第一次看到FIFO还以为是单片机的输出输出什么的,见笑了.数据结构不太了解的话可以看看我 ...
- java运用ascii实现动画效果_安卓开发20:动画之Animation 详细使用-主要通过java代码实现动画效果...
AlphaAnimation 透明效果实现: activity_main.xml中仅仅是一个简单的图片,下面的例子都会使用这个xml: xmlns:tools="http://schemas ...
最新文章
- 1.1.3 以类为单位的编程思想
- Android实现导航菜单随着ListView联动,当导航菜单遇到顶部菜单时停止在哪里,并且listview仍能滑动...
- @Singleton能保证单例吗
- 要广还是要深,这是一个问题
- C语言链表返回第n个到最后的节点的算法(附完整源码)
- 集合到文件改进版【应用】
- python asyncio_Python 中的异步编程:Asyncio
- Windows 集成 FTP 服务器配置–WS08R2已验证
- micropython教程modbus_基于S7-300400 CPU集成PN接口的Modbus TCP在TIA Portal的使用入门教程...
- eureka 客户端服务启动了又失败了_Spring cloud Eureka服务注册与发现详解
- java multipy_python multi-thread multi-process
- 对软件系统进行验收测试,宁夏软件系统验收测试_找小赛
- 华为手机在计算机里怎么隐藏游戏,原来华为手机隐藏着这么多实用功能!玩一年恐怕也发现不了...
- EasyExcel的导入excel文件
- mvn scm 作用
- servu ip段访问_西部数码使用指南:利用安全组设置拦截IP(IP段)
- Python Basic - python 文件对象的文件交互各类方法描述与实现
- 潜在客户生成,应该如何做?
- 若要运行此应用程序,您必须首先安装NET Framework 解决办法
- BB10 SDK离线安装步骤