当前位置:   article > 正文

用HTML做2个新年代码_html新年祝福代码

html新年祝福代码

文章目录


前言

新年快到了,先祝大家新年快乐!有两个代码,任你挑选。


一、烟花代码

烟花从发射到绽放一共分为三个阶段: 发射阶段, 烟花绽放 , 烟花凋零 。

代码:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title></title>
  6. <meta charset="utf-8">
  7. <title>3D烟花</title>
  8. <style>
  9. html,body{
  10. margin:0px;
  11. width:100%;
  12. height:100%;
  13. overflow:hidden;
  14. background:#000;
  15. }
  16. #canvas{
  17. width:100%;
  18. height:100%;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <canvas id="canvas" width="825" height="631"></canvas><script>
  24. function initVars(){
  25. pi=Math.PI;
  26. ctx=canvas.getContext("2d");
  27. canvas.width=canvas.clientWidth;
  28. canvas.height=canvas.clientHeight;
  29. cx=canvas.width/2;
  30. cy=canvas.height/2;
  31. playerZ=-25;
  32. playerX=playerY=playerVX=playerVY=playerVZ=pitch=yaw=pitchV=yawV=0;
  33. scale=600;
  34. seedTimer=0;seedInterval=5,seedLife=100;gravity=.02;
  35. seeds=new Array();
  36. sparkPics=new Array();
  37. s="https://cantelope.org/NYE/";
  38. for(i=1;i<=10;++i){
  39. sparkPic=new Image();
  40. sparkPic.src=s+"spark"+i+".png";
  41. sparkPics.push(sparkPic);
  42. }
  43. sparks=new Array();
  44. pow1=new Audio(s+"pow1.ogg");
  45. pow2=new Audio(s+"pow2.ogg");
  46. pow3=new Audio(s+"pow3.ogg");
  47. pow4=new Audio(s+"pow4.ogg");
  48. frames = 0;
  49. }
  50. function rasterizePoint(x,y,z){
  51. var p,d;
  52. x-=playerX;
  53. y-=playerY;
  54. z-=playerZ;
  55. p=Math.atan2(x,z);
  56. d=Math.sqrt(x*x+z*z);
  57. x=Math.sin(p-yaw)*d;
  58. z=Math.cos(p-yaw)*d;
  59. p=Math.atan2(y,z);
  60. d=Math.sqrt(y*y+z*z);
  61. y=Math.sin(p-pitch)*d;
  62. z=Math.cos(p-pitch)*d;
  63. var rx1=-1000,ry1=1,rx2=1000,ry2=1,rx3=0,ry3=0,rx4=x,ry4=z,uc=(ry4-ry3)*(rx2-rx1)-(rx4-rx3)*(ry2-ry1);
  64. if(!uc) return {x:0,y:0,d:-1};
  65. var ua=((rx4-rx3)*(ry1-ry3)-(ry4-ry3)*(rx1-rx3))/uc;
  66. var ub=((rx2-rx1)*(ry1-ry3)-(ry2-ry1)*(rx1-rx3))/uc;
  67. if(!z)z=.000000001;
  68. if(ua>0&&ua<1&&ub>0&&ub<1){
  69. return {
  70. x:cx+(rx1+ua*(rx2-rx1))*scale,
  71. y:cy+y/z*scale,
  72. d:Math.sqrt(x*x+y*y+z*z)
  73. };
  74. }else{
  75. return {
  76. x:cx+(rx1+ua*(rx2-rx1))*scale,
  77. y:cy+y/z*scale,
  78. d:-1
  79. };
  80. }
  81. }
  82. function spawnSeed(){
  83. seed=new Object();
  84. seed.x=-50+Math.random()*100;
  85. seed.y=25;
  86. seed.z=-50+Math.random()*100;
  87. seed.vx=.1-Math.random()*.2;
  88. seed.vy=-1.5;//*(1+Math.random()/2);
  89. seed.vz=.1-Math.random()*.2;
  90. seed.born=frames;
  91. seeds.push(seed);
  92. }
  93. function splode(x,y,z){
  94. t=5+parseInt(Math.random()*150);
  95. sparkV=1+Math.random()*2.5;
  96. type=parseInt(Math.random()*3);
  97. switch(type){
  98. case 0:
  99. pic1=parseInt(Math.random()*10);
  100. break;
  101. case 1:
  102. pic1=parseInt(Math.random()*10);
  103. do{ pic2=parseInt(Math.random()*10); }while(pic2==pic1);
  104. break;
  105. case 2:
  106. pic1=parseInt(Math.random()*10);
  107. do{ pic2=parseInt(Math.random()*10); }while(pic2==pic1);
  108. do{ pic3=parseInt(Math.random()*10); }while(pic3==pic1 || pic3==pic2);
  109. break;
  110. }
  111. for(m=1;m<t;++m){
  112. spark=new Object();
  113. spark.x=x; spark.y=y; spark.z=z;
  114. p1=pi*2*Math.random();
  115. p2=pi*Math.random();
  116. v=sparkV*(1+Math.random()/6)
  117. spark.vx=Math.sin(p1)*Math.sin(p2)*v;
  118. spark.vz=Math.cos(p1)*Math.sin(p2)*v;
  119. spark.vy=Math.cos(p2)*v;
  120. switch(type){
  121. case 0: spark.img=sparkPics[pic1]; break;
  122. case 1:
  123. spark.img=sparkPics[parseInt(Math.random()*2)?pic1:pic2];
  124. break;
  125. case 2:
  126. switch(parseInt(Math.random()*3)){
  127. case 0: spark.img=sparkPics[pic1]; break;
  128. case 1: spark.img=sparkPics[pic2]; break;
  129. case 2: spark.img=sparkPics[pic3]; break;
  130. }
  131. break;
  132. }
  133. spark.radius=25+Math.random()*50;
  134. spark.alpha=1;
  135. spark.trail=new Array();
  136. sparks.push(spark);
  137. }
  138. switch(parseInt(Math.random()*4)){
  139. case 0: pow=new Audio(s+"pow1.ogg"); break;
  140. case 1: pow=new Audio(s+"pow2.ogg"); break;
  141. case 2: pow=new Audio(s+"pow3.ogg"); break;
  142. case 3: pow=new Audio(s+"pow4.ogg"); break;
  143. }
  144. d=Math.sqrt((x-playerX)*(x-playerX)+(y-playerY)*(y-playerY)+(z-playerZ)*(z-playerZ));
  145. pow.volume=1.5/(1+d/10);
  146. pow.play();
  147. }
  148. function doLogic(){
  149. if(seedTimer<frames){
  150. seedTimer=frames+seedInterval*Math.random()*10;
  151. spawnSeed();
  152. }
  153. for(i=0;i<seeds.length;++i){
  154. seeds[i].vy+=gravity;
  155. seeds[i].x+=seeds[i].vx;
  156. seeds[i].y+=seeds[i].vy;
  157. seeds[i].z+=seeds[i].vz;
  158. if(frames-seeds[i].born>seedLife){
  159. splode(seeds[i].x,seeds[i].y,seeds[i].z);
  160. seeds.splice(i,1);
  161. }
  162. }
  163. for(i=0;i<sparks.length;++i){
  164. if(sparks[i].alpha>0 && sparks[i].radius>5){
  165. sparks[i].alpha-=.01;
  166. sparks[i].radius/=1.02;
  167. sparks[i].vy+=gravity;
  168. point=new Object();
  169. point.x=sparks[i].x;
  170. point.y=sparks[i].y;
  171. point.z=sparks[i].z;
  172. if(sparks[i].trail.length){
  173. x=sparks[i].trail[sparks[i].trail.length-1].x;
  174. y=sparks[i].trail[sparks[i].trail.length-1].y;
  175. z=sparks[i].trail[sparks[i].trail.length-1].z;
  176. d=((point.x-x)*(point.x-x)+(point.y-y)*(point.y-y)+(point.z-z)*(point.z-z));
  177. if(d>9){
  178. sparks[i].trail.push(point);
  179. }
  180. }else{
  181. sparks[i].trail.push(point);
  182. }
  183. if(sparks[i].trail.length>5)sparks[i].trail.splice(0,1);
  184. sparks[i].x+=sparks[i].vx;
  185. sparks[i].y+=sparks[i].vy;
  186. sparks[i].z+=sparks[i].vz;
  187. sparks[i].vx/=1.075;
  188. sparks[i].vy/=1.075;
  189. sparks[i].vz/=1.075;
  190. }else{
  191. sparks.splice(i,1);
  192. }
  193. }
  194. p=Math.atan2(playerX,playerZ);
  195. d=Math.sqrt(playerX*playerX+playerZ*playerZ);
  196. d+=Math.sin(frames/80)/1.25;
  197. t=Math.sin(frames/200)/40;
  198. playerX=Math.sin(p+t)*d;
  199. playerZ=Math.cos(p+t)*d;
  200. yaw=pi+p+t;
  201. }
  202. function rgb(col){
  203. var r = parseInt((.5+Math.sin(col)*.5)*16);
  204. var g = parseInt((.5+Math.cos(col)*.5)*16);
  205. var b = parseInt((.5-Math.sin(col)*.5)*16);
  206. return "#"+r.toString(16)+g.toString(16)+b.toString(16);
  207. }
  208. function draw(){
  209. ctx.clearRect(0,0,cx*2,cy*2);
  210. ctx.fillStyle="#ff8";
  211. for(i=-100;i<100;i+=3){
  212. for(j=-100;j<100;j+=4){
  213. x=i;z=j;y=25;
  214. point=rasterizePoint(x,y,z);
  215. if(point.d!=-1){
  216. size=250/(1+point.d);
  217. d = Math.sqrt(x * x + z * z);
  218. a = 0.75 - Math.pow(d / 100, 6) * 0.75;
  219. if(a>0){
  220. ctx.globalAlpha = a;
  221. ctx.fillRect(point.x-size/2,point.y-size/2,size,size);
  222. }
  223. }
  224. }
  225. }
  226. ctx.globalAlpha=1;
  227. for(i=0;i<seeds.length;++i){
  228. point=rasterizePoint(seeds[i].x,seeds[i].y,seeds[i].z);
  229. if(point.d!=-1){
  230. size=200/(1+point.d);
  231. ctx.fillRect(point.x-size/2,point.y-size/2,size,size);
  232. }
  233. }
  234. point1=new Object();
  235. for(i=0;i<sparks.length;++i){
  236. point=rasterizePoint(sparks[i].x,sparks[i].y,sparks[i].z);
  237. if(point.d!=-1){
  238. size=sparks[i].radius*200/(1+point.d);
  239. if(sparks[i].alpha<0)sparks[i].alpha=0;
  240. if(sparks[i].trail.length){
  241. point1.x=point.x;
  242. point1.y=point.y;
  243. switch(sparks[i].img){
  244. case sparkPics[0]:ctx.strokeStyle="#f84";break;
  245. case sparkPics[1]:ctx.strokeStyle="#84f";break;
  246. case sparkPics[2]:ctx.strokeStyle="#8ff";break;
  247. case sparkPics[3]:ctx.strokeStyle="#fff";break;
  248. case sparkPics[4]:ctx.strokeStyle="#4f8";break;
  249. case sparkPics[5]:ctx.strokeStyle="#f44";break;
  250. case sparkPics[6]:ctx.strokeStyle="#f84";break;
  251. case sparkPics[7]:ctx.strokeStyle="#84f";break;
  252. case sparkPics[8]:ctx.strokeStyle="#fff";break;
  253. case sparkPics[9]:ctx.strokeStyle="#44f";break;
  254. }
  255. for(j=sparks[i].trail.length-1;j>=0;--j){
  256. point2=rasterizePoint(sparks[i].trail[j].x,sparks[i].trail[j].y,sparks[i].trail[j].z);
  257. if(point2.d!=-1){
  258. ctx.globalAlpha=j/sparks[i].trail.length*sparks[i].alpha/2;
  259. ctx.beginPath();
  260. ctx.moveTo(point1.x,point1.y);
  261. ctx.lineWidth=1+sparks[i].radius*10/(sparks[i].trail.length-j)/(1+point2.d);
  262. ctx.lineTo(point2.x,point2.y);
  263. ctx.stroke();
  264. point1.x=point2.x;
  265. point1.y=point2.y;
  266. }
  267. }
  268. }
  269. ctx.globalAlpha=sparks[i].alpha;
  270. ctx.drawImage(sparks[i].img,point.x-size/2,point.y-size/2,size,size);
  271. }
  272. }
  273. }
  274. function frame(){
  275. if(frames>100000){
  276. seedTimer=0;
  277. frames=0;
  278. }
  279. frames++;
  280. draw();
  281. doLogic();
  282. requestAnimationFrame(frame);
  283. }
  284. window.addEventListener("resize",()=>{
  285. canvas.width=canvas.clientWidth;
  286. canvas.height=canvas.clientHeight;
  287. cx=canvas.width/2;
  288. cy=canvas.height/2;
  289. });
  290. initVars();
  291. frame();</script>
  292. </body>
  293. </html>

二、灯笼代码

灯笼代码我做的就比较简单了,但显示不出后面的字,望各位大佬多多指点。

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>Document</title>
  8. <style>
  9. .deng-box {
  10. position: fixed;
  11. top: 30px;
  12. left: 50%;
  13. z-index: 999;
  14. }
  15. .deng-box1 {
  16. position: fixed;
  17. top: 28px;
  18. left: 49%;
  19. z-index: 999;
  20. }
  21. .deng-box1 .deng {
  22. position: relative;
  23. width: 120px;
  24. height: 90px;
  25. margin: 50px;
  26. background: #d8000f;
  27. background: rgba(216, 0, 15, 0.8);
  28. border-radius: 50% 50%;
  29. -webkit-transform-origin: 50% -100px;
  30. -webkit-animation: swing 5s infinite ease-in-out;
  31. box-shadow: -5px 5px 30px 4px rgba(252, 144, 61, 1);
  32. }
  33. .deng {
  34. position: relative;
  35. width: 120px;
  36. height: 90px;
  37. margin: 50px;
  38. background: #d8000f;
  39. background: rgba(216, 0, 15, 0.8);
  40. border-radius: 50% 50%;
  41. -webkit-transform-origin: 50% -100px;
  42. -webkit-animation: swing 3s infinite ease-in-out;
  43. box-shadow: -5px 5px 50px 4px rgba(250, 108, 0, 1);
  44. }
  45. .deng-a {
  46. width: 100px;
  47. height: 90px;
  48. background: #d8000f;
  49. background: rgba(216, 0, 15, 0.1);
  50. margin: 12px 8px 8px 8px;
  51. border-radius: 50% 50%;
  52. border: 2px solid #dc8f03;
  53. }
  54. .deng-b {
  55. width: 45px;
  56. height: 90px;
  57. background: #d8000f;
  58. background: rgba(216, 0, 15, 0.1);
  59. margin: -4px 8px 8px 26px;
  60. border-radius: 50% 50%;
  61. border: 2px solid #dc8f03;
  62. }
  63. .xian {
  64. position: absolute;
  65. top: -20px;
  66. left: 60px;
  67. width: 2px;
  68. height: 20px;
  69. background: #dc8f03;
  70. }
  71. .shui-a {
  72. position: relative;
  73. width: 5px;
  74. height: 20px;
  75. margin: -5px 0 0 59px;
  76. -webkit-animation: swing 4s infinite ease-in-out;
  77. -webkit-transform-origin: 50% -45px;
  78. background: #ffa500;
  79. border-radius: 0 0 5px 5px;
  80. }
  81. .shui-b {
  82. position: absolute;
  83. top: 14px;
  84. left: -2px;
  85. width: 10px;
  86. height: 10px;
  87. background: #dc8f03;
  88. border-radius: 50%;
  89. }
  90. .shui-c {
  91. position: absolute;
  92. top: 18px;
  93. left: -2px;
  94. width: 10px;
  95. height: 35px;
  96. background: #ffa500;
  97. border-radius: 0 0 0 5px;
  98. }
  99. .deng:before {
  100. position: absolute;
  101. top: -7px;
  102. left: 29px;
  103. height: 12px;
  104. width: 60px;
  105. content: " ";
  106. display: block;
  107. z-index: 999;
  108. border-radius: 5px 5px 0 0;
  109. border: solid 1px #dc8f03;
  110. background: #ffa500;
  111. background: linear-gradient(
  112. to right,
  113. #dc8f03,
  114. #ffa500,
  115. #dc8f03,
  116. #ffa500,
  117. #dc8f03
  118. );
  119. }
  120. .deng:after {
  121. position: absolute;
  122. bottom: -7px;
  123. left: 10px;
  124. height: 12px;
  125. width: 60px;
  126. content: " ";
  127. display: block;
  128. margin-left: 20px;
  129. border-radius: 0 0 5px 5px;
  130. border: solid 1px #dc8f03;
  131. background: #ffa500;
  132. background: linear-gradient(
  133. to right,
  134. #dc8f03,
  135. #ffa500,
  136. #dc8f03,
  137. #ffa500,
  138. #dc8f03
  139. );
  140. }
  141. .deng-t {
  142. font-family: 华文行楷, Arial, Lucida Grande, Tahoma, sans-serif;
  143. font-size: 3.2rem;
  144. color: #dc8f03;
  145. font-weight: bold;
  146. line-height: 85px;
  147. text-align: center;
  148. }
  149. .night .deng-t,
  150. .night .deng-box,
  151. .night .deng-box1 {
  152. background: transparent !important;
  153. }
  154. @-moz-keyframes swing {
  155. 0% {
  156. -moz-transform: rotate(-10deg);
  157. }
  158. 50% {
  159. -moz-transform: rotate(10deg);
  160. }
  161. 100% {
  162. -moz-transform: rotate(-10deg);
  163. }
  164. }
  165. @-webkit-keyframes swing {
  166. 0% {
  167. -webkit-transform: rotate(-10deg);
  168. }
  169. 50% {
  170. -webkit-transform: rotate(10deg);
  171. }
  172. 100% {
  173. -webkit-transform: rotate(-10deg);
  174. }
  175. }
  176. </style>
  177. </head>
  178. <body>
  179. <!-- 灯笼1 -->
  180. <div class="deng-box">
  181. <div class="deng">
  182. <div class="xian"></div>
  183. <div class="deng-a">
  184. <div class="deng-b"><div class="deng-t"></div></div>
  185. </div>
  186. <div class="shui shui-a">
  187. <div class="shui-c"></div>
  188. <div class="shui-b"></div>
  189. </div>
  190. </div>
  191. </div>
  192. <!-- 灯笼2 -->
  193. <div class="deng-box1">
  194. <div class="deng">
  195. <div class="xian"></div>
  196. <div class="deng-a">
  197. <div class="deng-b"><div class="deng-t"></div></div>
  198. </div>
  199. <div class="shui shui-a">
  200. <div class="shui-c"></div>
  201. <div class="shui-b"></div>
  202. </div>
  203. </div>
  204. </div>
  205. </body>
  206. </html>

总结

新的一年,祝大家万事如意,心想事成!

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

闽ICP备14008679号