html--Noname

<!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>
  html, body {
	overflow: hidden;
	margin: 0;
	padding: 0;
	width: 100%;
	height: 100%;
	background:#000;
}
canvas {
	position: absolute;
	width: 100%;
	height: 100%;
	background:#000;
	cursor: pointer;
}
  </style>
 </HEAD>

 <BODY>
  <script>
  "use strict";
{
	// http://mrl.nyu.edu/~perlin/noise/
	const perlin = {
		init () {
			this.p = new Uint8Array(512);
			this.reset();
		},
		reset() {
			const p = new Uint8Array(256);
			for (let i = 0; i < 256; i++) p[i] = i;
			for (let i = 255; i > 0; i--) {
				const n = Math.floor((i + 1) * Math.random());
				[p[i], p[n]] = [p[n], p[i]];
			}
			for (let i = 0; i < 512; i++) this.p[i] = p[i & 255];
		},
		lerp(t, a, b) {
			return a + t * (b - a);
		},
		grad2d(i, x, y) {
			const v = (i & 1) === 0 ? x : y;
			return (i & 2) === 0 ? -v : v;
		},
		noise2d(x2d, y2d) {
			const X = Math.floor(x2d) & 255;
			const Y = Math.floor(y2d) & 255;
			const x = x2d - Math.floor(x2d);
			const y = y2d - Math.floor(y2d);
			const fx = (3 - 2 * x) * x * x;
			const fy = (3 - 2 * y) * y * y;
			const p0 = this.p[X] + Y;
			const p1 = this.p[X + 1] + Y;
			return this.lerp(
				fy,
				this.lerp(
					fx,
					this.grad2d(this.p[p0], x, y),
					this.grad2d(this.p[p1], x - 1, y)
				),
				this.lerp(
					fx,
					this.grad2d(this.p[p0 + 1], x, y - 1),
					this.grad2d(this.p[p1 + 1], x - 1, y - 1)
				)
			);
		}
	};
/
	const canvas = {
		init() {
			this.elem = document.createElement("canvas");
			document.body.appendChild(this.elem);
			this.width = this.elem.width = this.elem.offsetWidth;
			this.height = this.elem.height = this.elem.offsetHeight;
			return this.elem.getContext("2d");
		}
	};
/
	const webgl = {
		init(canvas, options) {
			this.elem = document.createElement("canvas");
			this.gl = (
				this.elem.getContext("webgl", options) ||
				this.elem.getContext("experimental-webgl", options)
			);
			if (!this.gl) return false;
			const vertexShader = this.gl.createShader(this.gl.VERTEX_SHADER);
			this.gl.shaderSource(vertexShader, `
				precision highp float;
				attribute vec3 aPosition;
				uniform vec2 uResolution;
				void main() {
					gl_PointSize = 1.0;
					gl_Position = vec4(
						( aPosition.x / uResolution.x * 2.0) - 1.0, 
						(-aPosition.y / uResolution.y * 2.0) + 1.0, 
						0.0,
						1.0
					);
				}`
			);
			this.gl.compileShader(vertexShader);
			const fragmentShader = this.gl.createShader(this.gl.FRAGMENT_SHADER);
			this.gl.shaderSource(fragmentShader, `
				precision highp float;
				void main() {
					gl_FragColor = vec4(0.2, 0.3, 1.0, 1.0);
				}`
			);
			this.gl.compileShader(fragmentShader);
			const program = this.gl.createProgram();
			this.gl.attachShader(program, vertexShader);
			this.gl.attachShader(program, fragmentShader);
			this.gl.linkProgram(program);
			this.gl.useProgram(program);
			this.aPosition = this.gl.getAttribLocation(program, "aPosition");
			this.gl.enableVertexAttribArray(this.aPosition);
			this.positionBuffer = this.gl.createBuffer();
			this.elem.width = canvas.width;
			this.elem.height = canvas.height;
			const uResolution = this.gl.getUniformLocation(program, "uResolution");
			this.gl.enableVertexAttribArray(uResolution);
			this.gl.uniform2f(uResolution, canvas.width, canvas.height);
			this.gl.viewport(
				0,
				0,
				this.gl.drawingBufferWidth,
				this.gl.drawingBufferHeight
			);
			return this.gl;
		},
		drawBuffer(data, num) {
			this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.positionBuffer);
			this.gl.vertexAttribPointer(this.aPosition, 2, this.gl.FLOAT, false, 0, 0);
			this.gl.bufferData(
				this.gl.ARRAY_BUFFER,
				data,
				this.gl.DYNAMIC_DRAW
			);
			this.gl.drawArrays(this.gl.GL_POINTS, 0, num);
		}
	};
/
	const ctx = canvas.init();
	const gl = webgl.init(canvas, {
		alpha: false,
		stencil: false,
		antialias: false,
		depth: false,
	});
	perlin.init();
	const nParticles = 30000;
	const velocities = new Float32Array(nParticles * 2);
	const particles = new Float32Array(nParticles * 2);
	let frame = 0;
	for (let i = 0; i < nParticles; i++) {
		const p = i * 2;
		particles[p+0] = Math.random() * canvas.width;
		particles[p+1] = Math.random() * canvas.height;
	}
/
	const run = () => {
		requestAnimationFrame(run);
		frame++;
		gl.clear(gl.COLOR_BUFFER_BIT);
		ctx.globalCompositeOperation = "source-over";
		ctx.fillStyle = "rgba(0, 0, 0, 0.025)";
		ctx.fillRect(0, 0, canvas.width, canvas.height);
		ctx.globalCompositeOperation = "lighter";
		for (let i = 0; i < nParticles; i++) {
			const p = i * 2;
			let n = 80 * perlin.noise2d(particles[p+0] * 0.001, particles[p+1] * 0.001);
			velocities[p+0] += 0.1 * Math.cos(n);
			velocities[p+1] += 0.1 * Math.sin(n);
			particles[p+0]  += (velocities[p+0] *= 0.99);
			particles[p+1]  += (velocities[p+1] *= 0.99);
			particles[p+0]   = (canvas.width  + particles[p+0]) % canvas.width;
			particles[p+1]   = (canvas.height + particles[p+1]) % canvas.height;
		}
		webgl.drawBuffer(particles, nParticles);
		if (frame > 30) ctx.drawImage(webgl.elem, 0, 0);	
	};
	requestAnimationFrame(run);
/
	["click", "touchdown"].forEach(event => {
		document.addEventListener(event, e => perlin.reset(), false);
	});
}
  </script>
 </BODY>
</HTML>


在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

相关推荐

  1. HTML

    2024-04-27 09:00:04       48 阅读
  2. <span style='color:red;'>HTML</span>

    HTML

    2024-04-27 09:00:04      36 阅读
  3. <span style='color:red;'>HTML</span>

    HTML

    2024-04-27 09:00:04      36 阅读
  4. HTML

    2024-04-27 09:00:04       31 阅读
  5. HTML

    2024-04-27 09:00:04       36 阅读
  6. HTML---html面试题

    2024-04-27 09:00:04       44 阅读
  7. HTML:HTML事件汇总

    2024-04-27 09:00:04       35 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-27 09:00:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-27 09:00:04       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-27 09:00:04       87 阅读
  4. Python语言-面向对象

    2024-04-27 09:00:04       96 阅读

热门阅读

  1. 计算机常见病毒及处理办法

    2024-04-27 09:00:04       32 阅读
  2. 【力扣】18. 四数之和

    2024-04-27 09:00:04       34 阅读
  3. PostgreSQL的扩展(extensions)-常用的扩展之pgBackRest

    2024-04-27 09:00:04       32 阅读
  4. fs.trash.interval详解

    2024-04-27 09:00:04       37 阅读
  5. rkt的原理及应用详解(一)

    2024-04-27 09:00:04       26 阅读
  6. Unity 异步与工作线程(多线程)

    2024-04-27 09:00:04       33 阅读
  7. 美团:搜索推荐算法工程师

    2024-04-27 09:00:04       35 阅读
  8. 嵌入式软件笔试题

    2024-04-27 09:00:04       31 阅读
  9. FinOps在云产品成本优化中的实践与策略

    2024-04-27 09:00:04       23 阅读
  10. 对于IOC的注入两种方式(注解和XML)

    2024-04-27 09:00:04       35 阅读