index.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <!DOCTYPE html>
  2. <html dir="ltr" lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width" />
  6. <title>Enjoy fireworks</title>
  7. <script type="text/javascript" src="http://game.ikongzhong.cn/games/qw/jquery.min.js"></script>
  8. <script type="text/javascript">
  9. var dataForWeixin = {
  10. appId: "gh_ff79a97cd7f3",
  11. TLImg: "http://game.ikongzhong.cn/games/yh/logo.jpg",
  12. url: "http://game.ikongzhong.cn/games/yh/en/",
  13. title: "Lonely fireworks shows, if you feel good, please share the wechat!",
  14. desc: "Lonely fireworks shows, if you feel good, please share the wechat!"
  15. };
  16. var onBridgeReady = function(){
  17. WeixinJSBridge.on('menu:share:appmessage', function(argv){
  18. var infos = $("#infos").text();
  19. WeixinJSBridge.invoke('sendAppMessage', {
  20. "appid": dataForWeixin.appId,
  21. "img_url": dataForWeixin.TLImg,
  22. "img_width": "120",
  23. "img_height": "120",
  24. "link": dataForWeixin.url + '?f=wx_hy_bb',
  25. "title": infos + dataForWeixin.title,
  26. "desc": dataForWeixin.desc
  27. });
  28. setTimeout(function () {location.href = "http://game.ikongzhong.cn/games/yh/en/";}, 1500);
  29. });
  30. WeixinJSBridge.on('menu:share:timeline', function(argv){
  31. var infos = $("#infos").text();
  32. WeixinJSBridge.invoke('shareTimeline', {
  33. "appid": dataForWeixin.appId,
  34. "img_url":dataForWeixin.TLImg,
  35. "img_width": "120",
  36. "img_height": "120",
  37. "link": dataForWeixin.url + '?f=wx_pyq_bb',
  38. "title": infos + dataForWeixin.title,
  39. "desc": dataForWeixin.desc
  40. });
  41. setTimeout(function () {location.href = "http://game.ikongzhong.cn/games/yh/en/";}, 1500);
  42. });
  43. };
  44. if(document.addEventListener){
  45. document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
  46. }else if(document.attachEvent){
  47. document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
  48. document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
  49. }
  50. </script>
  51. <style>
  52. /* basic styles for black background and crosshair cursor */
  53. body {
  54. background: #000;
  55. margin: 0;
  56. }
  57. canvas {
  58. cursor: crosshair;
  59. display: block;
  60. }
  61. .STYLE1 {color: #333333}
  62. </style>
  63. </head>
  64. <div style="text-align:center;clear:both">
  65. </div>
  66. <canvas id="canvas"><span class="STYLE1">Open IE effect more perfect </span></canvas>
  67. <script>
  68. // when animating on canvas, it is best to use requestAnimationFrame instead of setTimeout or setInterval
  69. // not supported in all browsers though and sometimes needs a prefix, so we need a shim
  70. window.requestAnimFrame = ( function() {
  71. return window.requestAnimationFrame ||
  72. window.webkitRequestAnimationFrame ||
  73. window.mozRequestAnimationFrame ||
  74. function( callback ) {
  75. window.setTimeout( callback, 1000 / 60 );
  76. };
  77. })();
  78. // now we will setup our basic variables for the demo
  79. var canvas = document.getElementById( 'canvas' ),
  80. ctx = canvas.getContext( '2d' ),
  81. // full screen dimensions
  82. cw = window.innerWidth,
  83. ch = window.innerHeight,
  84. // firework collection
  85. fireworks = [],
  86. // particle collection
  87. particles = [],
  88. // starting hue
  89. hue = 120,
  90. // when launching fireworks with a click, too many get launched at once without a limiter, one launch per 5 loop ticks
  91. limiterTotal = 5,
  92. limiterTick = 0,
  93. // this will time the auto launches of fireworks, one launch per 80 loop ticks
  94. timerTotal = 80,
  95. timerTick = 0,
  96. mousedown = false,
  97. // mouse x coordinate,
  98. mx,
  99. // mouse y coordinate
  100. my;
  101. // set canvas dimensions
  102. canvas.width = cw;
  103. canvas.height = ch;
  104. // now we are going to setup our function placeholders for the entire demo
  105. // get a random number within a range
  106. function random( min, max ) {
  107. return Math.random() * ( max - min ) + min;
  108. }
  109. // calculate the distance between two points
  110. function calculateDistance( p1x, p1y, p2x, p2y ) {
  111. var xDistance = p1x - p2x,
  112. yDistance = p1y - p2y;
  113. return Math.sqrt( Math.pow( xDistance, 2 ) + Math.pow( yDistance, 2 ) );
  114. }
  115. // create firework
  116. function Firework( sx, sy, tx, ty ) {
  117. // actual coordinates
  118. this.x = sx;
  119. this.y = sy;
  120. // starting coordinates
  121. this.sx = sx;
  122. this.sy = sy;
  123. // target coordinates
  124. this.tx = tx;
  125. this.ty = ty;
  126. // distance from starting point to target
  127. this.distanceToTarget = calculateDistance( sx, sy, tx, ty );
  128. this.distanceTraveled = 0;
  129. // track the past coordinates of each firework to create a trail effect, increase the coordinate count to create more prominent trails
  130. this.coordinates = [];
  131. this.coordinateCount = 3;
  132. // populate initial coordinate collection with the current coordinates
  133. while( this.coordinateCount-- ) {
  134. this.coordinates.push( [ this.x, this.y ] );
  135. }
  136. this.angle = Math.atan2( ty - sy, tx - sx );
  137. this.speed = 2;
  138. this.acceleration = 1.05;
  139. this.brightness = random( 50, 70 );
  140. // circle target indicator radius
  141. this.targetRadius = 1;
  142. }
  143. // update firework
  144. Firework.prototype.update = function( index ) {
  145. // remove last item in coordinates array
  146. this.coordinates.pop();
  147. // add current coordinates to the start of the array
  148. this.coordinates.unshift( [ this.x, this.y ] );
  149. // cycle the circle target indicator radius
  150. if( this.targetRadius < 8 ) {
  151. this.targetRadius += 0.3;
  152. } else {
  153. this.targetRadius = 1;
  154. }
  155. // speed up the firework
  156. this.speed *= this.acceleration;
  157. // get the current velocities based on angle and speed
  158. var vx = Math.cos( this.angle ) * this.speed,
  159. vy = Math.sin( this.angle ) * this.speed;
  160. // how far will the firework have traveled with velocities applied?
  161. this.distanceTraveled = calculateDistance( this.sx, this.sy, this.x + vx, this.y + vy );
  162. // if the distance traveled, including velocities, is greater than the initial distance to the target, then the target has been reached
  163. if( this.distanceTraveled >= this.distanceToTarget ) {
  164. createParticles( this.tx, this.ty );
  165. // remove the firework, use the index passed into the update function to determine which to remove
  166. fireworks.splice( index, 1 );
  167. } else {
  168. // target not reached, keep traveling
  169. this.x += vx;
  170. this.y += vy;
  171. }
  172. }
  173. // draw firework
  174. Firework.prototype.draw = function() {
  175. ctx.beginPath();
  176. // move to the last tracked coordinate in the set, then draw a line to the current x and y
  177. ctx.moveTo( this.coordinates[ this.coordinates.length - 1][ 0 ], this.coordinates[ this.coordinates.length - 1][ 1 ] );
  178. ctx.lineTo( this.x, this.y );
  179. ctx.strokeStyle = 'hsl(' + hue + ', 100%, ' + this.brightness + '%)';
  180. ctx.stroke();
  181. ctx.beginPath();
  182. // draw the target for this firework with a pulsing circle
  183. ctx.arc( this.tx, this.ty, this.targetRadius, 0, Math.PI * 2 );
  184. ctx.stroke();
  185. }
  186. // create particle
  187. function Particle( x, y ) {
  188. this.x = x;
  189. this.y = y;
  190. // track the past coordinates of each particle to create a trail effect, increase the coordinate count to create more prominent trails
  191. this.coordinates = [];
  192. this.coordinateCount = 5;
  193. while( this.coordinateCount-- ) {
  194. this.coordinates.push( [ this.x, this.y ] );
  195. }
  196. // set a random angle in all possible directions, in radians
  197. this.angle = random( 0, Math.PI * 2 );
  198. this.speed = random( 1, 10 );
  199. // friction will slow the particle down
  200. this.friction = 0.95;
  201. // gravity will be applied and pull the particle down
  202. this.gravity = 1;
  203. // set the hue to a random number +-20 of the overall hue variable
  204. this.hue = random( hue - 20, hue + 20 );
  205. this.brightness = random( 50, 80 );
  206. this.alpha = 1;
  207. // set how fast the particle fades out
  208. this.decay = random( 0.015, 0.03 );
  209. }
  210. // update particle
  211. Particle.prototype.update = function( index ) {
  212. // remove last item in coordinates array
  213. this.coordinates.pop();
  214. // add current coordinates to the start of the array
  215. this.coordinates.unshift( [ this.x, this.y ] );
  216. // slow down the particle
  217. this.speed *= this.friction;
  218. // apply velocity
  219. this.x += Math.cos( this.angle ) * this.speed;
  220. this.y += Math.sin( this.angle ) * this.speed + this.gravity;
  221. // fade out the particle
  222. this.alpha -= this.decay;
  223. // remove the particle once the alpha is low enough, based on the passed in index
  224. if( this.alpha <= this.decay ) {
  225. particles.splice( index, 1 );
  226. }
  227. }
  228. // draw particle
  229. Particle.prototype.draw = function() {
  230. ctx. beginPath();
  231. // move to the last tracked coordinates in the set, then draw a line to the current x and y
  232. ctx.moveTo( this.coordinates[ this.coordinates.length - 1 ][ 0 ], this.coordinates[ this.coordinates.length - 1 ][ 1 ] );
  233. ctx.lineTo( this.x, this.y );
  234. ctx.strokeStyle = 'hsla(' + this.hue + ', 100%, ' + this.brightness + '%, ' + this.alpha + ')';
  235. ctx.stroke();
  236. }
  237. // create particle group/explosion
  238. function createParticles( x, y ) {
  239. // increase the particle count for a bigger explosion, beware of the canvas performance hit with the increased particles though
  240. var particleCount = 30;
  241. while( particleCount-- ) {
  242. particles.push( new Particle( x, y ) );
  243. }
  244. }
  245. // main demo loop
  246. function loop() {
  247. // this function will run endlessly with requestAnimationFrame
  248. requestAnimFrame( loop );
  249. // increase the hue to get different colored fireworks over time
  250. hue += 0.5;
  251. // normally, clearRect() would be used to clear the canvas
  252. // we want to create a trailing effect though
  253. // setting the composite operation to destination-out will allow us to clear the canvas at a specific opacity, rather than wiping it entirely
  254. ctx.globalCompositeOperation = 'destination-out';
  255. // decrease the alpha property to create more prominent trails
  256. ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
  257. ctx.fillRect( 0, 0, cw, ch );
  258. // change the composite operation back to our main mode
  259. // lighter creates bright highlight points as the fireworks and particles overlap each other
  260. ctx.globalCompositeOperation = 'lighter';
  261. // loop over each firework, draw it, update it
  262. var i = fireworks.length;
  263. while( i-- ) {
  264. fireworks[ i ].draw();
  265. fireworks[ i ].update( i );
  266. }
  267. // loop over each particle, draw it, update it
  268. var i = particles.length;
  269. while( i-- ) {
  270. particles[ i ].draw();
  271. particles[ i ].update( i );
  272. }
  273. // launch fireworks automatically to random coordinates, when the mouse isn't down
  274. if( timerTick >= timerTotal ) {
  275. if( !mousedown ) {
  276. // start the firework at the bottom middle of the screen, then set the random target coordinates, the random y coordinates will be set within the range of the top half of the screen
  277. fireworks.push( new Firework( cw / 2, ch, random( 0, cw ), random( 0, ch / 2 ) ) );
  278. timerTick = 0;
  279. }
  280. } else {
  281. timerTick++;
  282. }
  283. // limit the rate at which fireworks get launched when mouse is down
  284. if( limiterTick >= limiterTotal ) {
  285. if( mousedown ) {
  286. // start the firework at the bottom middle of the screen, then set the current mouse coordinates as the target
  287. fireworks.push( new Firework( cw / 2, ch, mx, my ) );
  288. limiterTick = 0;
  289. }
  290. } else {
  291. limiterTick++;
  292. }
  293. }
  294. // mouse event bindings
  295. // update the mouse coordinates on mousemove
  296. canvas.addEventListener( 'mousemove', function( e ) {
  297. mx = e.pageX - canvas.offsetLeft;
  298. my = e.pageY - canvas.offsetTop;
  299. });
  300. // toggle mousedown state and prevent canvas from being selected
  301. canvas.addEventListener( 'mousedown', function( e ) {
  302. e.preventDefault();
  303. mousedown = true;
  304. });
  305. canvas.addEventListener( 'mouseup', function( e ) {
  306. e.preventDefault();
  307. mousedown = false;
  308. });
  309. // once the window loads, we are ready for some fireworks!
  310. window.onload = loop;
  311. </script>
  312. <img src="../yanhua.jpg" width="380" height="120">
  313. <img src="http://img.tongji.linezing.com/3455448/tongji.gif" />
  314. <audio autoplay="autoplay">
  315. <source src="http://www.sypeiyin.cn/Uploads/zh/News/2012071516257FJR.mp3" type="audio/mpeg">
  316. </audio>