• 炫酷爱心表白


    一、代码

    1. html>
    2. <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    3. <title>💗 Love you 💗title>
    4. <style type="text/css">
    5. body {
    6. margin: 0;
    7. overflow: hidden;
    8. background: #000;
    9. }
    10. canvas {
    11. position: absolute;
    12. width: 100%;
    13. height: 100%;
    14. }
    15. #pinkboard {
    16. animation: anim 1.5s ease-in-out infinite;
    17. -webkit-animation: anim 1.5s ease-in-out infinite;
    18. -o-animation: anim 1.5s ease-in-out infinite;
    19. -moz-animation: anim 1.5s ease-in-out infinite;
    20. }
    21. @keyframes anim {
    22. 0% {
    23. transform: scale(0.8);
    24. }
    25. 25% {
    26. transform: scale(0.7);
    27. }
    28. 50% {
    29. transform: scale(1);
    30. }
    31. 75% {
    32. transform: scale(0.7);
    33. }
    34. 100% {
    35. transform: scale(0.8);
    36. }
    37. }
    38. @-webkit-keyframes anim {
    39. 0% {
    40. -webkit-transform: scale(0.8);
    41. }
    42. 25% {
    43. -webkit-transform: scale(0.7);
    44. }
    45. 50% {
    46. -webkit-transform: scale(1);
    47. }
    48. 75% {
    49. -webkit-transform: scale(0.7);
    50. }
    51. 100% {
    52. -webkit-transform: scale(0.8);
    53. }
    54. }
    55. @-o-keyframes anim {
    56. 0% {
    57. -o-transform: scale(0.8);
    58. }
    59. 25% {
    60. -o-transform: scale(0.7);
    61. }
    62. 50% {
    63. -o-transform: scale(1);
    64. }
    65. 75% {
    66. -o-transform: scale(0.7);
    67. }
    68. 100% {
    69. -o-transform: scale(0.8);
    70. }
    71. }
    72. @-moz-keyframes anim {
    73. 0% {
    74. -moz-transform: scale(0.8);
    75. }
    76. 25% {
    77. -moz-transform: scale(0.7);
    78. }
    79. 50% {
    80. -moz-transform: scale(1);
    81. }
    82. 75% {
    83. -moz-transform: scale(0.7);
    84. }
    85. 100% {
    86. -moz-transform: scale(0.8);
    87. }
    88. }
    89. #name {
    90. position: absolute;
    91. top: 50%;
    92. left: 50%;
    93. transform: translate(-50%, -50%);
    94. margin-top: -20px;
    95. font-size: 46px;
    96. color: #ea80b0;
    97. }
    98. style>
    99. <script src="./💗 Love you 💗_files/monitors.3.6.36.cn.js.下载" async="" crossorigin="anonymous">script><script src="./💗 Love you 💗_files/sentry.3.6.36.cn.js.下载" async="" crossorigin="anonymous">script>head>
    100. <body>
    101. <canvas id="pinkboard" width="1707" height="868">canvas>
    102. <canvas id="canvas" width="1707" height="868">canvas>
    103. <script type="text/javascript">
    104. const colors = [
    105. "#eec996",
    106. "#8fb7d3",
    107. "#b7d4c6",
    108. "#c3bedd",
    109. "#f1d5e4",
    110. "#cae1d3",
    111. "#f3c89d",
    112. "#d0b0c3",
    113. "#819d53",
    114. "#c99294",
    115. "#cec884",
    116. "#ff8e70",
    117. "#e0a111",
    118. "#fffdf6",
    119. "#cbd7ac",
    120. "#e8c6c0",
    121. "#dc9898",
    122. "#ecc8ba",
    123. ]; //用来设置的颜色
    124. var canvas = document.getElementById("canvas");
    125. var ctx = canvas.getContext("2d");
    126. let count = 1;
    127. var ww = window.innerWidth;
    128. var wh = window.innerHeight;
    129. var hearts = [];
    130. function init() {
    131. requestAnimationFrame(render);
    132. canvas.width = ww;
    133. canvas.height = wh;
    134. for (var i = 0; i < 100; i++) {
    135. hearts.push(new Heart());
    136. }
    137. }
    138. function Heart() {
    139. this.x = Math.random() * ww;
    140. this.y = Math.random() * wh;
    141. this.opacity = Math.random() * 0.5 + 0.5;
    142. this.vel = {
    143. x: (Math.random() - 0.5) * 4,
    144. y: (Math.random() - 0.5) * 4,
    145. };
    146. this.targetScale = Math.random() * 0.15 + 0.02;
    147. this.scale = this.targetScale * Math.random();
    148. }
    149. Heart.prototype.update = function (i) {
    150. this.x += this.vel.x;
    151. this.y += this.vel.y;
    152. this.scale += (this.targetScale - this.scale) * 0.01;
    153. if (this.x - this.width > ww || this.x + this.width < 0) {
    154. this.scale = 0;
    155. this.x = Math.random() * ww;
    156. }
    157. if (this.y - this.height > wh || this.y + this.height < 0) {
    158. this.scale = 0;
    159. this.y = Math.random() * wh;
    160. }
    161. this.width = 473.8;
    162. this.height = 408.6;
    163. };
    164. Heart.prototype.draw = function (i) {
    165. ctx.globalAlpha = this.opacity;
    166. ctx.font = `${180 * this.scale}px "微软雅黑"`;
    167. // ctx.font="20px";
    168. ctx.fillStyle = colors[i % 18];
    169. ctx.fillText(
    170. "kawsar",
    171. this.x - this.width * 0.5,
    172. this.y - this.height * 0.5,
    173. this.width,
    174. this.height
    175. );
    176. // ctx.drawImage(
    177. // heartImage,
    178. // this.x - this.width * 0.5,
    179. // this.y - this.height * 0.5,
    180. // this.width,
    181. // this.height
    182. // );
    183. };
    184. function render() {
    185. ctx.clearRect(0, 0, ww, wh);
    186. // ctx.globalAlpha = 1;
    187. // ctx.fillStyle = "rgba(255,255,255,0.3)";
    188. // ctx.fillRect(0, 0, ww, wh);
    189. for (var i = 0; i < 100; i++) {
    190. hearts[i].update(i);
    191. hearts[i].draw(i);
    192. }
    193. requestAnimationFrame(render);
    194. }
    195. init();
    196. // var heartImage = new Image();
    197. // heartImage.onload = init();
    198. // heartImage.src =
    199. // "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0NzMuOHB4IiBoZWlnaHQ9IjQwOC42cHgiIHZpZXdCb3g9IjAgMCA0NzMuOCA0MDguNiI+PHBhdGggZmlsbD0iI2QzMjkzMiIgZD0iTTQwNC42LDE2LjZDMzg1LjQsNi4xLDM2My41LDAsMzQwLDBjLTQxLjUsMC03OC41LDE4LjktMTAzLDQ4LjVDMjEyLjMsMTguOSwxNzUuMywwLDEzMy44LDAgYy0yMy4zLDAtNDUuMyw2LjEtNjQuNSwxNi42QzI3LjksMzkuNSwwLDgzLjQsMCwxMzMuOWMwLDE0LjQsMi40LDI4LjMsNi42LDQxLjJDMjkuNiwyNzguNCwyMzcsNDA4LjYsMjM3LDQwOC42IHMyMDcuMi0xMzAuMiwyMzAuMi0yMzMuNWM0LjMtMTIuOSw2LjYtMjYuOCw2LjYtNDEuMkM0NzMuOCw4My40LDQ0NS45LDM5LjYsNDA0LjYsMTYuNnoiLz48L3N2Zz4=";
    200. window.addEventListener("resize", function () {
    201. ww = window.innerWidth;
    202. wh = window.innerHeight;
    203. });
    204. script>
    205. <script>
    206. /*
    207. * Settings
    208. */
    209. var settings = {
    210. particles: {
    211. length: 500, // maximum amount of particles
    212. duration: 2, // particle duration in sec
    213. velocity: 100, // particle velocity in pixels/sec
    214. effect: -0.75, // play with this for a nice effect
    215. size: 30, // particle size in pixels
    216. },
    217. };
    218. /*
    219. * RequestAnimationFrame polyfill by Erik M?ller
    220. */
    221. (function () {
    222. var b = 0;
    223. var c = ["ms", "moz", "webkit", "o"];
    224. for (var a = 0; a < c.length && !window.requestAnimationFrame; ++a) {
    225. window.requestAnimationFrame = window[c[a] + "RequestAnimationFrame"];
    226. window.cancelAnimationFrame =
    227. window[c[a] + "CancelAnimationFrame"] ||
    228. window[c[a] + "CancelRequestAnimationFrame"];
    229. }
    230. if (!window.requestAnimationFrame) {
    231. window.requestAnimationFrame = function (h, e) {
    232. var d = new Date().getTime();
    233. var f = Math.max(0, 16 - (d - b));
    234. var g = window.setTimeout(function () {
    235. h(d + f);
    236. }, f);
    237. b = d + f;
    238. return g;
    239. };
    240. }
    241. if (!window.cancelAnimationFrame) {
    242. window.cancelAnimationFrame = function (d) {
    243. clearTimeout(d);
    244. };
    245. }
    246. })();
    247. /*
    248. * Point class
    249. */
    250. var Point = (function () {
    251. function Point(x, y) {
    252. this.x = typeof x !== "undefined" ? x : 0;
    253. this.y = typeof y !== "undefined" ? y : 0;
    254. }
    255. Point.prototype.clone = function () {
    256. return new Point(this.x, this.y);
    257. };
    258. Point.prototype.length = function (length) {
    259. if (typeof length == "undefined")
    260. return Math.sqrt(this.x * this.x + this.y * this.y);
    261. this.normalize();
    262. this.x *= length;
    263. this.y *= length;
    264. return this;
    265. };
    266. Point.prototype.normalize = function () {
    267. var length = this.length();
    268. this.x /= length;
    269. this.y /= length;
    270. return this;
    271. };
    272. return Point;
    273. })();
    274. /*
    275. * Particle class
    276. */
    277. var Particle = (function () {
    278. function Particle() {
    279. this.position = new Point();
    280. this.velocity = new Point();
    281. this.acceleration = new Point();
    282. this.age = 0;
    283. }
    284. Particle.prototype.initialize = function (x, y, dx, dy) {
    285. this.position.x = x;
    286. this.position.y = y;
    287. this.velocity.x = dx;
    288. this.velocity.y = dy;
    289. this.acceleration.x = dx * settings.particles.effect;
    290. this.acceleration.y = dy * settings.particles.effect;
    291. this.age = 0;
    292. };
    293. Particle.prototype.update = function (deltaTime) {
    294. this.position.x += this.velocity.x * deltaTime;
    295. this.position.y += this.velocity.y * deltaTime;
    296. this.velocity.x += this.acceleration.x * deltaTime;
    297. this.velocity.y += this.acceleration.y * deltaTime;
    298. this.age += deltaTime;
    299. };
    300. Particle.prototype.draw = function (context, image) {
    301. function ease(t) {
    302. return --t * t * t + 1;
    303. }
    304. var size = image.width * ease(this.age / settings.particles.duration);
    305. context.globalAlpha = 1 - this.age / settings.particles.duration;
    306. context.drawImage(
    307. image,
    308. this.position.x - size / 2,
    309. this.position.y - size / 2,
    310. size,
    311. size
    312. );
    313. };
    314. return Particle;
    315. })();
    316. /*
    317. * ParticlePool class
    318. */
    319. var ParticlePool = (function () {
    320. var particles,
    321. firstActive = 0,
    322. firstFree = 0,
    323. duration = settings.particles.duration;
    324. function ParticlePool(length) {
    325. // create and populate particle pool
    326. particles = new Array(length);
    327. for (var i = 0; i < particles.length; i++)
    328. particles[i] = new Particle();
    329. }
    330. ParticlePool.prototype.add = function (x, y, dx, dy) {
    331. particles[firstFree].initialize(x, y, dx, dy);
    332. // handle circular queue
    333. firstFree++;
    334. if (firstFree == particles.length) firstFree = 0;
    335. if (firstActive == firstFree) firstActive++;
    336. if (firstActive == particles.length) firstActive = 0;
    337. };
    338. ParticlePool.prototype.update = function (deltaTime) {
    339. var i;
    340. // update active particles
    341. if (firstActive < firstFree) {
    342. for (i = firstActive; i < firstFree; i++)
    343. particles[i].update(deltaTime);
    344. }
    345. if (firstFree < firstActive) {
    346. for (i = firstActive; i < particles.length; i++)
    347. particles[i].update(deltaTime);
    348. for (i = 0; i < firstFree; i++) particles[i].update(deltaTime);
    349. }
    350. // remove inactive particles
    351. while (
    352. particles[firstActive].age >= duration &&
    353. firstActive != firstFree
    354. ) {
    355. firstActive++;
    356. if (firstActive == particles.length) firstActive = 0;
    357. }
    358. };
    359. ParticlePool.prototype.draw = function (context, image) {
    360. // draw active particles
    361. if (firstActive < firstFree) {
    362. for (i = firstActive; i < firstFree; i++)
    363. particles[i].draw(context, image);
    364. }
    365. if (firstFree < firstActive) {
    366. for (i = firstActive; i < particles.length; i++)
    367. particles[i].draw(context, image);
    368. for (i = 0; i < firstFree; i++) particles[i].draw(context, image);
    369. }
    370. };
    371. return ParticlePool;
    372. })();
    373. /*
    374. * Putting it all together
    375. */
    376. (function (canvas) {
    377. var context = canvas.getContext("2d"),
    378. particles = new ParticlePool(settings.particles.length),
    379. particleRate =
    380. settings.particles.length / settings.particles.duration, // particles/sec
    381. time;
    382. // get point on heart with -PI <= t <= PI
    383. function pointOnHeart(t) {
    384. return new Point(
    385. 160 * Math.pow(Math.sin(t), 3),
    386. 130 * Math.cos(t) -
    387. 50 * Math.cos(2 * t) -
    388. 20 * Math.cos(3 * t) -
    389. 10 * Math.cos(4 * t) +
    390. 25
    391. );
    392. }
    393. // creating the particle image using a dummy canvas
    394. var image = (function () {
    395. var canvas = document.createElement("canvas"),
    396. context = canvas.getContext("2d");
    397. canvas.width = settings.particles.size;
    398. canvas.height = settings.particles.size;
    399. // helper function to create the path
    400. function to(t) {
    401. var point = pointOnHeart(t);
    402. point.x =
    403. settings.particles.size / 2 +
    404. (point.x * settings.particles.size) / 350;
    405. point.y =
    406. settings.particles.size / 2 -
    407. (point.y * settings.particles.size) / 350;
    408. return point;
    409. }
    410. // create the path
    411. context.beginPath();
    412. var t = -Math.PI;
    413. var point = to(t);
    414. context.moveTo(point.x, point.y);
    415. while (t < Math.PI) {
    416. t += 0.01; // baby steps!
    417. point = to(t);
    418. context.lineTo(point.x, point.y);
    419. }
    420. context.closePath();
    421. // create the fill
    422. context.fillStyle = "#ea80b0";
    423. context.fill();
    424. // create the image
    425. var image = new Image();
    426. image.src = canvas.toDataURL();
    427. return image;
    428. })();
    429. // render that thing!
    430. function render() {
    431. // next animation frame
    432. requestAnimationFrame(render);
    433. // update time
    434. var newTime = new Date().getTime() / 1000,
    435. deltaTime = newTime - (time || newTime);
    436. time = newTime;
    437. // clear canvas
    438. context.clearRect(0, 0, canvas.width, canvas.height);
    439. // create new particles
    440. var amount = particleRate * deltaTime;
    441. for (var i = 0; i < amount; i++) {
    442. var pos = pointOnHeart(Math.PI - 2 * Math.PI * Math.random());
    443. var dir = pos.clone().length(settings.particles.velocity);
    444. particles.add(
    445. canvas.width / 2 + pos.x,
    446. canvas.height / 2 - pos.y,
    447. dir.x,
    448. -dir.y
    449. );
    450. }
    451. // update and draw particles
    452. particles.update(deltaTime);
    453. particles.draw(context, image);
    454. }
    455. // handle (re-)sizing of the canvas
    456. function onResize() {
    457. canvas.width = canvas.clientWidth;
    458. canvas.height = canvas.clientHeight;
    459. }
    460. window.onresize = onResize;
    461. // delay rendering bootstrap
    462. setTimeout(function () {
    463. onResize();
    464. render();
    465. }, 10);
    466. })(document.getElementById("pinkboard"));
    467. // 参考:https://blog.csdn.net/weixin_57038822/article/details/121644240
    468. script>
    469. <div id="__FEISHU_CLIPPER__">div>body>html>

    二、实现效果展示

  • 相关阅读:
    SpringCloud Alibaba微服务实战六- 服务网关
    卷积神经网络(原理与代码实现)
    《OpenDRIVE1.6规格文档》3
    使用标准IO对bitmap打马赛克
    永安通配符和泛域名SSL证书的区别
    vscode带命令行参数进行调试Golang go-admin:正确配置如下:
    LeetCode 每日一题 2024/4/15-2024/4/21
    web前端-javascript-自增++和自减--(a++和++a,都在自身基础上+1,a--和--a都在自增基础上-1,自增和自减的练习)
    4. 微服务之Nacos配置管理
    2023山东科技大学计算机考研信息汇总
  • 原文地址:https://blog.csdn.net/qq_58546982/article/details/134429718