html--红色空间


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
  <style>
  body {
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background-color: black;
}

canvas {
  width: 100%;
  height: 100%;
}

  </style>
 </HEAD>

 <BODY>
<canvas></canvas>
  <script>
  const c = document.getElementsByTagName("canvas")[0],
	ctx = c.getContext("2d"),
	dXCam = 0.08,
	dYCam = 0.08,
	dAng = 0.004,
	sep = 5,
	colorPixel = (i, color, z) => {
		i <<= 2;
		pixels[i] = (color >> 16) & 0xff;
		pixels[i + 1] = (color >> 8) & 0xff;
		pixels[i + 2] = color & 0xff;
		pixels[i + 3] = 0xff - (z << 2);
	},
	renderFloor = (cos, sin, xCam, yCam) => {
		for (let y = 0; y < height; ++y) {
			const yd = (y - height / 2) / height;
			const zd = yd < 0 ? -sep / yd : sep / yd;
			if (zd > 60) continue;
			for (let x = 0; x < width; ++x) {
				const xd = (x - width / 2) / height * zd;
				const xCol = xd * cos - zd * sin + xCam;
				const yCol = xd * sin + zd * cos + yCam;
				const color = xCol ^ yCol;
				colorPixel(x + y * width, color << 21, zd);
			}
		}
	},
	loop = () => {
		renderFloor(Math.cos(ang), Math.sin(ang), xCam, yCam);
		ctx.putImageData(data, 0, 0);
		ang += dAng;
		xCam += dXCam;
		yCam += dYCam;
		requestAnimationFrame(loop);
	};

let data, pixels, width, height, ang = 0, xCam = 100, yCam = 0;

(() => {
	width = window.innerWidth;
	height = window.innerHeight;
	c.width = width;
	c.height = height;
	data = ctx.getImageData(0, 0, width, height);
	pixels = data.data;
	loop();
})();

  </script>
 </BODY>
</HTML>

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fo安方

觉得俺的文章还行,感谢打赏,爱

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值