<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/" >

<channel>
	<title>pháo hoa &#8211; AnonyViet</title>
	<atom:link href="https://anonyviet.com/tag/phao-hoa/feed/" rel="self" type="application/rss+xml" />
	<link>https://anonyviet.com</link>
	<description>Webiste chia sẻ kiến thức công nghệ thông tin, mạng máy tính, bảo mật phổ biến nhất Việt Nam. Luôn cập nhật tin tức, thủ thuật nóng hổi nhất</description>
	<lastBuildDate>Fri, 25 Jul 2025 08:17:43 +0000</lastBuildDate>
	<language>vi</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://anonyviet.com/wp-content/uploads/2018/10/cropped-ico-logo-75x75.png</url>
	<title>pháo hoa &#8211; AnonyViet</title>
	<link>https://anonyviet.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Code pháo hoa trang trí cho Website dịp tết</title>
		<link>https://anonyviet.com/code-phao-hoa-trang-tri-cho-website-dip-tet/</link>
					<comments>https://anonyviet.com/code-phao-hoa-trang-tri-cho-website-dip-tet/#respond</comments>
		
		<dc:creator><![CDATA[AnonyViet]]></dc:creator>
		<pubDate>Sat, 25 Jan 2025 06:38:23 +0000</pubDate>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[code pháo hoa tết]]></category>
		<category><![CDATA[pháo hoa]]></category>
		<guid isPermaLink="false">https://anonyviet.com/?p=79105</guid>

					<description><![CDATA[Dịp Tết là thời điểm lý tưởng để trang trí website của bạn với các hiệu ứng Code pháo hoa trang trí đẹp mắt và sống động nhằm mang đến không khí lễ hội. Một trong những hiệu ứng phổ biến và ấn tượng là bắn pháo hoa. Với hiệu ứng này, website của bạn [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><strong>Dịp Tết là thời điểm lý tưởng để trang trí website của bạn với các hiệu ứng Code pháo hoa trang trí đẹp mắt và sống động nhằm mang đến không khí lễ hội. Một trong những hiệu ứng phổ biến và ấn tượng là bắn pháo hoa. Với hiệu ứng này, website của bạn không chỉ thu hút sự chú ý của người xem mà còn tạo cảm giác vui vẻ, hứng khởi.</strong></p>
<p><img fetchpriority="high" decoding="async" class="aligncenter size-full " src="https://anonyviet.com/wp-content/uploads/2025/01/code-phao-hoa-tet.jpg" alt="Code pháo hoa trang trí cho Website dịp tết 2" width="829" height="331" title="Code pháo hoa trang trí cho Website dịp tết 2"></p>
<p>Code bắn pháo hoa mang lại nhiều lợi ích và rất dễ áp dụng. Hiệu ứng này cho phép hiển thị các tia pháo hoa rực rỡ trên toàn màn hình, xuất hiện khi người dùng nhấp chuột hoặc tự động bắn sau mỗi vài giây. Đặc biệt, bạn có thể tùy chỉnh màu sắc, kích thước và tần suất pháo hoa để phù hợp với thiết kế tổng thể của website.</p>
<p>Ứng dụng của code pháo hoa rất đa dạng. Bạn có thể sử dụng nó để tạo điểm nhấn cho các chương trình khuyến mãi Tết trên website thương mại điện tử, làm đẹp blog cá nhân theo chủ đề năm mới, hoặc trang trí trang giới thiệu sự kiện và chiến dịch quảng bá lễ hội. Code được viết bằng JavaScript kết hợp với HTML và CSS, đảm bảo nhẹ nhàng, không ảnh hưởng đến tốc độ tải trang, và tương thích tốt trên hầu hết các trình duyệt hiện đại.</p>
<p>Ngoài ra bạn có thể tham khảo <a href="https://anonyviet.com/code-hieu-ung-phao-hoa-theo-chuot-trang-tri-website-tet/">code pháo hoa di theo chuột</a> ở bài viết trước</p>
<h1>Code pháo hoa trang trí Website</h1>
<p>Trước khi quyết định có dùng code hay không, bạn có thể xem Demo pháo hóa tại trang này: <a href="https://anonyviet.com/resource/phaohoa/demo.html">https://anonyviet.com/resource/phaohoa/demo.html</a></p>
<p>Đây là code gốc được tham khảo từ website: https://quaqueviet.nguyenlan.io.vn/phaohoa.txt</p>
<h3>Code pháo hoa tết cho WordPress</h3>
<p>Mở file functions.php trong thư mục theme của WordPress và copy toàn bộ code dưới đây dán vào ở cuối file functions.php (thường ở đường dẫn <strong>wp-content/themes/tên-theme/functions.php</strong>)</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">function chenphaohoa(){
?&gt;
&lt;link rel="stylesheet" href="https://anonyviet.com/resource/phaohoa/fireworks1.css"&gt;
&lt;script src="https://anonyviet.com/resource/phaohoa/fireworks1.js"&gt;&lt;/script&gt;
&lt;canvas id="fireworks" style="display:none;"&gt;&lt;/canvas&gt; 
&lt;?php
}

add_action('wp_footer','chenphaohoa');</pre>
<h3>Thêm code pháo hoa tết vào Blogspot/Website khác</h3>
<p>Bạn vào Menu đổi theme của Blogspot, edit html và thực hiện các bước sau:</p>
<ol>
<li class="whitespace-normal break-words">Vào Blogspot Dashboard</li>
<li class="whitespace-normal break-words">Theme &gt; Edit HTML</li>
<li class="whitespace-normal break-words">Dán code vào vị trí tương ứng bên dưới</li>
</ol>
<p><strong>Thêm code Trong phần <span style="color: #0000ff;">&lt;head&gt;</span></strong></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">&lt;link href='https://anonyviet.com/resource/phaohoa/fireworks1.css' rel='stylesheet' type='text/css'/&gt;</pre>
<p>Ngay trước thẻ đóng <span style="color: #0000ff;"><strong>&lt;/body&gt;</strong></span></p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">&lt;!-- FIREWORKS SCRIPT --&gt;
&lt;script src='https://anonyviet.com/resource/phaohoa/fireworks1.js' type='text/javascript'&gt;&lt;/script&gt;

&lt;!-- INITIALIZE FIREWORKS --&gt;
&lt;script&gt;
document.addEventListener("DOMContentLoaded", function() {
    const container = document.createElement('div');
    container.id = 'fireworks-container';
    document.body.appendChild(container);
    
    // Cấu hình pháo hoa
    const fireworksConfig = [
        {left:"15%", color:"#FF4C4C", explosionType:"circle", size:"large", launchTime:0},
        {left:"70%", color:"#FFD24C", explosionType:"star", size:"medium", launchTime:0},
        // ... (Giữ nguyên fireworksData như code gốc)
    ];

    fireworksConfig.forEach(config =&gt; {
        setTimeout(() =&gt; launchRocket(container, config), config.launchTime);
    });
    
    const maxTime = Math.max(...fireworksConfig.map(f =&gt; f.launchTime));
    setTimeout(() =&gt; launchGrandFinaleRocket(container), maxTime + 4000);
});
&lt;/script&gt;</pre>
<h1>Code pháo hoa phù hợp với Website có nền màu trắng sáng</h1>
<p>Đây là code pháo hoa khi bắn sẽ có thân pháo hoa pháo hình lắp lánh, tỏa sáng đối với các web có nền trắng, tạo hiệu ứng lung linh</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">&lt;!DOCTYPE html&gt;
&lt;html lang="vi"&gt;
&lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
  &lt;title&gt;Demo Pháo Hoa&lt;/title&gt;
  &lt;style&gt;
    body {
      margin: 0;
      background-color: #808080; /* Màu xám cho nền */
      overflow: hidden;
    }
    #fireworksCanvas {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      pointer-events: none;
      z-index: 9999;
    }
  &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;canvas id="fireworksCanvas"&gt;&lt;/canvas&gt;
  
  &lt;script&gt;
    const canvas = document.getElementById('fireworksCanvas');
    const ctx = canvas.getContext('2d');
    let width = window.innerWidth;
    let height = window.innerHeight;
    canvas.width = width;
    canvas.height = height;

    const fireworks = [];

    class Firework {
      constructor(x, targetY, colors) {
        this.x = x;
        this.y = height; // Xuất phát từ đáy màn hình
        this.targetY = targetY; // Mục tiêu vị trí phát nổ
        this.colors = colors;
        this.exploded = false;
        this.speedY = -6; // Tốc độ bay lên
        this.previousPositions = []; // Lưu trữ các vị trí trước đó để vẽ tia sáng
        this.particles = []; // Lưu hạt pháo hoa khi nổ
      }

      createParticles() {
        for (let i = 0; i &lt; 80; i++) {
          this.particles.push({
            x: this.x,
            y: this.y,
            speed: Math.random() * 3 + 1,
            angle: Math.random() * Math.PI * 2,
            radius: Math.random() * 2 + 1,
            color: this.colors[Math.floor(Math.random() * this.colors.length)],
            alpha: 1,
            decay: Math.random() * 0.02 + 0.01,
          });
        }
      }

      update() {
        if (!this.exploded) {
          // Lưu vị trí hiện tại vào mảng previousPositions
          this.previousPositions.push({ x: this.x, y: this.y });

          // Giữ lại chỉ một số lượng giới hạn vị trí để không làm đầy bộ nhớ
          if (this.previousPositions.length &gt; 10) {
            this.previousPositions.shift();
          }

          // Di chuyển pháo hoa lên
          this.y += this.speedY;
          if (this.y &lt;= this.targetY) {
            this.exploded = true;
            this.createParticles();
          }
        } else {
          this.updateParticles();
        }
      }

      updateParticles() {
        this.particles.forEach((particle, index) =&gt; {
          particle.x += Math.cos(particle.angle) * particle.speed;
          particle.y += Math.sin(particle.angle) * particle.speed;
          particle.alpha -= particle.decay;

          if (particle.alpha &lt;= 0) {
            this.particles.splice(index, 1);
          }
        });
      }

      draw() {
        if (!this.exploded) {
          // Vẽ tia sáng bằng các đoạn thẳng giữa các vị trí trước đó
          ctx.beginPath();
          for (let i = 0; i &lt; this.previousPositions.length - 1; i++) {
            const start = this.previousPositions[i];
            const end = this.previousPositions[i + 1];
            ctx.moveTo(start.x, start.y);
            ctx.lineTo(end.x, end.y);
          }
          // Sử dụng màu sắc ngẫu nhiên cho tia sáng
          ctx.strokeStyle = `rgb(${Math.random() * 255}, ${Math.random() * 255}, ${Math.random() * 255})`;
          ctx.lineWidth = 2; // Độ dày của tia sáng
          ctx.stroke();
        } else {
          // Vẽ các hạt pháo hoa khi nổ
          this.particles.forEach((particle) =&gt; {
            ctx.beginPath();
            ctx.arc(particle.x, particle.y, particle.radius, 0, Math.PI * 2);
            ctx.fillStyle = `rgba(${particle.color.r}, ${particle.color.g}, ${particle.color.b}, ${particle.alpha})`;
            ctx.fill();
          });
        }
      }

      isDone() {
        return this.exploded &amp;&amp; this.particles.length === 0;
      }
    }

    function createFirework() {
      const x = Math.random() * width; // Vị trí bắn pháo hoa ngẫu nhiên
      const targetY = Math.random() * (height / 2); // Mục tiêu phát nổ trong nửa trên màn hình
      const colors = [
        { r: 255, g: 0, b: 0 },    // Đỏ
        { r: 255, g: 255, b: 0 },  // Vàng
        { r: 0, g: 255, b: 0 },    // Xanh lá
        { r: 0, g: 0, b: 255 },    // Xanh dương
        { r: 255, g: 0, b: 255 },  // Tím
      ];
      fireworks.push(new Firework(x, targetY, colors));
    }

    function animateFireworks() {
      ctx.clearRect(0, 0, width, height);
      fireworks.forEach((firework, index) =&gt; {
        firework.update();
        firework.draw();

        if (firework.isDone()) {
          fireworks.splice(index, 1);
        }
      });

      requestAnimationFrame(animateFireworks);
    }

    // Tạo pháo hoa mới mỗi 3 giây
    setInterval(() =&gt; {
      createFirework();
    }, 3000);

    window.addEventListener('resize', () =&gt; {
      width = window.innerWidth;
      height = window.innerHeight;
      canvas.width = width;
      canvas.height = height;
    });

    animateFireworks();
  &lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>&nbsp;</p>
<p>Hiệu ứng code pháo hoa là một trong những cách thú vị để tạo điểm nhấn và tăng tính thẩm mỹ cho các trang web hoặc sự kiện đặc biệt như Tết, Giáng Sinh, hay kỷ niệm. Code pháo hoa trong bài được được thiết kế bằng HTML, CSS, và JavaScript, giúp tạo ra những vụ nổ pháo hoa sống động, nhiều màu sắc và có thể dễ dàng tích hợp vào bất kỳ dự án nào. Cảm ơn chủ website https://quaqueviet.nguyenlan.io.vn/ đã share code cho mọi người</p>
<h2>Câu hỏi thường gặp</h2>
<h3>Tôi có thể sử dụng code pháo hoa này trên website của mình không?</h3>
<p>Có, code pháo hoa được viết bằng JavaScript, HTML và CSS, tương thích với hầu hết các trình duyệt hiện đại và dễ dàng tích hợp vào website của bạn.</p>
<h3>Code pháo hoa có ảnh hưởng đến tốc độ tải trang web không?</h3>
<p>Không đáng kể. Code được tối ưu để nhẹ nhàng và không gây ảnh hưởng đến tốc độ tải trang web.</p>
<h3>Tôi có thể tùy chỉnh code pháo hoa theo ý muốn không?</h3>
<p>Có, bạn có thể tùy chỉnh màu sắc, kích thước, tần suất và hiệu ứng của pháo hoa để phù hợp với thiết kế website của mình.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://anonyviet.com/code-phao-hoa-trang-tri-cho-website-dip-tet/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Code tạo Pháo Hoa dùng HTML 5 và Javascript</title>
		<link>https://anonyviet.com/code-tao-phao-hoa-dung-html-5-va-javascript/</link>
					<comments>https://anonyviet.com/code-tao-phao-hoa-dung-html-5-va-javascript/#comments</comments>
		
		<dc:creator><![CDATA[AnonyViet]]></dc:creator>
		<pubDate>Fri, 29 Jan 2016 03:59:49 +0000</pubDate>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[fire]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[pháo hoa]]></category>
		<category><![CDATA[script]]></category>
		<guid isPermaLink="false">http://anonyviet.com/?p=1588</guid>

					<description><![CDATA[Hôm nay mình sẽ đem đến cho các bạn thêm một ít kiến thức về sử dụng HTML5 và Javascript . Hôm nay mình sẽ hướng dẫn cho các bạn cách làm hiệu ứng bắn pháo hoa rất đẹp mắt để trang trí Website cho bạn vào ngày tết, đặc biệt khi click chuột sẽ có hiệu ứng đi kèm. [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Hôm nay mình sẽ đem đến cho các bạn thêm một ít kiến thức về sử dụng <strong>HTML5</strong> và <strong>Javascript</strong> . Hôm nay mình sẽ hướng dẫn cho các bạn cách làm hiệu ứng bắn pháo hoa rất đẹp mắt để trang trí Website cho bạn vào ngày tết, đặc biệt khi click chuột sẽ có hiệu ứng đi kèm. Qua bài viết này, hi vọng các bạn sẽ nắm thêm 1 phần kiến thức về HTML5 Canvas.</p>
<p>Bạn có thể xem trước bản <span style="font-size: 14pt;"><a href="https://anonyviet.com/resource/phaohoa2/index.html" target="_blank">Demo tại đây</a></span></p>
<p><strong>     Các bạn tạo ra 3 file:</strong> <span style="color: #0000ff;">index.html</span>, <span style="color: #0000ff;">style.css</span>, <span style="color: #0000ff;">script.js</span> theo nội dung bên dưới, lưu vào cùng thư mục. Hoặc đơn giản tải <strong><a href="http://adf.ly/1WKa2f" target="_blank" rel="noopener">file này</a></strong> xuống đã có sẵn code.</p>
<p><a href="https://anonyviet.com/wp-content/uploads/2016/01/canvas-fireworks-tutorial.jpg" rel="attachment wp-att-1590"><img decoding="async" class="aligncenter size-full " src="https://anonyviet.com/wp-content/uploads/2016/01/canvas-fireworks-tutorial.jpg" alt="canvas-fireworks-tutorial" width="400" height="270" title="Code tạo Pháo Hoa dùng HTML 5 và Javascript 4"></a></p>
<p><span style="color: #ff0000;"><strong>Bước 1:</strong></span> Tạo 1 file<span style="color: #0000ff;"> index.html</span> với nội dung</p>
<pre class="lang:xhtml decode:true">&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset="utf-8" /&gt;
&lt;title&gt;Tạo hiệu ứng bắn pháo hoa bằng HTML5 và Javascript&lt;/title&gt;
&lt;link rel="icon" href="https://anonyviet.com/resource/phaohoa2/favicon.ico" type="image/x-ico"/&gt;

&lt;link href="style.css" rel="stylesheet" /&gt;

&lt;/head&gt;
&lt;body&gt;

&lt;div id="info"&gt;
	&lt;p style="color:#e1e1b8;" &gt;&lt;b&gt;Tạo hiệu ứng bắn pháo hoa bằng HTML5 và Javascript&lt;/b&gt;&lt;/p&gt;
	&lt;p&gt;Hãy thử tìm hiểu và áp dụng ngay cho website của mình để cùng chào đón tết nguyên đán nha các bạn. &lt;a href="https://anonyviet.com/code-tao-phao-hoa-dung-html-5-va-javascript/"&gt;Xem Cách Làm&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;

&lt;canvas id="canvas"&gt;Canvas không hổ trợ trình duyệt của bạn.&lt;/canvas&gt;
&lt;script type="text/javascript" src="script.js"&gt; &lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p><strong><span style="color: #ff0000;">Bước 2:</span> </strong>Tạo 1 file CSS đặt tên là <span style="color: #0000ff;">style.css</span> với  nội dung:</p>
<pre class="lang:xhtml decode:true ">#info {
	background:#333;
	opacity:0.8;
	position: absolute;
	top:5px;
	right:5px;
	width:280px;
	color:#fff;
	border-radius: 5px;
	z-index:10
	
}

#info p {
   padding:0 10px;
}

#info a{ color:#f2ea0a; }

/* basic styles for black background and crosshair cursor */
body {
	background: #000;
	margin: 0;
}

canvas {
	cursor: crosshair;
	display: block;
}</pre>
<p><span style="color: #ff0000;"><strong>Bước 3: </strong></span>Tạo file <span style="color: #0000ff;">script.js</span> với nội dung (Đây là file quan trọng tạo ra pháo hoa)</p>
<pre class="lang:js decode:true ">// when animating on canvas, it is best to use requestAnimationFrame instead of setTimeout or setInterval
// not supported in all browsers though and sometimes needs a prefix, so we need a shim
window.requestAnimFrame = ( function() {
	return window.requestAnimationFrame ||
				window.webkitRequestAnimationFrame ||
				window.mozRequestAnimationFrame ||
				function( callback ) {
					window.setTimeout( callback, 1000 / 60 );
				};
})();

// now we will setup our basic variables for the demo
var canvas = document.getElementById( 'canvas' ),
		ctx = canvas.getContext( '2d' ),
		// full screen dimensions
		cw = window.innerWidth,
		ch = window.innerHeight,
		// firework collection
		fireworks = [],
		// particle collection
		particles = [],
		// starting hue
		hue = 120,
		// when launching fireworks with a click, too many get launched at once without a limiter, one launch per 5 loop ticks
		limiterTotal = 5,
		limiterTick = 0,
		// this will time the auto launches of fireworks, one launch per 80 loop ticks
		timerTotal = 80,
		timerTick = 0,
		mousedown = false,
		// mouse x coordinate,
		mx,
		// mouse y coordinate
		my;
		
// set canvas dimensions
canvas.width = cw;
canvas.height = ch;

// now we are going to setup our function placeholders for the entire demo

// get a random number within a range
function random( min, max ) {
	return Math.random() * ( max - min ) + min;
}

// calculate the distance between two points
function calculateDistance( p1x, p1y, p2x, p2y ) {
	var xDistance = p1x - p2x,
			yDistance = p1y - p2y;
	return Math.sqrt( Math.pow( xDistance, 2 ) + Math.pow( yDistance, 2 ) );
}

// create firework
function Firework( sx, sy, tx, ty ) {
	// actual coordinates
	this.x = sx;
	this.y = sy;
	// starting coordinates
	this.sx = sx;
	this.sy = sy;
	// target coordinates
	this.tx = tx;
	this.ty = ty;
	// distance from starting point to target
	this.distanceToTarget = calculateDistance( sx, sy, tx, ty );
	this.distanceTraveled = 0;
	// track the past coordinates of each firework to create a trail effect, increase the coordinate count to create more prominent trails
	this.coordinates = [];
	this.coordinateCount = 3;
	// populate initial coordinate collection with the current coordinates
	while( this.coordinateCount-- ) {
		this.coordinates.push( [ this.x, this.y ] );
	}
	this.angle = Math.atan2( ty - sy, tx - sx );
	this.speed = 2;
	this.acceleration = 1.05;
	this.brightness = random( 50, 70 );
	// circle target indicator radius
	this.targetRadius = 1;
}

// update firework
Firework.prototype.update = function( index ) {
	// remove last item in coordinates array
	this.coordinates.pop();
	// add current coordinates to the start of the array
	this.coordinates.unshift( [ this.x, this.y ] );
	
	// cycle the circle target indicator radius
	if( this.targetRadius &lt; 8 ) {
		this.targetRadius += 0.3;
	} else {
		this.targetRadius = 1;
	}
	
	// speed up the firework
	this.speed *= this.acceleration;
	
	// get the current velocities based on angle and speed
	var vx = Math.cos( this.angle ) * this.speed,
			vy = Math.sin( this.angle ) * this.speed;
	// how far will the firework have traveled with velocities applied?
	this.distanceTraveled = calculateDistance( this.sx, this.sy, this.x + vx, this.y + vy );
	
	// if the distance traveled, including velocities, is greater than the initial distance to the target, then the target has been reached
	if( this.distanceTraveled &gt;= this.distanceToTarget ) {
		createParticles( this.tx, this.ty );
		// remove the firework, use the index passed into the update function to determine which to remove
		fireworks.splice( index, 1 );
	} else {
		// target not reached, keep traveling
		this.x += vx;
		this.y += vy;
	}
}

// draw firework
Firework.prototype.draw = function() {
	ctx.beginPath();
	// move to the last tracked coordinate in the set, then draw a line to the current x and y
	ctx.moveTo( this.coordinates[ this.coordinates.length - 1][ 0 ], this.coordinates[ this.coordinates.length - 1][ 1 ] );
	ctx.lineTo( this.x, this.y );
	ctx.strokeStyle = 'hsl(' + hue + ', 100%, ' + this.brightness + '%)';
	ctx.stroke();
	
	ctx.beginPath();
	// draw the target for this firework with a pulsing circle
	ctx.arc( this.tx, this.ty, this.targetRadius, 0, Math.PI * 2 );
	ctx.stroke();
}

// create particle
function Particle( x, y ) {
	this.x = x;
	this.y = y;
	// track the past coordinates of each particle to create a trail effect, increase the coordinate count to create more prominent trails
	this.coordinates = [];
	this.coordinateCount = 5;
	while( this.coordinateCount-- ) {
		this.coordinates.push( [ this.x, this.y ] );
	}
	// set a random angle in all possible directions, in radians
	this.angle = random( 0, Math.PI * 2 );
	this.speed = random( 1, 10 );
	// friction will slow the particle down
	this.friction = 0.95;
	// gravity will be applied and pull the particle down
	this.gravity = 1;
	// set the hue to a random number +-20 of the overall hue variable
	this.hue = random( hue - 20, hue + 20 );
	this.brightness = random( 50, 80 );
	this.alpha = 1;
	// set how fast the particle fades out
	this.decay = random( 0.015, 0.03 );
}

// update particle
Particle.prototype.update = function( index ) {
	// remove last item in coordinates array
	this.coordinates.pop();
	// add current coordinates to the start of the array
	this.coordinates.unshift( [ this.x, this.y ] );
	// slow down the particle
	this.speed *= this.friction;
	// apply velocity
	this.x += Math.cos( this.angle ) * this.speed;
	this.y += Math.sin( this.angle ) * this.speed + this.gravity;
	// fade out the particle
	this.alpha -= this.decay;
	
	// remove the particle once the alpha is low enough, based on the passed in index
	if( this.alpha &lt;= this.decay ) {
		particles.splice( index, 1 );
	}
}

// draw particle
Particle.prototype.draw = function() {
	ctx. beginPath();
	// move to the last tracked coordinates in the set, then draw a line to the current x and y
	ctx.moveTo( this.coordinates[ this.coordinates.length - 1 ][ 0 ], this.coordinates[ this.coordinates.length - 1 ][ 1 ] );
	ctx.lineTo( this.x, this.y );
	ctx.strokeStyle = 'hsla(' + this.hue + ', 100%, ' + this.brightness + '%, ' + this.alpha + ')';
	ctx.stroke();
}

// create particle group/explosion
function createParticles( x, y ) {
	// increase the particle count for a bigger explosion, beware of the canvas performance hit with the increased particles though
	var particleCount = 30;
	while( particleCount-- ) {
		particles.push( new Particle( x, y ) );
	}
}

// main demo loop
function loop() {
	// this function will run endlessly with requestAnimationFrame
	requestAnimFrame( loop );
	
	// increase the hue to get different colored fireworks over time
	hue += 0.5;
	
	// normally, clearRect() would be used to clear the canvas
	// we want to create a trailing effect though
	// setting the composite operation to destination-out will allow us to clear the canvas at a specific opacity, rather than wiping it entirely
	ctx.globalCompositeOperation = 'destination-out';
	// decrease the alpha property to create more prominent trails
	ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
	ctx.fillRect( 0, 0, cw, ch );
	// change the composite operation back to our main mode
	// lighter creates bright highlight points as the fireworks and particles overlap each other
	ctx.globalCompositeOperation = 'lighter';
	
	// loop over each firework, draw it, update it
	var i = fireworks.length;
	while( i-- ) {
		fireworks[ i ].draw();
		fireworks[ i ].update( i );
	}
	
	// loop over each particle, draw it, update it
	var i = particles.length;
	while( i-- ) {
		particles[ i ].draw();
		particles[ i ].update( i );
	}
	
	// launch fireworks automatically to random coordinates, when the mouse isn't down
	if( timerTick &gt;= timerTotal ) {
		if( !mousedown ) {
			// 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
			fireworks.push( new Firework( cw / 2, ch, random( 0, cw ), random( 0, ch / 2 ) ) );
			timerTick = 0;
		}
	} else {
		timerTick++;
	}
	
	// limit the rate at which fireworks get launched when mouse is down
	if( limiterTick &gt;= limiterTotal ) {
		if( mousedown ) {
			// start the firework at the bottom middle of the screen, then set the current mouse coordinates as the target
			fireworks.push( new Firework( cw / 2, ch, mx, my ) );
			limiterTick = 0;
		}
	} else {
		limiterTick++;
	}
}

// mouse event bindings
// update the mouse coordinates on mousemove
canvas.addEventListener( 'mousemove', function( e ) {
	mx = e.pageX - canvas.offsetLeft;
	my = e.pageY - canvas.offsetTop;
});

// toggle mousedown state and prevent canvas from being selected
canvas.addEventListener( 'mousedown', function( e ) {
	e.preventDefault();
	mousedown = true;
});

canvas.addEventListener( 'mouseup', function( e ) {
	e.preventDefault();
	mousedown = false;
});

// once the window loads, we are ready for some fireworks!
window.onload = loop;
</pre>
<p>Các đoạn script trên, đều có chú thích từng bước cụ thể ở từng phần, nếu bạn muốn chỉnh sửa thêm bơt code có thể đọc chú thích để tham khảo. Điều quan trọng là đoạn script này các bạn phải đặt bên dưới thẻ <strong>&lt;body&gt;</strong> nhé</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://anonyviet.com/code-tao-phao-hoa-dung-html-5-va-javascript/feed/</wfw:commentRss>
			<slash:comments>15</slash:comments>
		
		
			</item>
		<item>
		<title>Code Tạo Pháo Hoa Cho Website Trang Trí Tết</title>
		<link>https://anonyviet.com/code-tao-phao-hoa-cho-website-trang-tri-tet/</link>
					<comments>https://anonyviet.com/code-tao-phao-hoa-cho-website-trang-tri-tet/#comments</comments>
		
		<dc:creator><![CDATA[AnonyViet]]></dc:creator>
		<pubDate>Wed, 27 Jan 2016 13:51:10 +0000</pubDate>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mã]]></category>
		<category><![CDATA[pháo hoa]]></category>
		<guid isPermaLink="false">http://anonyviet.com/?p=1569</guid>

					<description><![CDATA[   Ngày tết gần đến rồi, ắt hẵn những bạn làm Webiste đều muốn trang trí cho ngôi nhà thứ 2 của mình thêm lộng lẫy lung linh huyền ảo. Hôm này mình sẽ hướng dẫn cho các bạn cách tạo pháo hoa để tạo không khí tết cho Webiste nhé. Bước 1: Trước tiên [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><strong>   Ngày tết gần đến rồi, ắt hẵn những bạn làm Webiste đều muốn trang trí cho ngôi nhà thứ 2 của mình thêm lộng lẫy lung linh huyền ảo. Hôm này mình sẽ hướng dẫn cho các bạn cách tạo pháo hoa để tạo không khí tết cho Webiste nhé.</strong></p>
<p><span style="text-decoration: underline;"><span style="color: #0000ff;"><strong>Bước 1:</strong></span></span> Trước tiên bạn cần tạo 1 file tên phaohoa.js, nội dung code copy ở dưới nhé (có thể dùng notepad). Rồi up lên Hosting</p>
<p>Hoặc bạn có thể tải về theo link: <a href="https://anonyviet.com/resource/phaohoa/phaohoa.js" target="_blank" rel="noopener noreferrer">https://anonyviet.com/resource/phaohoa/phaohoa.js</a></p>
<pre class="lang:default decode:true">// &lt;![CDATA[
var bits=80; // how many bits
var speed=33; // how fast - smaller is faster
var bangs=5; // how many can be launched simultaneously (note that using too many can slow the script down)
var colours=new Array("#03f", "#f03", "#0e0", "#93f", "#0cf", "#f93", "#f0c"); 
//                     blue    red     green   purple  cyan    orange  pink

/****************************
*      Fireworks Effect     *
*(c)2004-14 mf2fm web-design*
*  http://www.mf2fm.com/rv  *
* DON'T EDIT BELOW THIS BOX *
****************************/
var bangheight=new Array();
var intensity=new Array();
var colour=new Array();
var Xpos=new Array();
var Ypos=new Array();
var dX=new Array();
var dY=new Array();
var stars=new Array();
var decay=new Array();
var swide=1000;
var shigh=600;
var boddie;

if (typeof('addRVLoadEvent')!='function') function addRVLoadEvent(funky) {
  var oldonload=window.onload;
  if (typeof(oldonload)!='function') window.onload=funky;
  else window.onload=function() {
    if (oldonload) oldonload();
    funky();
  }
}

addRVLoadEvent(light_blue_touchpaper);

function light_blue_touchpaper() { if (document.getElementById) {
  var i;
  boddie=document.createElement("div");
  boddie.style.position="fixed";
  boddie.style.top="0px";
  boddie.style.left="0px";
  boddie.style.overflow="visible";
  boddie.style.zIndex = '9999';
  boddie.style.width="1px";
  boddie.style.height="1px";
  boddie.style.backgroundColor="transparent";
  document.body.appendChild(boddie);
  set_width();
  for (i=0; i&lt;bangs; i++) {
    write_fire(i);
    launch(i);
    setInterval('stepthrough('+i+')', speed);
  }
}}

function write_fire(N) {
  var i, rlef, rdow;
  stars[N+'r']=createDiv('|', 12);
  boddie.appendChild(stars[N+'r']);
  for (i=bits*N; i&lt;bits+bits*N; i++) {
    stars[i]=createDiv('*', 13);
    boddie.appendChild(stars[i]);
  }
}

function createDiv(char, size) {
  var div=document.createElement("div");
  div.style.font=size+"px monospace";
  div.style.position="absolute";
  div.style.zIndex = '9999';
  div.style.backgroundColor="transparent";
  div.appendChild(document.createTextNode(char));
  return (div);
}

function launch(N) {
  colour[N]=Math.floor(Math.random()*colours.length);
  Xpos[N+"r"]=swide*0.5;
  Ypos[N+"r"]=shigh-5;
  bangheight[N]=Math.round((0.5+Math.random())*shigh*0.4);
  dX[N+"r"]=(Math.random()-0.5)*swide/bangheight[N];
  if (dX[N+"r"]&gt;1.25) stars[N+"r"].firstChild.nodeValue="/";
  else if (dX[N+"r"]&lt;-1.25) stars[N+"r"].firstChild.nodeValue="\\";
  else stars[N+"r"].firstChild.nodeValue="|";
  stars[N+"r"].style.color=colours[colour[N]];
}

function bang(N) {
  var i, Z, A=0;
  for (i=bits*N; i&lt;bits+bits*N; i++) { 
    Z=stars[i].style;
    Z.left=Xpos[i]+"px";
    Z.top=Ypos[i]+"px";
    if (decay[i]) decay[i]--;
    else A++;
    if (decay[i]==15) Z.fontSize="7px";
    else if (decay[i]==7) Z.fontSize="2px";
    else if (decay[i]==1) Z.visibility="hidden";
	if (decay[i]&gt;1 &amp;&amp; Math.random()&lt;.1) {
	   Z.visibility="hidden";
	   setTimeout('stars['+i+'].style.visibility="visible"', speed-1);
	}
    Xpos[i]+=dX[i];
    Ypos[i]+=(dY[i]+=1.25/intensity[N]);

  }
  if (A!=bits) setTimeout("bang("+N+")", speed);
}

function stepthrough(N) { 
  var i, M, Z;
  var oldx=Xpos[N+"r"];
  var oldy=Ypos[N+"r"];
  Xpos[N+"r"]+=dX[N+"r"];
  Ypos[N+"r"]-=4;
  if (Ypos[N+"r"]&lt;bangheight[N]) {
    M=Math.floor(Math.random()*3*colours.length);
    intensity[N]=5+Math.random()*4;
    for (i=N*bits; i&lt;bits+bits*N; i++) {
      Xpos[i]=Xpos[N+"r"];
      Ypos[i]=Ypos[N+"r"];
      dY[i]=(Math.random()-0.5)*intensity[N];
      dX[i]=(Math.random()-0.5)*(intensity[N]-Math.abs(dY[i]))*1.25;
      decay[i]=16+Math.floor(Math.random()*16);
      Z=stars[i];
      if (M&lt;colours.length) Z.style.color=colours[i%2?colour[N]:M];
      else if (M&lt;2*colours.length) Z.style.color=colours[colour[N]];
      else Z.style.color=colours[i%colours.length];
      Z.style.fontSize="13px";
      Z.style.visibility="visible";
    }
    bang(N);
    launch(N);
  }
  stars[N+"r"].style.left=oldx+"px";
  stars[N+"r"].style.top=oldy+"px";
} 

window.onresize=set_width;
function set_width() {
  var sw_min=999999;
  var sh_min=999999;
  if (document.documentElement &amp;&amp; document.documentElement.clientWidth) {
    if (document.documentElement.clientWidth&gt;0) sw_min=document.documentElement.clientWidth;
    if (document.documentElement.clientHeight&gt;0) sh_min=document.documentElement.clientHeight;
  }
  if (typeof(self.innerWidth)!="undefined" &amp;&amp; self.innerWidth) {
    if (self.innerWidth&gt;0 &amp;&amp; self.innerWidth&lt;sw_min) sw_min=self.innerWidth;
    if (self.innerHeight&gt;0 &amp;&amp; self.innerHeight&lt;sh_min) sh_min=self.innerHeight;
  }
  if (document.body.clientWidth) {
    if (document.body.clientWidth&gt;0 &amp;&amp; document.body.clientWidth&lt;sw_min) sw_min=document.body.clientWidth;
    if (document.body.clientHeight&gt;0 &amp;&amp; document.body.clientHeight&lt;sh_min) sh_min=document.body.clientHeight;
  }
  if (sw_min==999999 || sh_min==999999) {
    sw_min=800;
    sh_min=600;
  }
  swide=sw_min;
  shigh=sh_min;
}
// ]]&gt;</pre>
<p>&nbsp;</p>
<p><strong><span style="text-decoration: underline; color: #0000ff;">Bước 2</span>: </strong>Chèn đoạn code dưới đây vào dưới thẻ <span style="color: #0000ff;"><strong>&lt;body&gt;</strong></span> của trang Web</p>
<p><strong><span style="color: #ff0000;">Lưu ý:</span><code> </code></strong><span style="color: #0000ff;"><code><strong>src="http://websitecuaban.com/phaohoa.js"</strong></code><span style="color: #000000;">đây là đường dẫn của file phaohoa.js mà bạn up lên Website, nhớ thay đường dẫn cho đúng nhé.</span></span></p>
<pre class="lang:default decode:true">&lt;script src="http://websitecuaban.com/phaohoa.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
var bgBegin = 22;
var bgEnd = 31;
var bgTetId = 31;
var bgTetUrl = '/banner/';
document.body.style.backgroundImage = 'url(' + bgTetUrl + bgTetId + '.jpg)';
document.body.style.backgroundAttachment = 'fixed';
document.body.style.backgroundSize = 'cover';
setInterval(function(){
	if (bgTetId == bgEnd) bgTetId = bgBegin;
	document.body.style.backgroundImage = 'url(' + bgTetUrl + bgTetId + '.jpg)';
	document.body.style.backgroundAttachment = 'fixed';
	document.body.style.backgroundSize = 'cover';
	bgTetId++;
}, 15000);
&lt;/script&gt;</pre>
<p>Bây giờ bạn có thể mở lại Website và <span style="color: #0000ff;"><strong>nhấn F5 để refresh</strong></span> và thưởng thức nhé</p>
<p><em>Bạn có thể xem làm Website có ruồi chạy tại <a href="https://anonyviet.com/huong-dan-tao-ruoi-chay-tren-website/" target="_blank" rel="noopener noreferrer">bài này</a></em></p>
]]></content:encoded>
					
					<wfw:commentRss>https://anonyviet.com/code-tao-phao-hoa-cho-website-trang-tri-tet/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
	</channel>
</rss>
