当前位置:   article > 正文

女神节告白代码_女神节代码html

女神节代码html

今天是女神节,送给所有女神们一句话:

爱自己是终生浪漫的开始,无论何时都要好好爱自己

目录

1. 请求动画帧填充

2.点类

3.粒子类

​编辑 4.ParticlePool 池类

5.创建和填充

6.处理循环队列

7.更新活动粒子

8.移除非活性粒子

9.绘制有源粒子 

10.整合

​编辑 11.进行样式表达

 12.使用虚拟画布创建粒子图像

13.用来创建路径的辅助器功能

14.创建路径

15.创建填充

15.创建图像

16.做出成果

17.创建新的粒子

18.更新和绘制粒子

19.重新处理画布大小

20. 延迟渲染引导

 21.全部代码


 今天我们来写表白爱心代码

首先HTML里body只要写两行代码就可以了,后面都是js代码了

我们的样式css代码如下:

首先我们先定义一个Settings

1. 请求动画帧填充

RequestAnimationFrame polyfill by Erik M?ller

2.点类

 Point class

3.粒子类

Particle class

 4.ParticlePool 池类

 ParticlePool class

5.创建和填充

create and populate particle pool 

6.处理循环队列

 handle circular queue 

7.更新活动粒子

update active particles

8.移除非活性粒子

remove inactive particles

9.绘制有源粒子 

draw active particles

10.整合

Putting it all together

 11.进行样式表达

get point on heart with -PI <= t <= PI

 12.使用虚拟画布创建粒子图像

creating the particle image using a dummy canvas

13.用来创建路径的辅助器功能

 helper function to create the path

14.创建路径

 create the path

15.创建填充

15.创建图像

16.做出成果

17.创建新的粒子

18.更新和绘制粒子

update and draw particles

19.重新处理画布大小

20. 延迟渲染引导

 delay rendering bootstrap

 21.全部代码

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. </head>
  6. <style>
  7. * {
  8. padding: 0;
  9. margin: 0;
  10. }
  11. html,
  12. body {
  13. height: 100%;
  14. padding: 0;
  15. margin: 0;
  16. background: rgb(253, 253, 253);
  17. }
  18. canvas {
  19. position: absolute;
  20. width: 100%;
  21. height: 100%;
  22. }
  23. .aa {
  24. position: fixed;
  25. left: 50%;
  26. bottom: 10px;
  27. color: #ccc;
  28. }
  29. h1{
  30. text-align: center;
  31. padding-top: 100px;
  32. }
  33. </style>
  34. <body>
  35. <h1>女神节快乐!</h1>
  36. <canvas id="pinkboard"></canvas>
  37. <script>
  38. /*
  39. * Settings
  40. */
  41. var settings = {
  42. particles: {
  43. length: 500, // maximum amount of particles
  44. duration: 2, // particle duration in sec
  45. velocity: 100, // particle velocity in pixels/sec
  46. effect: -0.75, // play with this for a nice effect
  47. size: 30 // particle size in pixels
  48. }
  49. };
  50. /*
  51. * RequestAnimationFrame polyfill by Erik M?ller
  52. */
  53. (function () {
  54. var b = 0;
  55. var c = ["ms", "moz", "webkit", "o"];
  56. for (var a = 0; a < c.length && !window.requestAnimationFrame; ++a) {
  57. window.requestAnimationFrame = window[c[a] + "RequestAnimationFrame"];
  58. window.cancelAnimationFrame =
  59. window[c[a] + "CancelAnimationFrame"] ||
  60. window[c[a] + "CancelRequestAnimationFrame"];
  61. }
  62. if (!window.requestAnimationFrame) {
  63. window.requestAnimationFrame = function (h, e) {
  64. var d = new Date().getTime();
  65. var f = Math.max(0, 16 - (d - b));
  66. var g = window.setTimeout(function () {
  67. h(d + f);
  68. }, f);
  69. b = d + f;
  70. return g;
  71. };
  72. }
  73. if (!window.cancelAnimationFrame) {
  74. window.cancelAnimationFrame = function (d) {
  75. clearTimeout(d);
  76. };
  77. }
  78. })();
  79. /*
  80. * Point class
  81. */
  82. var Point = (function () {
  83. function Point(x, y) {
  84. this.x = typeof x !== "undefined" ? x : 0;
  85. this.y = typeof y !== "undefined" ? y : 0;
  86. }
  87. Point.prototype.clone = function () {
  88. return new Point(this.x, this.y);
  89. };
  90. Point.prototype.length = function (length) {
  91. if (typeof length == "undefined")
  92. return Math.sqrt(this.x * this.x + this.y * this.y);
  93. this.normalize();
  94. this.x *= length;
  95. this.y *= length;
  96. return this;
  97. };
  98. Point.prototype.normalize = function () {
  99. var length = this.length();
  100. this.x /= length;
  101. this.y /= length;
  102. return this;
  103. };
  104. return Point;
  105. })();
  106. /*
  107. * Particle class
  108. */
  109. var Particle = (function () {
  110. function Particle() {
  111. this.position = new Point();
  112. this.velocity = new Point();
  113. this.acceleration = new Point();
  114. this.age = 0;
  115. }
  116. Particle.prototype.initialize = function (x, y, dx, dy) {
  117. this.position.x = x;
  118. this.position.y = y;
  119. this.velocity.x = dx;
  120. this.velocity.y = dy;
  121. this.acceleration.x = dx * settings.particles.effect;
  122. this.acceleration.y = dy * settings.particles.effect;
  123. this.age = 0;
  124. };
  125. Particle.prototype.update = function (deltaTime) {
  126. this.position.x += this.velocity.x * deltaTime;
  127. this.position.y += this.velocity.y * deltaTime;
  128. this.velocity.x += this.acceleration.x * deltaTime;
  129. this.velocity.y += this.acceleration.y * deltaTime;
  130. this.age += deltaTime;
  131. };
  132. Particle.prototype.draw = function (context, image) {
  133. function ease(t) {
  134. return --t * t * t + 1;
  135. }
  136. var size = image.width * ease(this.age / settings.particles.duration);
  137. context.globalAlpha = 1 - this.age / settings.particles.duration;
  138. context.drawImage(
  139. image,
  140. this.position.x - size / 2,
  141. this.position.y - size / 2,
  142. size,
  143. size
  144. );
  145. };
  146. return Particle;
  147. })();
  148. /*
  149. * ParticlePool class
  150. */
  151. var ParticlePool = (function () {
  152. var particles,
  153. firstActive = 0,
  154. firstFree = 0,
  155. duration = settings.particles.duration;
  156. function ParticlePool(length) {
  157. // create and populate particle pool
  158. particles = new Array(length);
  159. for (var i = 0; i < particles.length; i++)
  160. particles[i] = new Particle();
  161. }
  162. ParticlePool.prototype.add = function (x, y, dx, dy) {
  163. particles[firstFree].initialize(x, y, dx, dy);
  164. // handle circular queue
  165. firstFree++;
  166. if (firstFree == particles.length) firstFree = 0;
  167. if (firstActive == firstFree) firstActive++;
  168. if (firstActive == particles.length) firstActive = 0;
  169. };
  170. ParticlePool.prototype.update = function (deltaTime) {
  171. var i;
  172. // update active particles
  173. if (firstActive < firstFree) {
  174. for (i = firstActive; i < firstFree; i++)
  175. particles[i].update(deltaTime);
  176. }
  177. if (firstFree < firstActive) {
  178. for (i = firstActive; i < particles.length; i++)
  179. particles[i].update(deltaTime);
  180. for (i = 0; i < firstFree; i++) particles[i].update(deltaTime);
  181. }
  182. // remove inactive particles
  183. while (
  184. particles[firstActive].age >= duration &&
  185. firstActive != firstFree
  186. ) {
  187. firstActive++;
  188. if (firstActive == particles.length) firstActive = 0;
  189. }
  190. };
  191. ParticlePool.prototype.draw = function (context, image) {
  192. // draw active particles
  193. if (firstActive < firstFree) {
  194. for (i = firstActive; i < firstFree; i++)
  195. particles[i].draw(context, image);
  196. }
  197. if (firstFree < firstActive) {
  198. for (i = firstActive; i < particles.length; i++)
  199. particles[i].draw(context, image);
  200. for (i = 0; i < firstFree; i++) particles[i].draw(context, image);
  201. }
  202. };
  203. return ParticlePool;
  204. })();
  205. /*
  206. * Putting it all together
  207. */
  208. (function (canvas) {
  209. var context = canvas.getContext("2d"),
  210. particles = new ParticlePool(settings.particles.length),
  211. particleRate =
  212. settings.particles.length / settings.particles.duration, // particles/sec
  213. time;
  214. // get point on heart with -PI <= t <= PI
  215. function pointOnHeart(t) {
  216. return new Point(
  217. 160 * Math.pow(Math.sin(t), 3),
  218. 130 * Math.cos(t) -
  219. 50 * Math.cos(2 * t) -
  220. 20 * Math.cos(3 * t) -
  221. 10 * Math.cos(4 * t) +
  222. 25
  223. );
  224. }
  225. // creating the particle image using a dummy canvas
  226. var image = (function () {
  227. var canvas = document.createElement("canvas"),
  228. context = canvas.getContext("2d");
  229. canvas.width = settings.particles.size;
  230. canvas.height = settings.particles.size;
  231. // helper function to create the path
  232. function to(t) {
  233. var point = pointOnHeart(t);
  234. point.x =
  235. settings.particles.size / 2 +
  236. (point.x * settings.particles.size) / 350;
  237. point.y =
  238. settings.particles.size / 2 -
  239. (point.y * settings.particles.size) / 350;
  240. return point;
  241. }
  242. // create the path
  243. context.beginPath();
  244. var t = -Math.PI;
  245. var point = to(t);
  246. context.moveTo(point.x, point.y);
  247. while (t < Math.PI) {
  248. t += 0.01; // baby steps!
  249. point = to(t);
  250. context.lineTo(point.x, point.y);
  251. }
  252. context.closePath();
  253. // create the fill
  254. context.fillStyle = "red";
  255. context.fill();
  256. // create the image
  257. var image = new Image();
  258. image.src = canvas.toDataURL();
  259. return image;
  260. })();
  261. // render that thing!
  262. function render() {
  263. // next animation frame
  264. requestAnimationFrame(render);
  265. // update time
  266. var newTime = new Date().getTime() / 1000,
  267. deltaTime = newTime - (time || newTime);
  268. time = newTime;
  269. // clear canvas
  270. context.clearRect(0, 0, canvas.width, canvas.height);
  271. // create new particles
  272. var amount = particleRate * deltaTime;
  273. for (var i = 0; i < amount; i++) {
  274. var pos = pointOnHeart(Math.PI - 2 * Math.PI * Math.random());
  275. var dir = pos.clone().length(settings.particles.velocity);
  276. particles.add(
  277. canvas.width / 2 + pos.x,
  278. canvas.height / 2 - pos.y,
  279. dir.x,
  280. -dir.y
  281. );
  282. }
  283. // update and draw particles
  284. particles.update(deltaTime);
  285. particles.draw(context, image);
  286. }
  287. // handle (re-)sizing of the canvas
  288. function onResize() {
  289. canvas.width = canvas.clientWidth;
  290. canvas.height = canvas.clientHeight;
  291. }
  292. window.onresize = onResize;
  293. // delay rendering bootstrap
  294. setTimeout(function () {
  295. onResize();
  296. render();
  297. }, 10);
  298. })(document.getElementById("pinkboard"));
  299. </script>
  300. </body>
  301. </html>

好了,这就是全部爱心代码了

今天是三八女神节,无论是小妹妹还是大姐姐,我都想对我的同性说:生活处处充满美好,无论身处什么逆境,都应该往前看,一切都会过去的,我们女性大部分都会因为感情,学业,家庭的等困扰所影响,我一直觉得感情应该以佛系的态度看待,学业,努力向上我觉得就很幸福,自己想要的自己去努力争取,不去依附她人,做自己的女王,你就是这个世界最闪闪发光的人!!!

今天的分享就到此结束了

创作不易点赞评论互关三连

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/357777
推荐阅读
相关标签
  

闽ICP备14008679号