开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 0

青羽/code-base

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
main
分支 (1)
main
main
分支 (1)
main
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
main
分支 (1)
main
code-base
/
JavaScript
/
draw_heart.html
code-base
/
JavaScript
/
draw_heart.html
draw_heart.html 5.36 KB
一键复制 编辑 原始数据 按行查看 历史
青羽 提交于 2025年11月16日 23:05 +08:00 . [JavaScript] upgrade draw_heart: 鼠标交互
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Heart</title>
<style>
body {
margin: 0;
overflow: hidden;
background-color: #1a001a;
}
canvas {
display: block;
}
</style>
</head>
<body>
<canvas id="heartCanvas"></canvas>
<script>
const canvas = document.getElementById("heartCanvas");
const ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const BG_COLOR = "#1a001a";
const PARTICLE_COUNT = 600;
const HEART_SCALE = 20;
const ANIMATION_DURATION = 360; // Number of frames
const COLORS = [
"#ffc0cb",
"#ff69b4",
"#db7093",
"#e6e6fa",
"#dda0dd",
"#ffffff",
];
class Particle {
constructor() {
const t = Math.random() * 2 * Math.PI;
this.targetX = HEART_SCALE * (16 * Math.pow(Math.sin(t), 3));
this.targetY =
HEART_SCALE *
(13 * Math.cos(t) -
5 * Math.cos(2 * t) -
2 * Math.cos(3 * t) -
Math.cos(4 * t));
// Center the heart
this.targetX += canvas.width / 2;
this.targetY = -this.targetY + canvas.height / 2; // Y is inverted in canvas
this.startX = Math.random() * canvas.width;
this.startY = Math.random() * canvas.height;
this.x = this.startX;
this.y = this.startY;
this.dx = (this.targetX - this.startX) / ANIMATION_DURATION;
this.dy = (this.targetY - this.startY) / ANIMATION_DURATION;
this.vx = 0;
this.vy = 0;
this.size = Math.random() * 2 + 1;
this.color = COLORS[Math.floor(Math.random() * COLORS.length)];
}
update(mouseX, mouseY) {
if (frame < ANIMATION_DURATION) {
// Initial formation animation
this.x += this.dx;
this.y += this.dy;
} else {
// Move towards target position
const dxTarget = this.targetX - this.x;
const dyTarget = this.targetY - this.y;
const distanceTarget = Math.sqrt(
dxTarget * dxTarget + dyTarget * dyTarget
);
// Apply a force to return to the target
if (distanceTarget > 0.1) {
this.vx += dxTarget * 0.001;
this.vy += dyTarget * 0.001;
}
// Repulsion from mouse
const dxMouse = this.x - mouseX;
const dyMouse = this.y - mouseY;
const distanceMouse = Math.sqrt(
dxMouse * dxMouse + dyMouse * dyMouse
);
const repulsionRadius = 60;
if (distanceMouse < repulsionRadius) {
const force = (repulsionRadius - distanceMouse) / repulsionRadius;
this.vx += (dxMouse / distanceMouse) * force * 0.5;
this.vy += (dyMouse / distanceMouse) * force * 0.5;
}
// Apply friction/damping
this.vx *= 0.95;
this.vy *= 0.95;
// Update position
this.x += this.vx;
this.y += this.vy;
}
}
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
ctx.fillStyle = this.color;
ctx.fill();
}
}
const particles = [];
for (let i = 0; i < PARTICLE_COUNT; i++) {
particles.push(new Particle());
}
let frame = 0;
let mouseX = -1000;
let mouseY = -1000;
function animate() {
ctx.fillStyle = BG_COLOR;
ctx.fillRect(0, 0, canvas.width, canvas.height);
particles.forEach((p) => {
p.update(mouseX, mouseY);
p.draw();
});
if (frame < ANIMATION_DURATION) {
frame++;
} else {
// Final draw is now part of the continuous loop
// Add text when animation is "done"
ctx.fillStyle = "white";
ctx.font = "italic 16px Arial";
ctx.textAlign = "center";
ctx.fillText(
"Made with Love",
canvas.width / 2,
canvas.height / 2 - 10
);
ctx.fillText(
"For TQW, My Dear",
canvas.width / 2,
canvas.height / 2 + 10
);
}
requestAnimationFrame(animate);
}
animate();
window.addEventListener("mousemove", (e) => {
mouseX = e.clientX;
mouseY = e.clientY;
});
window.addEventListener("mouseout", () => {
mouseX = -1000;
mouseY = -1000;
});
window.addEventListener("resize", () => {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
// Re-center particles on resize
particles.forEach((p) => {
const t = Math.random() * 2 * Math.PI;
p.targetX = HEART_SCALE * (16 * Math.pow(Math.sin(t), 3));
p.targetY =
HEART_SCALE *
(13 * Math.cos(t) -
5 * Math.cos(2 * t) -
2 * Math.cos(3 * t) -
Math.cos(4 * t));
p.targetX += canvas.width / 2;
p.targetY = -p.targetY + canvas.height / 2;
});
});
</script>
</body>
</html>
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

Some code of mine.
暂无标签
MIT
使用 MIT 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chobity/code-base.git
git@gitee.com:chobity/code-base.git
chobity
code-base
code-base
main
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /