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.

            
              
<p class="f">
  <a target="_blank" href="http://www.jeremieboulay.fr">@Jeremboo</a>
  <br /> ┗|`O´|┛
</p>

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" style="display: none">
  <defs>
    <filter id="goo">
      <feGaussianBlur in="SourceGraphic" stdDeviation="8" result="blur" />
      <feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 60 -9"/>
    </filter>
  </defs>
</svg>

            
          
!
            
              // INIT
mainColor = #7CB518
secondaryColor = #F3DE2C
bgColor = #5C8001

body, html, #fire
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden
  background-color: bgColor
  margin: 0
  font-family: Century Gothic,CenturyGothic,AppleGothic,sans-serif

.f
  position: fixed
  bottom: 5px
  right: 15px
  font-family: 'Arial'
  font-size: 0.7rem
  color: mainColor
  text-align: center;

  a
    font-size: 0.8rem
    color: secondaryColor


.Fire-canvas
  position: absolute;
  top: 0;
  left: 0;
  filter: url("#goo")

            
          
!
            
              
const AMPL = 0.1;
const ROT = 0.75;
let fireElement = false;
let windowWidth = window.innerWidth;
let windowHeight = window.innerHeight;
let mouseX = windowWidth * 0.5;
let mouseY = windowHeight - 50;
const recordMousePosition = e => {
  mouseX = e.x;
  mouseY = e.y;
};

window.addEventListener('mousemove', recordMousePosition);
window.addEventListener('touchmove', recordMousePosition);
window.onresize = () => {
  windowWidth = window.innerWidth;
  windowHeight = window.innerHeight;
};

// UTILS
const getRandomFloat = (min, max) => (Math.random() * (max - min) + min);
const createCanvas = (width = window.innerWidth, height = window.innerHeight) => {
  const canvas = document.createElement('canvas');
  canvas.width = width;
  canvas.height = height;
  const context = canvas.getContext('2d');
  return {
    canvas,
    context,
    imageData: context.getImageData(0, 0, width, height),
  };
};

const Ball = (context, maxSize = 30, x = 15, y = 15, color = '#ff0000') => {
  let r = 0;
  let isDied = false;
  let rMax = maxSize * Math.random();
  const angle = Math.PI * 2 * getRandomFloat(ROT - AMPL, ROT + AMPL);
  const vel = rMax * 0.025;
  const vx = Math.cos(angle) * ((maxSize - rMax) * 0.4) * 0.2;
  const vy = Math.sin(angle) * ((maxSize - rMax) * 0.4) * 0.2;

  return {
    isDied,
    update: () => {
      x += vx;
      y += vy;
      rMax -= vel;
      r += (rMax - r) * 0.2;
      if (r <= 0.2) {
        r = 0.1;
        isDied = true;
      }
    },
    render: () => {
      context.fillStyle = color;
      context.beginPath();
      context.arc(x, y, r, 0, Math.PI * 2, false);
      context.fill();
    },
  };
};

const Balls = (color = '#ff0000', size = 30) => {
  let balls = [];
  const { canvas, context } = createCanvas();
  canvas.classList.add('Fire-canvas');
  fireElement.appendChild(canvas);

  return {
    update: () => {
      canvas.width = windowWidth;
      canvas.height = windowHeight;
      context.clearRect(0, 0, windowWidth, windowHeight);

      if (Math.random() > 0.5) {
        balls.push(new Ball(context, size, mouseX, mouseY - (size * 0.5), color));
      }

      let i;
      const length = balls.length;
      for (i = 0; i < length; i++) {
        balls[i].update();
        balls[i].render();
      }
      balls = balls.filter(b => (!b.isDied));
    },
  };
};

const Fire = (size = 100) => {
  fireElement = document.createElement('div');
  fireElement.id = 'fire';
  fireElement.className = 'Fire';
  document.body.appendChild(fireElement);

  const f1 = new Balls('#F3DE2C', size);
  const f2 = new Balls('#FAA300', size * 0.5);
  const f3 = new Balls('#FB6107', size * 0.15);

  return {
    update: () => {
      f1.update();
      f2.update();
      f3.update();
    },
  };
};

const fire = new Fire();

/* ---- CREATING ZONE END ---- */
/**/ /* ---- LOOP ---- */
/**/ function _loop(){
/**/   fire.update();
/**/ 	 requestAnimationFrame(_loop);
/**/ }
/**/ _loop();
/**/ /* ---- LOOP END ---- */

            
          
!
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