当前位置: 首页 > news >正文

珠海网站哪家好如何给网站流量来源做标记通过在网址后边加问号?

珠海网站哪家好,如何给网站流量来源做标记通过在网址后边加问号?,设计素材网站破解,wordpress域名更改实现目标 分析问题 整个图主要是用canvas实现,其中难点是将线的长度控制在一定范围内、并且透明度随长度变化。 前置知识 canvas绘制点、线、三角形、弧形 // 点ctx.moveTo(this.x, this.y);ctx.arc(this.x, this.y, this.r,0, 2 * Math.PI, false);ctx.fillStyle …

实现目标

在这里插入图片描述

分析问题

整个图主要是用canvas实现,其中难点是将线的长度控制在一定范围内、并且透明度随长度变化。

前置知识

canvas绘制点、线、三角形、弧形

	// 点ctx.moveTo(this.x, this.y);ctx.arc(this.x, this.y, this.r,0, 2 * Math.PI, false);ctx.fillStyle = "white";ctx.fill();// 线ctx.beginPath();ctx.moveTo(p1.x, p1.y);ctx.lineTo(p2.x, p2.y);// 三角形ctx.beginPath();ctx.moveTo(p1.x, p1.y);ctx.lineTo(p2.x, p2.y);ctx.lineTo(p3.x, p3.y);ctx.closePath();// 弧形ctx.beginPath();ctx.arc(100, 100, 50, 0, Math.PI / 2, false); // 从 0° 到 90°(顺时针)ctx.strokeStyle = "blue";ctx.lineWidth = 3;ctx.stroke();

代码实战

实现思路
随机生成n个点,然后随机选m个 三个随机点(属于n个点中) 组成的集合绘制三角形。

<head><style>* {margin: 0 auto;padding: 0;}canvas {position: fixed;background: black;width: 100%;height: 100%;}</style>
</head>
<body><canvas></canvas><script src="./index.js"></script>
</body>
// 获取 canvas节点
let cts = document.querySelector("canvas");
let ctx = cts.getContext("2d");
// 设置宽高
cts.width = window.innerWidth;
cts.height = window.innerHeight;class Point {constructor(x, y) {this.x = x;this.y = y;this.r = 1;}draw() {ctx.moveTo(this.x, this.y);ctx.arc(this.x, this.y, this.r,0, 2 * Math.PI, false);ctx.fillStyle = "white";ctx.fill();}
}class Graph {constructor() {// 圆点个数this.pointSize = 500;this.maxHeight = window.innerHeight;this.maxWidth = window.innerWidth;// 对角线this.maxLine = Math.sqrt(this.maxHeight * this.maxHeight + this.maxWidth * this.maxWidth);// 所有点集this.points = new Array(this.pointSize).fill(0).map(() =>new Point(Math.random() * this.maxWidth, Math.random() * this.maxHeight))}// 绘制 p1-p2 直线drawLine(p1, p2) {let tLine =  Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));let at = 0.2 - tLine / 500;// this.maxLine;// 太长的线不绘制if (tLine > 100) return;ctx.moveTo(p1.x, p1.y);ctx.lineTo(p2.x, p2.y);ctx.strokeStyle = `rgba(255, 255, 255, ${at})`;}// 绘制三角形drawRan(p1, p2, p3) {if (!p1 || !p2 || !p3) return;ctx.beginPath();this.drawLine(p1, p2);this.drawLine(p2, p3);ctx.stroke();}draw() {// 绘制所有圆点for (let i = 0; i < this.pointSize; i++) {let p1 = this.points[i];p1.draw();}// 选取随机的三点绘制三角形for (let i = 0; i < this.pointSize * this.pointSize / 10; i++) {let t1 = Math.floor(Math.random() * this.pointSize);let t2 =  Math.floor(Math.random() * this.pointSize);let t3 =  Math.floor(Math.random() * this.pointSize);let p1 = this.points[t1];let p2 = this.points[t2];let p3 = this.points[t3];this.drawRan(p1, p2, p3);}}
}let init = () => {let g = new Graph();g.draw();
}
init();

优化

点集动态移动(弧形),随机选点、弧形半径随机。


let cts = document.querySelector("canvas");
let ctx = cts.getContext("2d");let setWH = () => {cts.width = window.innerWidth;cts.height = window.innerHeight;
}
let clearBG = () => {ctx.clearRect(0, 0, cts.width, cts.height);
}class Point {constructor(x, y) {this.px = x;this.py = y;this.r = 1;this.radius = 500 * Math.random();this.angle = 0;}draw() {ctx.moveTo(this.x, this.y);ctx.arc(this.x, this.y, this.r,0, 2 * Math.PI, false);ctx.fillStyle = "white";ctx.fill();}move() {this.x = this.px + this.radius * Math.cos(this.angle);this.y = this.py + this.radius * Math.sin(this.angle);this.angle = (this.angle + 0.05) % (Math.PI * 2);}
}class Graph {constructor() {this.pointSize = 500;this.maxHeight = window.innerHeight;this.maxWidth = window.innerWidth;this.maxLine = Math.sqrt(this.maxHeight * this.maxHeight + this.maxWidth * this.maxWidth);this.points = new Array(this.pointSize).fill(0).map(() =>new Point(Math.random() * this.maxWidth, Math.random() * this.maxHeight))}drawLine(p1, p2) {let tLine =  Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));let at = 0.2 - tLine / 500;// this.maxLine;if (tLine > 100) return;ctx.moveTo(p1.x, p1.y);ctx.lineTo(p2.x, p2.y);ctx.strokeStyle = `rgba(255, 255, 255, ${at})`;}drawRan(p1, p2, p3) {if (!p1 || !p2 || !p3) return;ctx.beginPath();this.drawLine(p1, p2);this.drawLine(p2, p3);ctx.stroke();}draw() {for (let i = 0; i < this.pointSize; i++) {let p1 = this.points[i];p1.move();p1.draw();}for (let i = 0; i < this.pointSize * this.pointSize / 10; i++) {let t1 = Math.floor(Math.random() * this.pointSize);let t2 =  Math.floor(Math.random() * this.pointSize);let t3 =  Math.floor(Math.random() * this.pointSize);let p1 = this.points[t1];let p2 = this.points[t2];let p3 = this.points[t3];this.drawRan(p1, p2, p3);}}
}let timer = null;let init = () => {setWH();let g = new Graph();timer = setInterval(() => {clearBG();g.draw();}, 1000)
}
init();
http://www.dtcms.com/a/613548.html

相关文章:

  • Rust入门
  • Rust入门 之一
  • “伪”局域网
  • C语言编译软件Mac | 在Mac上选择最合适的C语言编译工具
  • 怎么样建设一个网上教学网站网页版微信二维码不能直接识别
  • Linux BPF 技术深度解析:从原理到实践
  • 高端网站报价wordpress如何添加背景音乐
  • C# 对多个任务进行符合管理
  • 在Eclipse IDE for Embedded C/C++ Developers软件中定义的宏,编译C源文件时编译器无法找到宏定义!
  • 从局域网到全网可用!PDFMathTranslate 翻译工具的进阶使用法
  • 深入理解 JavaScript 异步编程:从单线程到 Promise 的完整指南
  • 怎么自己做歌曲网站沈阳网站建设方案策划
  • 电脑卡顿因重复文件?AllDup无安装版快速查重+批量删除 文件管理混乱?AllDup多模式查重工具,Python开发者也能高效用
  • Dubbo Mock机制详解:服务降级与本地测试的利器
  • JDBC与事务的协同:ThreadLocal的巧妙运用
  • 底层视觉及图像增强-项目实践理论补充(十六-0-(13):HDR技术全链路解析:从原理到LED显示工程实践):从奥运大屏,到手机小屏,快来挖一挖里面都有什么
  • 深圳服务平台网站网站提示域名解析错误怎么办
  • 论文阅读13——基于大语言模型和视觉模态融合的可解释端到端自动驾驶框架:DriveLLM-V的设计与应用
  • 考研408--数据结构--day2--顺序表及其增删改查
  • 软件演示环境动态扩展与成本优化:基于目标跟踪与计划扩展的AWS Auto Scaling策略
  • 网站设计的资质叫什么花蝴蝶韩国免费视频
  • AI Agent 之工具使用:从函数定义到实际应用
  • 【C++】 map/multimap底层原理与逻辑详解
  • 如何利用国外网站开发客户wordpress的免费模板
  • C++、Java 还是测试开发?
  • Java 开发 - 粘包处理器 - 基于消息头 + 消息体(魔数验证、长度验证)
  • Spring Cloud Data Flow 简介
  • 前端性能优化指标,首次内容绘制与交互时间
  • MySQL :实用函数、约束、多表查询与事务隔离
  • 【Java架构师体系课 | MySQL篇】③ Explain执行计划详解