canvas实现三维水波波纹文字动态效果代码
代码语言:html
所属分类:三维
代码描述:canvas实现三维水波波纹文字动态效果代码,可以输入指定文字实现出水波纹动画效果。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style type="text/css">
body { background-color: #000000; margin: 0px; overflow: hidden; }
#info { position: absolute; top: 0px; width: 100%; color: #00a0c0; padding: 5px; font-family:Monospace; font-size:13px; text-align:center; }
</style>
</head>
<body>
<div id="container"></div>
<div id="info">Type some text and hit enter. Click to draw waves.</div>
<script type="text/javascript">
var QUALITY_X = 6, QUALITY_Y = 3,
WIDTH = Math.floor(window.innerWidth / QUALITY_X), HEIGHT = Math.floor(window.innerHeight / QUALITY_Y), SIZE = WIDTH * HEIGHT,
HEIGHT_HALF = Math.floor(HEIGHT / 2),
TEXT_OFFSETY = Math.floor((HEIGHT - 64) / 2),
context, image, data,
buffer1, buffer2, tempbuffer,
canvasHeightMap, contextHeightMap, imageHeightMap, dataHeightMap,
canvasText, contextText, imageText, dataText,
input, text,
isUserInteracting, pointers;
init();
setInterval(loop, 1000 / 60);
function init() {
var container, canvas;
container = document.getElementById('container');
// input box
input = document.createElement("input");
input.type = "text";
input.value = "type";
input.style.position = "absolute";
input.style.top = "10px";
input.style.left = "10px";
input.style.opacity = "0";
container.appendChild(input);
input.focus();
// Height Map (Water)
canvasHeightMap = document.createElement("canvas");
canvasHeightMap.width = WIDTH;
canvasHeightMap.height = HEIGHT;
contextHeightMap = canvasHeightMap.getContext("2d");
imageHeightMap = contextHeightMap.getImageData(0, 0, WIDTH, HEIGHT);
dataHeightMap = imageHeightMap.data
buffer1 = [];
buffer2 = [];
for (var i = 0; i < SIZE; i ++) {
buffer1[i] = 128;
buffer2[i] = 128;
}
// Text
canvasText = document.createElement("canvas");
canvasText.width = WIDTH;
canvasText.height = 128;
contextText = canv.........完整代码请登录后点击上方下载按钮下载查看
网友评论0