html--互动星空

<!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.mfbz.cn/a/601855.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

CSS-背景属性

目录 背景属性 background-color (背景颜色 ) background-image (背景图片 ) background-repeat (背景图平铺方式 ) no-repeat 不平铺 repeat-x 水平方向平铺 repeat-y 垂直方向平铺 repeat 平铺 background-position (背景图位置) background-size (背景缩…

Apple 添加了 13 英寸 iPad Air

劈啪&#xff01;苹果推出的新款 iPad Air&#xff0c;将所有梦想变为现实&#xff01;它配备了强大的后置 12MP 摄像头和前置 12MP 摄像头&#xff0c;令您的拍摄体验更加出色。苹果还加入了 Apple Pencil 悬停功能&#xff0c;让您的创作更加灵活。 这款 iPad Air 不仅速度加…

antd vue pro (vue 2.x) 多页签详细操作

antd vue pro 多页签配置操作&#xff0c;具体操作如下。 1.引入 tagviews文件 在 store/modules 中创建 tagviews.js &#xff0c;复制一下代码到文件中保存 const state {visitedViews: [],cachedViews: [] }const mutations {ADD_VISITED_VIEW: (state, view) > {if …

相交链表(数据结构)

160. 相交链表 - 力扣&#xff08;LeetCode&#xff09;https://leetcode.cn/problems/intersection-of-two-linked-lists/description/ 题目 解决思路 1&#xff0c;找到相交的点 相交链表的关键也就是找到相交的点&#xff0c;所以我们需要首先判断有没有相交的节点&#…

多模态路径:利用其他模态的无关数据改进变压器(CVPR 2024)

<Multimodal Pathway: Improve Transformers with Irrelevant Data from Other Modalities> 论文地址&#xff1a;https://arxiv.org/abs/2401.14405 项目网页&#xff1a;https://ailab-cvc.github.io/M2PT/ 开源代码&#xff1a;https://github.com/AILab-CVC/M2PT 讲…

还有谁不想薅云渲染的羊毛?五种云渲染优惠知道就是省到

不管你是效果图设计师还是动画设计师&#xff0c;在面对紧急或大量的渲染任务时&#xff0c;总会有云渲染的需要。然而&#xff0c;现在的云渲染越来越贵&#xff0c;我们该如何尽可能地节约成本完成渲染任务呢&#xff1f;本文将为你介绍云渲染的五种优惠形式&#xff0c;看完…

spring bean生命周期全部过程

Spring Bean的生命周期包括以下全部过程&#xff1a; 实例化&#xff1a;在Spring容器启动时&#xff0c;根据配置文件或注解等信息创建Bean的实例。属性赋值&#xff1a;如果Bean有属性需要进行初始化&#xff0c;Spring容器会自动为这些属性进行赋值。自定义初始化方法&…

Vue.js【路由】

初识路由 提到路由&#xff08;Route&#xff09;&#xff0c;一般我们会联想到网络中常见的路由器&#xff08;Router&#xff09;&#xff0c;那么路由和路由器之间有什么关联呢&#xff1f;路由是指路由器从一个接口接收到数据&#xff0c;根据数据的目的地址将数据定向传送…

【Java笔记】多线程:一些有关中断的理解

文章目录 线程中断的作用线程的等待状态WAITINGTIMED_WAITING 线程从等待中恢复 java.lang.Thread中断实现相关方法中断标识interrupted 一些小练习Thread.interrupt() 只唤醒线程并修改中断标识sleep() 清除中断状态标识 Reference 线程中断的作用 线程中断可以使一个线程从等…

无处不在的AI:被科技巨头盯上的Agent智能体的崭新时代

&#x1f97d;一.Agent AI智能体 Agent AI 智能体是一种基于人工智能技术的智能代理&#xff0c;它可以自主地执行任务、与环境进行交互&#xff0c;并根据环境的变化做出决策。 OpenAI将AI Agent定义为以大语言模型&#xff08;LLM&#xff09;为大脑驱动具有自主理解、感知、…

关于电商API接口【满足高并发大批量请求】||电商API接口入门指南

简介&#xff1a; API&#xff08;应用程序编程接口&#xff09;是一种让不同软件之间进行通信的方式。在电子商务中&#xff0c;电商API接口可以用于获取商品信息、下单、支付等等。本篇文章将介绍电商API接口的入门知识&#xff0c;并提供示例代码以帮助你快速上手。 一、了解…

言出身随!人情世故:利益交换与人脉的重要性——早读(逆天打工人爬取热门微信文章解读)

巴黎输了&#xff0c;看了比赛还得加班 引言Python 代码第一篇 洞见 认知越高的人&#xff0c;越懂得感恩第二篇 冯站长之家 2024年5月8日&#xff08;周三&#xff09;三分钟新闻早餐结尾 智慧赋予我决策的明灯 勇气则是我行动的盾牌 在细雨中骑行 是我以智慧选择的道路 用勇气…

Foxmail邮箱API发送邮件失败的原因有哪些?

Foxmail邮箱API发送邮件的注意事项&#xff1f;如何用API发信&#xff1f; 在使用Foxmail邮箱API发送邮件时&#xff0c;有时会遇到发送失败的情况。这种情况可能由多种原因造成&#xff0c;下面AokSend就来详细探讨一下Foxmail邮箱API发送邮件失败的可能原因。 Foxmail邮箱A…

Ubuntu18.04 安装 anconda

anaconda官网 bash Anaconda3-2021.11-Linux-x86_64.sh一直回车&#xff0c;输入yes 选择安装目录 是否希望更新shell配置文件以自动初始化conda

4diacIDE同时编译不同版本踩坑记录

4diac不同版本依赖插件版本及jdk版本是不同的&#xff0c;当你需要搭建不同版本4diacIDE开发环境时&#xff0c;就会出现各种问题。最近一个月github上项目提交记录比较多&#xff0c;出现了不少坑。以下记录下此背景下的解决方法&#xff1a; 1、首先由于.target依赖的eclipse…

java项目跑不起来 端口已被使用

背景 Springboot项目跑不起来&#xff0c;原因端口被占用。 解决方法 在 Windows 环境下&#xff0c;你可以按照以下步骤来查看某个端口被占用的情况&#xff0c;并停止相应的进程&#xff1a; 查看所有端口占用情况&#xff1a; 按下 Win R 键&#xff0c;打开运行窗口。…

C语言内存函数memcpy与memmove

一.memcpy的使用和模拟实现 1.函数原型 void* memcpy(void* destination, const void* source, size_t num); destination是目标内存块的指针 source是源内存块的指针 num是要复制的字节数 .函数memcpy从source的位置开始向后复制 num个字节 的数据到destination指向的内存位置…

YOLO系列自研改进:基于注意力机制的多尺度特征提取模块

目录 一、原理 二、代码 三、在YOLO中的应用 一、原理 这个模块的原理仍然是利用不同大小的卷积核来提取不同尺度的特征,同样将通道划分为两部分,一部分通过注意力机制进行通道信息和空间信息的提取,另一部分通过多个不同大小的卷积核来提取多尺度的特征信息。 二、代码…

【Unity】使用Resources.LoadAll读取文件的顺序问题

最近在做客户的一个项目&#xff0c;其中的一个模块使用到了照片&#xff0c;但是发现了一个很严重的问题。当你在使用Unity的时候&#xff0c;它竟然不按照顺序读取&#xff1f;这个机器人是不是逻辑有问题&#xff1f;如下图&#xff1a; 名字脱敏了哈。。。 照片比较多&…

await执行顺序

用一个简单的例子来说明&#xff0c;await到底在等待什么 求代码的打印顺序 function testAsy(x) {return new Promise((resolve) > {setTimeout(() > {resolve(x);}, 3000);}); } async function testAwt() {console.log("async开始执行");// 最先打印let r…
最新文章