html--互动星空

news/2024/5/20 2:15:08
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>互动星空</title><style>
html,body {margin:0;overflow:hidden;width:100%;height:100%;cursor:none;background:black;background:linear-gradient(to bottom,#000000 0%,#5788fe 100%);
}
.filter {width:100%;height:100%;position:absolute;top:0;left:0;background:#fe5757;animation:colorChange 30s ease-in-out infinite;animation-fill-mode:both;mix-blend-mode:overlay;
}
@keyframes colorChange {0%,100% {opacity:0;
}
50% {opacity:.9;
}
}.landscape {position:absolute;bottom:0px;left:0;width:100%;height:100%;/*background-image:url(https://openclipart.org/image/2400px/svg_to_png/250847/Trees-Landscape-Silhouette.png);*/
background-image:url('http://www.jq22.com/css/img/xkbg.png');background-size:1000px 250px;background-repeat:repeat-x;background-position:center bottom;
}
</style>
</head>
<body><div class="landscape"></div>
<div class="filter"></div>
<canvas id="canvas"></canvas><script>
function Star(id, x, y){this.id = id;this.x = x;this.y = y;this.r = Math.floor(Math.random()*2)+1;var alpha = (Math.floor(Math.random()*10)+1)/10/2;this.color = "rgba(255,255,255,"+alpha+")";
}Star.prototype.draw = function() {ctx.fillStyle = this.color;ctx.shadowBlur = this.r * 2;ctx.beginPath();ctx.arc(this.x, this.y, this.r, 0, 2 * Math.PI, false);ctx.closePath();ctx.fill();
}Star.prototype.move = function() {this.y -= .15;if (this.y <= -10) this.y = HEIGHT + 10;this.draw();
}Star.prototype.die = function() {stars[this.id] = null;delete stars[this.id];
}function Dot(id, x, y, r) {this.id = id;this.x = x;this.y = y;this.r = Math.floor(Math.random()*5)+1;this.maxLinks = 2;this.speed = .5;this.a = .5;this.aReduction = .005;this.color = "rgba(255,255,255,"+this.a+")";this.linkColor = "rgba(255,255,255,"+this.a/4+")";this.dir = Math.floor(Math.random()*140)+200;
}Dot.prototype.draw = function() {ctx.fillStyle = this.color;ctx.shadowBlur = this.r * 2;ctx.beginPath();ctx.arc(this.x, this.y, this.r, 0, 2 * Math.PI, false);ctx.closePath();ctx.fill();
}Dot.prototype.link = function() {if (this.id == 0) return;var previousDot1 = getPreviousDot(this.id, 1);var previousDot2 = getPreviousDot(this.id, 2);var previousDot3 = getPreviousDot(this.id, 3);if (!previousDot1) return;ctx.strokeStyle = this.linkColor;ctx.moveTo(previousDot1.x, previousDot1.y);ctx.beginPath();ctx.lineTo(this.x, this.y);if (previousDot2 != false) ctx.lineTo(previousDot2.x, previousDot2.y);if (previousDot3 != false) ctx.lineTo(previousDot3.x, previousDot3.y);ctx.stroke();ctx.closePath();
}function getPreviousDot(id, stepback) {if (id == 0 || id - stepback < 0) return false;if (typeof dots[id - stepback] != "undefined") return dots[id - stepback];else return false;//getPreviousDot(id - stepback);
}Dot.prototype.move = function() {this.a -= this.aReduction;if (this.a <= 0) {this.die();return}this.color = "rgba(255,255,255,"+this.a+")";this.linkColor = "rgba(255,255,255,"+this.a/4+")";this.x = this.x + Math.cos(degToRad(this.dir))*this.speed,this.y = this.y + Math.sin(degToRad(this.dir))*this.speed;this.draw();this.link();
}Dot.prototype.die = function() {dots[this.id] = null;delete dots[this.id];
}var canvas  = document.getElementById('canvas'),ctx = canvas.getContext('2d'),WIDTH,HEIGHT,mouseMoving = false,mouseMoveChecker,mouseX,mouseY,stars = [],initStarsPopulation = 80,dots = [],dotsMinDist = 2,maxDistFromCursor = 50;setCanvasSize();
init();function setCanvasSize() {WIDTH = document.documentElement.clientWidth,HEIGHT = document.documentElement.clientHeight;                      canvas.setAttribute("width", WIDTH);canvas.setAttribute("height", HEIGHT);
}function init() {ctx.strokeStyle = "white";ctx.shadowColor = "white";for (var i = 0; i < initStarsPopulation; i++) {stars[i] = new Star(i, Math.floor(Math.random()*WIDTH), Math.floor(Math.random()*HEIGHT));//stars[i].draw();}ctx.shadowBlur = 0;animate();
}function animate() {ctx.clearRect(0, 0, WIDTH, HEIGHT);for (var i in stars) {stars[i].move();}for (var i in dots) {dots[i].move();}drawIfMouseMoving();requestAnimationFrame(animate);
}window.onmousemove = function(e){mouseMoving = true;mouseX = e.clientX;mouseY = e.clientY;clearInterval(mouseMoveChecker);mouseMoveChecker = setTimeout(function() {mouseMoving = false;}, 100);
}function drawIfMouseMoving(){if (!mouseMoving) return;if (dots.length == 0) {dots[0] = new Dot(0, mouseX, mouseY);dots[0].draw();return;}var previousDot = getPreviousDot(dots.length, 1);var prevX = previousDot.x; var prevY = previousDot.y; var diffX = Math.abs(prevX - mouseX);var diffY = Math.abs(prevY - mouseY);if (diffX < dotsMinDist || diffY < dotsMinDist) return;var xVariation = Math.random() > .5 ? -1 : 1;xVariation = xVariation*Math.floor(Math.random()*maxDistFromCursor)+1;var yVariation = Math.random() > .5 ? -1 : 1;yVariation = yVariation*Math.floor(Math.random()*maxDistFromCursor)+1;dots[dots.length] = new Dot(dots.length, mouseX+xVariation, mouseY+yVariation);dots[dots.length-1].draw();dots[dots.length-1].link();
}
//setInterval(drawIfMouseMoving, 17);function degToRad(deg) {return deg * (Math.PI / 180);
}
</script></body>
</html>

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述


http://www.mrgr.cn/p/32564274

相关文章

翻译: 什么是ChatGPT 通过图形化的方式来理解 Transformer 架构 深度学习二

合集 ChatGPT 通过图形化的方式来理解 Transformer 架构 翻译: 什么是ChatGPT 通过图形化的方式来理解 Transformer 架构 深度学习一翻译: 什么是ChatGPT 通过图形化的方式来理解 Transformer 架构 深度学习二翻译: 什么是ChatGPT 通过图形化的方式来理解 Transformer 架构 深…

《最新出炉》系列入门篇-Python+Playwright自动化测试-44-鼠标操作-上篇

1.简介 前边文章中已经讲解过鼠标的拖拽操作,今天宏哥在这里对其的其他操作进行一个详细地介绍和讲解,然后对其中的一些比较常见的、重要的操作单独拿出来进行详细的介绍和讲解。 2.鼠标操作语法 鼠标操作介绍官方API的文档地址:https://playwright.dev/docs/api/class-mous…

windows下使用命令行查看已存储的wifi密码

netsh wlan show interface查看当前已连接wifi信息 netsh wlan show profiles查看所有已保存的wifi配置文件 netsh wlan show profiles name="XXXXXX" key="Clear"查看特定配置文件详情,包括wifi密码,密码在“关键内容”行

springboot lua检查redis库存

需求 最近需求需要实现检查多个马戏场次下的座位等席对应库存渠道的库存余量&#xff0c;考虑到性能&#xff0c;决定采用Lua脚本实现库存检查。 数据结构 库存层级结构 redis库存hash类型结构 实现 lua脚本 --- 字符串分割为数组 local function split(str, char)local…

JAVA IO/NIO 知识点总结

一、常见 IO 模型简介 1. 阻塞IO模型 最传统的一种IO模型&#xff0c;即在读写数据过程中会发生阻塞现象。当用户线程发出IO请求之后&#xff0c;内核会去查看数据是否就绪&#xff0c;如果没有就绪就会等待数据就绪&#xff0c;而用户线程就会处于阻塞状态&#xff0c;用户线…

和comate一起,用JavaScript实现一个简易版五子棋小游戏

前言 五子棋起源于中国&#xff0c;是全国智力运动会竞技项目之一&#xff0c;是一种两人对弈的纯策略型棋类游戏。双方分别使用黑白两色的棋子&#xff0c;下在棋盘直线与横线的交叉点上&#xff0c;先形成五子连珠者获胜。 这次和Baidu Comate智能代码助手共同完成这个小游戏…

9.3.k8s的控制器资源(deployment部署控制器)

目录 一、deployment部署控制器概念 二、deployment资源的清单编写 三、小结 功能 使用场景 原理 四、deployment实现升级和回滚 1.编辑deployment资源清单&#xff08;v1版本&#xff09; 2.创建service资源用于访问 ​编辑 3.修改deploy清单中pod镜像版本为V2 4…

如何分析慢SQL语句

如果一条sql执行很慢的话,通常会使用MySQL自动的执行计划explain来去查看这条sql的执行情况,比如在这里面可以通过key和key_len检查是否命中了索引,如果本身已经添加了索引,也可以判断索引是否有失效的情况,第二个,可以通过type字段查看sql是否有进一步的优化空间,是否存…

sonarqube(一)安装

一、前置条件: 安装工具如下:JDK MySql服务器 SonarQube SonarScanner二、下载和安装 1.jdk和mysql和sonar有版本对应的要求,sonar7.5对应jdk1.8和mysql>=5.6,<8.0 下载地址:http://www.sonarqube.org/downloads/ 下载完成后解压后点击StartSonar.bat启动即可。 或者…

shell翻译官

shell脚本概述 shell的作用&#xff1a; 完成自动化运维工作&#xff0c;批量完成重复操作&#xff0c;结合crontab完成周期性任务 shell编程规范&#xff1a; Shell脚本的编写 vim XXX.sh 1.申明解释器 #!/bin/bash #!/bin/python 2.编写注释信息 要以 # 号开…

Verilog中4位数值比较器电路

某4位数值比较器的功能表如下。 请用Verilog语言采用门级描述方式&#xff0c;实现此4位数值比较器 参考代码如下&#xff1a; &#xff08;CSDN代码块不支持Verilog&#xff0c;代码复制到notepad编辑器中&#xff0c;语言选择Verilog&#xff0c;看得更清楚&#xff09; t…

项目计划书(Word原件)

项目开发计划包括项目描述、项目组织、成本预算、人力资源估算、设备资源计划、沟通计划、采购计划、风险计划、项目过程定义及项目的进度安排和里程碑、质量计划、数据管理计划、度量和分析计划、监控计划和培训计划等。 软件资料清单列表部分文档&#xff1a; 工作安排任务书…

《Python编程从入门到实践》day21

# 昨日知识点回顾 设置背景颜色 在屏幕中央绘制飞船 # 今日知识点学习 12.5 重构&#xff1a;方法_check_events()和_update_screen() 12.5.1 方法_check_events() import sys import pygame from Settings import Settings from Ship import Shipclass AlienInvasion:"…

java的三种编译(JAVAC,JIT,AOT)

1.javac把java代码编译成字节码(中间代码),然后由java虚拟机解释执行 2.jit(运行时编译)把java代码直接编译成机器码,然后由java虚拟机直接运行(缓存)。有对客户端的C1和对服务器端的C2编译器 缓存 代码优化 逃逸分析,是否超出范围。对不同逃逸状态做优化 全局逃逸 对象超…

怎么设置一天多个时间点的闹钟提醒?

在日常生活中,我们经常需要在一天的不同时间点完成特定的任务,如定时喝水、定时查看后台数据、定时吃药等。这时候,如果能有一款软件,可以在一条日程里轻松设置多个时间点的闹钟提醒,那将大大提高我们的工作效率和生活品质。 那么怎么设置一天多个时间点的闹钟提醒呢?定时…

sql优化思路

sql的优化经验 这里解释一下SQL语句的优化的原理 1.指明字段名称&#xff0c;可以尽量使用覆盖索引&#xff0c;避免回表查询&#xff0c;因此可以提高效率 2.字面意思&#xff0c;无需过多赘述。索引就是为了提高查询效率的。 3.图中两条sql直接可以使用union all 或者 uni…

智慧工地,筑牢安全防线:严防塔吊相撞,守护施工安全之巅!

塔吊相撞的事故是一个严重的施工安全问题&#xff0c;而智慧工地则是一种利用现代科技手段提高施工安全性的解决方案。 为了避免类似事故的发生&#xff0c;智慧工地可以采取以下措施&#xff1a; 一、建立全面的监控系统 智慧工地可以建立完善的监控系统&#xff0c;通过安装…

GreatSQL的sp中添加新的sp_instr引入的bug解析

GreatSQL的sp中添加新的sp_instr引入的bug解析 一、问题发现 在一次开发中用到的sp需要添加新的sp_instr以满足需求,但是添加了数个sp_instr以后发现执行新的sp会发生core。注:本次使用的GreatSQL 8.0.32-251、sp_head.cc的init_sp_psi_keys()代码里面添加10个新的sp_instr:…

使用脚本一键部署项目的示例(脚本会创建syetemctl的系统服务)

文章目录 说明使用脚本一键部署本项目开启/停止服务开启/关闭开机自动运行更新项目 参考地址&#xff1a;https://github.com/Evil0ctal/Douyin_TikTok_Download_API?tabreadme-ov-file 说明 后续相关项目可以使用这种方式创建脚本&#xff0c;脚本均放置在项目根目录下的bas…

对于习惯使用ftp传输的企业,如何寻找最佳的替代方案?

FTP协议广泛应用各行业的文件传输场景中,对于很多企业而言,由于FTP传输应用获取门槛低、使用普遍,因此,有较为稳定的FTP使用习惯,但即便如此,也不得不面对,FTP应用存在着严重缺陷: 传输效率问题:FTP协议作为最早的互联网文件传输协议,虽然解决了传输协议有无的问题,…