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">
			* { color: #808080; }
			body { background-color: #000000; background-image: url('space.jpg'); background-position: top center; margin: 0px; overflow: hidden; }
			#info { position: absolute; top: 0px; width: 100%; padding: 5px; font-family:Monospace; font-size:13px; text-align:center; }
		</style>
	</head>
	<body>

	

		<div id="container"></div>
		<div id="info">Rollover the sun to create a eclipse.</div>		

		<script type="text/javascript">

			var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight,
			SCREEN_WIDTH_HALF = window.innerWidth / 2, SCREEN_HEIGHT_HALF = window.innerHeight / 2,
			LEVELS = 32;

			var context, shape, shapeContext;
			var planet;

			var mouseX = 0, mouseY = 0;
			var easedMouseX = 0, easedMouseY = 0;

			init();
			setInterval(loop, 1000/30);

			function init() {
			
				var container, canvas;
			
				container = document.getElementById('container');

				planet = document.createElement("canvas");
				planet.width = 150;
				planet.height = 150;
				planet.style.position = 'absolute';
				container.appendChild(planet);

				planetContext = planet.getContext("2d");
				planetContext.beginPath();
				planetContext.arc(75 - (easedMouseX * 1000), 75 - (easedMouseY * 1000), 75, 0, Math.PI * 2, true);
				planetContext.fillStyle = "rgb(0, 0, 0)";
				planetContext.fill();

				canvas = document.createElement("canvas");
				canvas.width = 512;
				canvas.height = 512;
				canvas.style.position = 'absolute';
				canvas.styl.........完整代码请登录后点击上方下载按钮下载查看

网友评论0