canvas实现三维水波波纹文字动态效果代码

代码语言:html

所属分类:三维

代码描述:canvas实现三维水波波纹文字动态效果代码,可以输入指定文字实现出水波纹动画效果。

代码标签: 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 = canvasText.getContext("2d");
				contextText.font = "80px Helvetica";
				contextText.fillStyle = "rgb(255, 0, 0)";
				contextText.textAlign = "center";

				// Output (Parallax)

				canvas = document.createElement("canvas");
				canvas.width = WIDTH;
				canvas.height = HEIGHT;
				canvas.style.width = window.innerWidth + "px";
				canvas.style.height = window.innerHeight + "px";
				container.appendChild(canvas);

				context = canvas.getContext ("2d");
				context.fillStyle = "rgb(0, 0, 0)";
				context.fillRect(0, 0, WIDTH, HEIGHT);

				image = context.getImageData(0, 0, WIDTH, HEIGHT);
				data = image.data;

				document.addEventListener('mousedown', onDocumentMouseDown, false);
				document.addEventListener('mousemove', onDocumentMouseMove, false);
				document.addEventListener('mouseup', onDocumentMouseUp, false);
				document.addEventListener('mouseout', onDocumentMouseOut, false);
				document.addEventListener('touchstart', onDocumentTouchStart, false);
				document.addEventListener('touchmove', onDocumentTouchMove, false);
				document.addEve.........完整代码请登录后点击上方下载按钮下载查看

网友评论0