首页 > 其他分享 >html--全魔乱舞

html--全魔乱舞

时间:2024-05-30 10:29:35浏览次数:20  
标签:p2 p3 const -- 0.5 全魔 width html Math

<!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;
	touch-action: none;
	content-zooming: none;
	position: absolute;
	margin: 0;
	padding: 0;
	width: 100%;
	height: 100%;
	background: #000;
}

#screen {
	position: absolute;
	width: 100vh;
	height: 100vh;
	max-height: 100vw;
	max-width: 100vw;
	margin: auto;
	top: 0;
	bottom: 0;
	left: 0;
	right: 0;
	user-select: none;
}
#screen canvas {
	position: relative;
	float: left;
	display: block;
	width: 28.7vmin;
	height: 28.7vmin;
	background:#222;
	margin-left: 3vmin;
	margin-top: 3vmin;
	border-radius: 3vmin;
}</style>
 </HEAD>

 <BODY><div id="screen"></div>
  <script>"use strict";
{
	const Box = class {
		constructor(container, i) {
			this.canvas = document.createElement("canvas");
			container.appendChild(this.canvas);
			this.width = this.canvas.width = this.canvas.offsetWidth;
			this.height = this.canvas.height = this.canvas.offsetHeight;
			this.ctx = this.canvas.getContext("2d");
			this.ctx.lineCap = "round";
			this.points = Array.from(
				{ length: 12 },
				_ => new Box.Point(this.width * 0.5, this.width * 0.5)
			);
			this.constraints = [];
			this.color = `hsl(${10 * i}, 70%, 30%)`;
			// links p1, p2, length, width
			const links = [
				[0, 1, 6, 5],
				[1, 2, 5, 4],
				[3, 7, 10, 6],
				[7, 8, 7, 4],
				[3, 9, 10, 6],
				[9, 10, 7, 4],
				[0, 4, 5, 0],
				[0, 3, 7, 9],
				[0, 5, 6, 5],
				[5, 6, 5, 4],
				[4, 11, 0.1, 11]
			];
			// constaints: p1, p2, p3, angle, range
			const p2 = Math.PI / 2;
			const p3 = Math.PI / 3;
			[
				[0, 4, 11, 0, 0, 0],
				[4, 0, 3, 0, 1, 0.05],
				[3, 0, 4, 0, 1, 0.05],
				[3, 0, 1, p2, p2 * 4, 0],
				[0, 1, 2, -p2, p3, 0.05],
				[3, 0, 5, p2, p2 * 4, 0],
				[0, 5, 6, -p2, p3, 0.05],
				[0, 3, 7, -p3 + 0.5, p2, 0.05],
				[0, 3, 9, -p3 + 0.5, p2, 0.05],
				[3, 7, 8, p2, p3, 0.05],
				[3, 9, 10, p2, p3, 0.05]
			].forEach(p => {
				this.constraints.push(new Box.Constraint(this, links, p, this.width / 30));
			});
		}
		run() {
			this.ctx.setTransform(0, 1, 1, 0, 0, 0);
			this.ctx.clearRect(0, 0, this.width + 1, this.height + 1);
			this.ctx.globalCompositeOperation = "lighter";
			for (const constraint of this.constraints) constraint.solve();
			for (const point of this.points) point.integrate();
		}
	};
	Box.Point = class {
		constructor(x, y) {
			this.x = x;
			this.y = y;
			this.xb = x;
			this.yb = y
			this.w = 0;
		}
		integrate() {
			const vx = (this.x - this.xb) * 0.995;
			const vy = (this.y - this.yb) * 0.995;
			this.xb = this.x;
			this.yb = this.y;
			this.x += vx;
			this.y += vy;
		}
	};
	Box.Constraint = class {
		constructor(box, links, p, s) {
			this.ctx = box.ctx;
			this.p1 = box.points[p[0]];
			this.p2 = box.points[p[1]];
			this.p3 = box.points[p[2]];
			this.m = 0;
			this.angle = p[3];
			this.range = p[4];
			this.force = p[5];
			const link1 = this.link(links, p[0], p[1]);
			const link2 = this.link(links, p[1], p[2]);
			this.len1 = link1[2] * s;
			this.len2 = link2[2] * s;
			this.width = link2[3] * s * 0.5;
			if (this.width * 0.5 > this.p3.w) this.p3.w = this.width * 0.5;
			this.shape = document.createElement("canvas");
			if (this.width) {
				this.shape.width = this.len2 + this.width;
				this.shape.height = this.width;
				const ict = this.shape.getContext("2d");
				ict.lineCap = "round";
				ict.strokeStyle = box.color;
				ict.beginPath();
				ict.lineWidth = this.width * 0.9;
				ict.moveTo(this.width * 0.5, this.width * 0.5);
				ict.lineTo(this.len2 + this.width * 0.5, this.width * 0.5);
				ict.stroke();
			}
		}
		link(links, p0, p1) {
			for (const link of links) {
				if (
					(p0 === link[0] && p1 === link[1]) ||
					(p1 === link[0] && p0 === link[1])
				)
					return link;
			}
		}
		solve() {
			const a1 = Math.atan2(this.p2.y - this.p1.y, this.p2.x - this.p1.x);
			const b1 = Math.atan2(this.p3.y - this.p2.y, this.p3.x - this.p2.x);
			const c = this.angle - (b1 - a1);
			const d = c > Math.PI ? c - 2 * Math.PI : c < -Math.PI ? c + 2 * Math.PI : c;
			const e = Math.abs(d) > this.range ? (-Math.sign(d) * this.range + d) * this.force : 0;
			const cos1 = Math.cos(a1 - e);
			const sin1 = Math.sin(a1 - e);
			const x1 = this.p1.x + (this.p2.x - this.p1.x) * 0.5;
			const y1 = this.p1.y + (this.p2.y - this.p1.y) * 0.5;
			this.p1.x = x1 - cos1 * this.len1 * 0.5;
			this.p1.y = y1 - sin1 * this.len1 * 0.5;
			this.p2.x = x1 + cos1 * this.len1 * 0.5;
			this.p2.y = y1 + sin1 * this.len1 * 0.5;
			this.m += 0.0005 * (Math.random() - 0.5);
			this.m *= 0.99;
			const a2 = this.m + Math.atan2(this.p2.y - this.p3.y, this.p2.x - this.p3.x) + e;
			const cos2 = Math.cos(a2);
			const sin2 = Math.sin(a2);
			const x2 = this.p3.x + (this.p2.x - this.p3.x) * 0.5;
			const y2 = this.p3.y + (this.p2.y - this.p3.y) * 0.5;
			this.p3.x = x2 - cos2 * this.len2 * 0.5;
			this.p3.y = y2 - sin2 * this.len2 * 0.5;
			this.p2.x = x2 + cos2 * this.len2 * 0.5;
			this.p2.y = y2 + sin2 * this.len2 * 0.5;
			if (this.width) {
				this.ctx.setTransform(cos2, sin2, -sin2, cos2, this.p2.x, this.p2.y);
				this.ctx.drawImage(
					this.shape,
					-this.len2 - this.width * 0.5,
					-this.width * 0.5
				);
			}
		}
	};
	const screen = document.querySelector("#screen");
	const boxes = Array.from({ length: 9 }, (v, i) => new Box(screen, i));
	const run = () => {
		requestAnimationFrame(run);
		for (const box of boxes) box.run();
	};
	run();
}</script>
 </BODY>
</HTML>


在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

标签:p2,p3,const,--,0.5,全魔,width,html,Math
From: https://blog.csdn.net/stqer/article/details/139316815

相关文章

  • 你知道列存储的定义和优势以及行存储的区别?--数据仓库基本概念
    列存储(ColumnarStorage)是一种数据库存储数据的方式,它将每一列的数据存储在一起,而不是按行存储。这与传统的行存储(RowStorage)相反,后者将一行中的所有数据存储在一起。列存储的定义:列存储数据库或文件系统会将表中的每一列数据分别存储在不同的位置。例如,如果有一个表包含......
  • Hive中常用query--关联/聚合/去重/排序举例
    在Hive中,可以使用各种查询来执行关联(JOINs)、聚合(Aggregations)、去重(Distinct)和排序(Sorting)操作。以下是一些常见的查询示例:关联(JOIN):在Hive中执行关联操作通常是为了将两个或多个表中相关的行连接起来。SELECTe.name,e.salary,d.department_nameFROMemployeeseJOIN......
  • 【包邮送书】你好!C语言
    欢迎关注博主Mindtechnist或加入【智能科技社区】一起学习和分享Linux、C、C++、Python、Matlab,机器人运动控制、多机器人协作,智能优化算法,滤波估计、多传感器信息融合,机器学习,人工智能等相关领域的知识和技术。关注公粽号《机器和智能》回复关键词“python项目实战......
  • 新一代爬虫平台!不写代码即可完成爬虫...
    大家好,我是Java陈序员。今天,给大家介绍一个优秀的爬虫平台,无需编写代码,只要通过简单的流程配置,即可实现爬虫。关注微信公众号:【Java陈序员】,获取开源项目分享、AI副业分享、超200本经典计算机电子书籍等。项目介绍spider-flow——新一代爬虫平台,以流程图的方式定义爬虫,是......
  • C#解析json的几种方式
    json格式的数据是javascript原生的一种数据格式,比xml更简洁。它有两种形式:json对象和json对象数组。 在此之前,有必要解释几个基本概念:json字符串,就是string,它一定是由双引号包起来的,如"{'name':'jerry'}"。这是一个string,尽管去掉双引号后它就是一个json对象。json对象,就是以......
  • cocos 无法设置Node layer属性
    升级到3.83之后突然无法设置Nodelayer属性,编译器打开之后无法保存1.删除temp,library文件夹后重新打开,(仍无法解决。)。原以为升级之后问他资源没有升级导致2.为什么打开prefab之后又恢复layer属性??分析原因:cocoseditor里的属性是从全局变量里读.在浏览器环境中cc是一个全......
  • css23 CSS Links, Cursors
    https://www.w3schools.com/css/css_link.asp CSSLinks  WithCSS,linkscanbestyledinmanydifferentways.StylingLinksLinkscanbestyledwithanyCSSproperty(e.g.color,font-family,background,etc.).Examplea{  color:hotpink;}&l......
  • mac,linux 查看文件编码
    查看文件编码可以通过以下几种方式:在类unix编程时,在读取文本的时候会遇到文本的编码问题,这时候就要查看文件内容的编码了,下面是查看编码的几种方式1.在Vim中可以直接查看文件编码:setfileencoding即可显示文件编码格式。如果你只是想查看其它编码格式的文件或者想解决用Vim......
  • Linux 内核启动流程
    链接脚本vmlinux.lds示例代码36.1.1vmlinux.lds链接脚本492OUTPUT_ARCH(arm)493ENTRY(stext)494jiffies=jiffies_64;495SECTIONS496{497/*498*XXX:Thelinkerdoesnotdefinehowoutputsectionsare499*assignedtoinputsectionswhentherearem......
  • 如何使用前端表格控件实现多数据源整合?
    前言作为表格产品的典型应用场景之一,几乎所有的行业都会存在类Excel报表开发这样的应用场景,而在这些应用场景中,经常会遇见下面的这些痛点:报表数据往往来自多个不同的数据源,需要报表系统能够同时连接多个数据源,并融合不同的数据格式实际的报表中需要对数据结果进行逻辑计算,例......