Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div id="scene">
	<div id="meteor">
		<canvas id="fire"></canvas>
	</div>
</div>
            
          
!
            
              body { 
	background-color: #000; 
}

#scene {
	animation: move 1s ease-in-out infinite;
	animation-fill-mode: forwards;
	position: absolute;
	top: 35%;
    left: 40%;
	transform: translate(-50%, -50%);
	backface-visibility: hidden;
	filter: blur(5px) contrast(100%) brightness(630%);
    border-radius: 50%;
    width: 10px;
    height: 10px;
}

#meteor {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate3d(-50%, -50%, 0) rotate(-90deg);
	backface-visibility: hidden;
	perspective: 210px;
	perspective-origin: 40px 0;
}

#meteor::before {
	content: '';
	display: block;
	position: absolute;
	bottom: 0;
	left: 50%;
	width: 130%;
	padding-bottom: 160%;
	height: 0;
	background: linear-gradient(to bottom, transparent 0%, #b96d34 100%);
    border-radius: 100px;
    transform: translate(-50%, 20%);
    box-shadow: 0 19px 0 5px #000, 0 20px 0 4.6px red;
	z-index: 1;
}

#fire { 
	background-color: #000; 
	filter: none;
	transition: filter 1s ease;
	transform: rotateX(30deg) scale3d(1,1,1) translateY(-120px);
}

@keyframes move {
	0%   { transform: rotatez(43deg) translate(2px, 1px); }  
	25%  { transform: rotatez(43deg) translate(3px, 2px); }  
	50%  { transform: rotatez(43deg) translate(2px, 1px); }  
	75%  { transform: rotatez(43deg) translate(1px, 3px); }  
	100% { transform: rotatez(43deg) translate(2px, 1px); }  
}
            
          
!
            
              const firePixels  = [];
const fireWidth   = 30;
const fireHeight  = 50;
const pixelWidth  = 3;
const pixelHeight = 10;

const elCanvas    = document.getElementById('fire');
const canvas      = elCanvas.getContext("2d");

function start() {
	defineCanvasSize();
	createFireDataStructure();
	createFireSource();
	calculateFirePropagation();	
	
	setInterval(function() {
		createFireSource();
	}, 1000);
}

function createFireDataStructure() {
	const numberOfPixels = fireWidth * fireHeight;
	
	for (let i=0; i < numberOfPixels; i++) {
		firePixels[i] = { fireIintensity: 0, windIntensity: 0 };
	}
}

function calculateFirePropagation() {
	for (let col = 0; col < fireWidth; col++) {
		for (let row = 0; row < fireHeight; row++) {
			const pixelIndex = col + (fireWidth * row);

			updateFireIntensityPerPixel(pixelIndex);
		}
	}

	
	renderFire();
	
	requestAnimationFrame(calculateFirePropagation);
}

function updateFireIntensityPerPixel(currentPixelIndex) {
	const belowPixelIndex = currentPixelIndex + fireWidth;
	
	if (belowPixelIndex >= fireWidth * fireHeight)
		return;
	
	const fireIintensityDecay = Math.floor(Math.random() * 7);
	const windIntensityDecay = Math.floor(Math.random() * 20);

	const belowPixelFireIntensity = firePixels[belowPixelIndex].fireIintensity;
	const belowPixelFireWind = firePixels[belowPixelIndex].windIntensity;

	let newFireIntensity = belowPixelFireIntensity - fireIintensityDecay;
	let newWindIntensity = 0;
	let changeIndex = 0;
	
	if (newFireIntensity <= 0) {
		newFireIntensity = 0;
	}

	if (belowPixelFireWind > 0) {
		newWindIntensity = belowPixelFireWind - windIntensityDecay;
		changeIndex = belowPixelFireWind > 10 ? 1 : 0;
	} else if (belowPixelFireWind < 0) {
		newWindIntensity = belowPixelFireWind + windIntensityDecay;
		changeIndex = belowPixelFireWind < -10 ? -2 : 0;
	}
	
	firePixels[currentPixelIndex - changeIndex] = { fireIintensity: newFireIntensity, windIntensity: newWindIntensity };
}

function defineCanvasSize() {
	elCanvas.width = fireWidth * pixelWidth;
	elCanvas.height = fireHeight * pixelHeight;
}

function createFireSource() {
	for (let col = 0; col < fireWidth; col++) {
		const overflowPixelIndex = fireWidth * fireHeight;
		const pixelIndex = (overflowPixelIndex - fireWidth) + col;
		
		const fireIintensity = Math.floor(Math.random() * (100 - 50 + 1)) + 50;
		const windIntensityDirection = Math.random() < 0.5 ? -1 : 1;
		const windIntensity = Math.floor(Math.random() * 20) * windIntensityDirection;

		firePixels[pixelIndex] = { fireIintensity: fireIintensity, windIntensity: windIntensity };
	}
}

function renderFire() {
	let x = 0;
	let y = 0;
	let index = 0;
	
  	canvas.clearRect(0,0, pixelWidth * fireWidth, pixelHeight * fireHeight);

	for (let row = 0; row < fireHeight; row++) {
		y = row * pixelHeight;
		
		for (let col = 0; col < fireWidth; col++) {
			x = col * pixelWidth;
			index = col + (fireWidth * row);

			const colorH = Math.round(firePixels[index].fireIintensity * 40 / 100);
			const colorS = 100;
			const colorL = firePixels[index].fireIintensity;
			const color = `hsl(${colorH}, ${colorS}%, ${colorL}%)`;
			
			const rotate = (firePixels[index].windIntensity) * Math.PI / 180;
			
			// Debug
			// canvas.beginPath();
			// canvas.strokeRect(x, y, pixelSize, pixelSize);

			canvas.save();
			
			canvas.beginPath();
			
			canvas.translate(x + (pixelWidth / 2), y + pixelHeight);
			canvas.rotate(rotate);
			
			canvas.moveTo(0, 0);
			canvas.lineTo(0, pixelHeight * -1);
			
			canvas.strokeStyle = color;
			canvas.lineWidth = 1;
			canvas.stroke();

			canvas.restore();
			
			canvas.beginPath();
			canvas.fillStyle = 'black';
			canvas.fillRect(0, pixelHeight * (fireHeight - 1), pixelWidth * fireWidth, pixelHeight);
		}
	}
}

start();
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console