html--宠物

文章目录

  • html
  • js
  • css

html

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>CodePen - Spaceworm</title>
  <script>
window.requestAnimFrame = (function() {
  return (
    window.requestAnimationFrame ||
    window.webkitRequestAnimationFrame ||
    window.mozRequestAnimationFrame ||
    window.oRequestAnimationFrame ||
    window.msRequestAnimationFrame ||
    function(callback) {
      window.setTimeout(callback);
    }
  );
});

function init(elemid) {
  let canvas = document.getElementById(elemid),
    c = canvas.getContext("2d"),
    w = (canvas.width = window.innerWidth),
    h = (canvas.height = window.innerHeight);
  c.fillStyle = "rgba(30,30,30,1)";
  c.fillRect(0, 0, w, h);
  return {c:c,canvas:canvas};
}
</script>

<link rel="stylesheet" href="css/style.css">

</head>
<body>

<canvas id="canvas"></canvas>

<script src="js/script.js"></script>

</body>
</html>

js

window.onload = function () {
  //functions definition

  //class definition
  class segm {
    constructor(x, y, l) {
      this.b = Math.random()*1.9+0.1;
      this.x0 = x;
      this.y0 = y;
      this.a = Math.random() * 2 * Math.PI;
      this.x1 = this.x0 + l * Math.cos(this.a);
      this.y1 = this.y0 + l * Math.sin(this.a);
      this.l = l;
    }
    update(x, y) {
      this.x0 = x;
      this.y0 = y;
      this.a = Math.atan2(this.y1 - this.y0, this.x1 - this.x0);
      this.x1 = this.x0 + this.l * Math.cos(this.a);
      this.y1 = this.y0 + this.l * Math.sin(this.a);
    }
  }
  class rope {
    constructor(tx, ty, l, b, slq) {
      this.res = l / slq;
      this.l = l;
      this.segm = [];
      this.segm.push(new segm(tx, ty, this.l / this.res));
      for (let i = 1; i < this.res; i++) {
        this.segm.push(
          new segm(this.segm[i - 1].x1, this.segm[i - 1].y1, this.l / this.res)
        );
      }
      this.b = b;
    }
    update(t) {
      this.segm[0].update(t.x, t.y);
      for (let i = 1; i < this.res; i++) {
        this.segm[i].update(this.segm[i - 1].x1, this.segm[i - 1].y1);
      }
    }
    show(t) {
      if(t == "l"){
      c.beginPath();
      for (let i = 0; i < this.segm.length; i++) {
        c.lineTo(this.segm[i].x0, this.segm[i].y0);
      }
      c.lineTo(
        this.segm[this.segm.length - 1].x1,
        this.segm[this.segm.length - 1].y1
      );
      c.strokeStyle = "white";
      c.lineWidth = this.b;
      c.stroke();

      c.beginPath();
      c.arc(this.segm[0].x0, this.segm[0].y0, 1, 0, 2 * Math.PI);
      c.fillStyle = "white";
      c.fill();

      c.beginPath();
      c.arc(
        this.segm[this.segm.length - 1].x1,
        this.segm[this.segm.length - 1].y1,
        2,
        0,
        2 * Math.PI
      );
      c.fillStyle = "white";
      c.fill();
      }else{
      for (let i = 0; i < this.segm.length; i++) {
        c.beginPath();
        c.arc(this.segm[i].x0, this.segm[i].y0, this.segm[i].b, 0, 2*Math.PI);
        c.fillStyle = "white";
      c.fill();
      }
        c.beginPath();
      c.arc(
        this.segm[this.segm.length - 1].x1,
        this.segm[this.segm.length - 1].y1,
        2, 0, 2*Math.PI
      );
      c.fillStyle = "white";
      c.fill();
      }
    }
  }

  //setting up canvas
  let c = init("canvas").c,
    canvas = init("canvas").canvas,
    w = (canvas.width = window.innerWidth),
    h = (canvas.height = window.innerHeight),
    ropes = [];

  //variables definition
  let nameOfVariable = "value",
    mouse = {},
    last_mouse = {},
    rl = 50,
    randl = [],
    target = { x: w/2, y: h/2 },
    last_target = {},
    t = 0,
    q = 10,
    da = [],
    type = "l";

  for (let i = 0; i < 100; i++) {
    ropes.push(
      new rope(
        w / 2,
        h / 2,
        (Math.random() * 1 + 0.5) * 500,
        Math.random() * 0.4 + 0.1,
        Math.random()*15+5
      )
    );
    randl.push(Math.random() * 2 - 1);
    da.push(0);
  }

  //place for objects in animation
  function draw() {
    
    if (mouse.x) {
      target.errx = mouse.x - target.x;
      target.erry = mouse.y - target.y;
    } else {
      target.errx =
        w / 2 +
        (h / 2 - q) *
          Math.sqrt(2) *
          Math.cos(t) /
          (Math.pow(Math.sin(t), 2) + 1) -
        target.x;
      target.erry =
        h / 2 +
        (h / 2 - q) *
          Math.sqrt(2) *
          Math.cos(t) *
          Math.sin(t) /
          (Math.pow(Math.sin(t), 2) + 1) -
        target.y;
    }

    target.x += target.errx / 10;
    target.y += target.erry / 10;

    t += 0.01;
    
    for (let i = 0; i < ropes.length; i++) {
      if (randl[i] > 0) {
        da[i] += (1 - randl[i]) / 10;
      } else {
        da[i] += (-1 - randl[i]) / 10;
      }
      ropes[i].update({
        x:
          target.x +
          randl[i] * rl * Math.cos((i * 2 * Math.PI) / ropes.length + da[i]),
        y:
          target.y +
          randl[i] * rl * Math.sin((i * 2 * Math.PI) / ropes.length + da[i])
      });
      if(randl[i] > -0.5){
        type = "l";
      }else{
        type = "o";
      }
      ropes[i].show(type);
    }
    last_target.x = target.x;
    last_target.y = target.y;
  }

  //mouse position
  canvas.addEventListener(
    "mousemove",
    function (e) {
      last_mouse.x = mouse.x;
      last_mouse.y = mouse.y;

      mouse.x = e.pageX - this.offsetLeft;
      mouse.y = e.pageY - this.offsetTop;
    },
    false
  );
  
  canvas.addEventListener("mouseleave", function(e) {
    mouse.x = false;
    mouse.y = false;
  });

  //animation frame
  function loop() {
    window.requestAnimFrame(loop);
    c.clearRect(0, 0, w, h);
    draw();
  }

  //window resize
  window.addEventListener("resize", function () {
    (w = canvas.width = window.innerWidth),
      (h = canvas.height = window.innerHeight);
    loop();
  });

  //animation runner
  loop();
  setInterval(loop, 1000 / 60);
};

css

body,
html {
  margin: 0px;
  padding: 0px;
  position: fixed;
  background: rgb(30, 30, 30);
  cursor: none;
}

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/457690.html

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

相关文章

简单的思考(一):MATLAB实现心形线

今天刷B站的时候看见了&#xff1a; 于是想着自己能不能也做出来 clc;clear; % 定义x的范围 x -2:0.01:2;% 初始化图形 figure; set(gcf,position,[0,0,800,600],color,w); h1 plot(x,abs(x).^(2/3) (0.9*sqrt((3.3-x.^2))).*sin(0.1*pi*x),r,LineWidth,3); hold on xlim(…

HAProxy——高性能负载均衡器

目录 一.常见的Web集群调度器 二.HAProxy基本介绍 1.HAProxy是什么&#xff1f; 2.HAProxy的特性 3.HAProxy常用的8种负载均衡调度算法 3.1 轮询&#xff1a;RR&#xff08;Round Robin&#xff09; 3.2 最小连接数&#xff1a;LC&#xff08;Least Connections&#xff…

基于JAVA的教务系统小程序的设计与实现【附项目源码】分享

基于JAVA的教务系统小程序的设计与实现: 源码地址&#xff1a;https://download.csdn.net/download/qq_41810183/88842782 一、引言 随着信息技术的不断发展&#xff0c;教务管理工作逐渐走向数字化、智能化。为了提高教务管理效率&#xff0c;方便师生查询教务信息&#xff…

ChatGPT 插件Plugin集合

ChatGPT的插件功能推出一段时间了&#xff0c;陆陆续续的上架了得有200了。 但是其中大部分都不是很好用&#xff0c;并且找起来也复杂。 推荐一个不知名热心人做的导航页。 ChatGPT Plugins Overview 基本上集合了所有的插件&#xff0c;并且还在实时更新中。 需要升级4.0&a…

机器学习 Python库 乱记录

MLFlow—模型实验和跟踪 MLflow是一个平台&#xff0c;帮助你从头到尾管理你的机器学习实验&#xff0c;确保可追溯性和可重复性。它提供了一个集中的存储库&#xff0c;用于存储你的代码、数据和模型工件&#xff0c;以及一个跟踪系统&#xff0c;记录你所有的实验&#xff0c…

前端实现文件预览(pdf、excel、word、图片)

需求&#xff1a;实现一个在线预览pdf、excel、word、图片等文件的功能。 介绍&#xff1a;支持pdf、xlsx、docx、jpg、png、jpeg。 以下使用Vue3代码实现所有功能&#xff0c;建议以下的预览文件标签可以在外层包裹一层弹窗。 图片预览 iframe标签能够将另一个HTML页面嵌入到…

openGauss学习笔记-242 openGauss性能调优-SQL调优-典型SQL调优点-SQL自诊断

文章目录 openGauss学习笔记-242 openGauss性能调优-SQL调优-典型SQL调优点-SQL自诊断242.1 SQL自诊断242.1.1 告警场景242.1.2 规格约束 openGauss学习笔记-242 openGauss性能调优-SQL调优-典型SQL调优点-SQL自诊断 SQL调优是一个不断分析与尝试的过程&#xff1a;试跑Query&…

操作系统(AndroidIOS)图像绘图的基本原理

屏幕显示图像的过程 我们知道&#xff0c;屏幕是由一个个物理显示单元组成&#xff0c;每一个单元我们可以称之为一个物理像素点&#xff0c;而每一个像素点可以发出多种颜色。 而图像&#xff0c;就是在不同的物理像素点上显示不同的颜色构成的。 像素点的颜色 像素的颜色是…

HTML5、CSS3面试题(二)

上一章:HTML5、CSS3面试题&#xff08;一&#xff09; 哪些是块级元素那些是行内元素&#xff0c;各有什么特点 &#xff1f;&#xff08;必会&#xff09; 行内元素: a、span、b、img、strong、input、select、lable、em、button、textarea 、selecting 块级元素&#xff1…

一文解决Word中公式插入问题(全免费/latex公式输入/texsWord)

分文不花&#xff0c;搞定你的word公式输入/texsWord完全使用指南 背景 碎碎念&#xff1a;折折腾腾至少装了几个小时&#xff0c;遇到了若干大坑。遇到的问题网上都搜索不到答案&#xff01;&#xff01;&#xff01;就让我来当指路的小火柴吧。 本篇适用于在word中输入la…

使用Python进行自然语言处理(NLP):NLTK与Spacy的比较【第133篇—NLTK与Spacy】

使用Python进行自然语言处理&#xff08;NLP&#xff09;&#xff1a;NLTK与Spacy的比较 自然语言处理&#xff08;NLP&#xff09;是人工智能领域的一个重要分支&#xff0c;它涉及到计算机如何理解、解释和生成人类语言。在Python中&#xff0c;有许多库可以用于NLP任务&…

【设计模式】二、UML 类图与面向对象设计原则 之 UML概述

二、UML 类图与面向对象设计原则 &#xff08;一&#xff09;UML 类图 UML 概述类与类的UML图示类之间的关系 &#xff08;二&#xff09;面向对象设计原则 单一职责原则&#xff08;Single Responsibility Principle, SRP&#xff09;开闭原则&#xff08;Open-Closed Princip…

x86_64架构栈帧以及帧指针FP

文章目录 一、x86_64架构寄存器简介二、x86_64架构帧指针FP三、示例四、保存帧指针参考资料 一、x86_64架构寄存器简介 在x86架构中&#xff0c;有8个通用寄存器可用&#xff1a;eax、ebx、ecx、edx、ebp、esp、esi和edi。在x86_64&#xff08;x64&#xff09;扩展中&#xff…

基于检索增强的 GPT-3.5 的文本到 SQL 框架,具有样本感知提示和动态修订链。

文章目录 一、论文关键信息二、基础概念三、主要内容1. Motivations2. Insights3. 解决方案的关键4. 实验 四、总结与讨论 &#x1f349; CSDN 叶庭云&#xff1a;https://yetingyun.blog.csdn.net/ 一、论文关键信息 论文标题&#xff1a;Retrieval-augmented GPT-3.5-based T…

港大提出图结构大语言模型:GraphGPT

1. 引言 图神经网络&#xff08;Graph Neural Networks&#xff09;已经成为分析和学习图结构数据的强大框架&#xff0c;推动了社交网络分析、推荐系统和生物网络分析等多个领域的进步。图神经网络的主要优势在于它们能够捕获图数据中固有的结构信息和依赖关系。利用消息传递…

Selenium 自动化 —— 入门和 Hello World 实例

Selenium 是什么 Selenium 是一个用于自动化网页浏览器操作的工具&#xff0c;它支持多种浏览器和多种操作系统。主要用于测试 web 应用程序的功能&#xff0c;也可用于执行一些基本的浏览器操作任务&#xff0c;例如自动化表单填写、网页导航等。 Selenium 是一个开源项目&a…

大米自动化生产线的运作原理与科技创新

在当今科技飞速发展的时代&#xff0c;自动化生产线已经成为各个行业提高效率、降低成本的重要工具。而在粮食产业中&#xff0c;大米的自动化生产线更是以其独特的魅力&#xff0c;引领着粮食加工业的转型升级。星派将带您深入了解大米自动化生产线的运作原理&#xff0c;以及…

Docker 安装部署MySQL教程

前言 Docker安装MySQL镜像以及启动容器&#xff0c;大致都是三步&#xff1a;查询镜像–>拉取镜像–>启动容器 1、查询镜像 docker search mysql2、拉取镜像 拉取镜像时选择stars值较高的 docker pull mysql:5.7 #这里指定拉取对应的版本Mysql5.7&#xff0c;没有指…

【新手】在idea中配置tomcat服务器,并部署一个项目

目录 第一步&#xff1a;新建java项目第二步&#xff1a;新建完成后&#xff0c;按照步骤选择添加框架支持第三步&#xff1a;点击添加配置第四步&#xff1a;在web文件包下创建一个新的jsp第五步&#xff1a;在新建的jsp里编写java或者html 前言&#xff1a;本章学习的是在ide…

Ubuntu虚拟机的IP总频繁变化,导致Xshell断开连接

文章目录 一、IP变化的原因二、解决方法&#xff1a;固定IP三、参考文章 一、IP变化的原因 1.DHCP协议 虚拟机系统(Ubuntu、CentOS、UOS等Linux系统)启动后&#xff0c;加入本地局域网网络时&#xff0c;会向本地网络申请租约一个IP地址&#xff0c;租约时长不定。我这里租约时…
最新文章