123

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.

            
                   
<canvas id="myCanvas"></canvas>
<button class="btn btn-danger" onclick="extinguish()">Water</button>  



            
          
!
            
              body, html {
  margin: 0;
  padding: 0;
  background: 'black';

}

canvas {
  position: absolute;
  z-index: 1;
  left: 0;
  top: 0;
  
}

#myCanvas{
  position: absolute;
  z-index: 2;
  left: 0;
  top: 0;
}

button {
  position:absolute;
  right: 0;
  z-index: 2;
}
            
          
!
            
              

// define the canvas
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var width = canvas.width = window.innerWidth;
var height = canvas.height = window.innerHeight;
var imageObj = new Image();
imageObj.onload = function() {
        context.drawImage(imageObj, 900, 50);
      };
      imageObj.src = 'https://pbs.twimg.com/profile_images/1218527213/clipartfireservicefirefighterattack_400x400.gif';


//this is ART!!
function spray(){

  //creates a fluidity to the bezier curves
var waveOne = Math.floor(Math.random()*600);
var waveTwo = Math.floor(Math.random()*10);
var waveThree = Math.floor(Math.random()*500);
var waveFour = Math.floor(Math.random()*500);
var waveFive = Math.floor(Math.random()*500);
var waveSix = Math.floor(Math.random()*500);  

//sets water stream to either white or a shade of blue  
var color;
var waterStream;  
function waterColor(){  
  var stream = Math.random();
    if (stream < .25){
         color = 'rgb(13, 26, 129)';
    }
    else if (stream < .5){
         color = 'rgb(0,0,255)';
    }
    else if (stream< .75){
         color ='rgb(71, 113, 165)';
    } 
    else{
         color = 'white';
    }
  return color; 
}
waterColor();

//makes the white steams thinner than the blues
function white(){
  if (color === 'white'){
    waterStream = 2;
  }
  else  if(color !== white){
    waterStream = Math.floor(Math.random()*15);
  }
}  
white();

// draw the curve
context.beginPath();
context.moveTo(1000, 250);
context.bezierCurveTo(waveOne, waveTwo, waveThree, waveFour, waveFive, waveSix);
context.lineWidth = waterStream;
context.strokeStyle = color;
context.stroke(); 

 };

//animation for water splashing on the ground

function splash() {
  
  var canvas = document.createElement("canvas");
      var context = canvas.getContext("2d");
      canvas.width = window.innerWidth;
      canvas.height = window.innerHeight;
      
  document.body.appendChild(canvas);

  var particles = {},
particleIndex = 0,
settings = {
            density: 200,
            particleSize: 20,
            startingX: 250,
            startingY: 300,
            gravity: 0.5,
            groundLevel: canvas.height*.75
          };

function Particle() {

        this.x = settings.startingX;
        this.y = settings.startingY;


        this.vx = Math.random() * 20 - 10;
        this.vy = Math.random() * 20 - 5;

        particleIndex ++;
        particles[particleIndex] = this;
        this.id = particleIndex;
        this.life = 0;
        this.maxLife = 100;
      }

    
      Particle.prototype.draw = function() {
        this.x += this.vx;
        this.y += this.vy;
        
       
  if ((this.y + settings.particleSize) > settings.groundLevel) {
    this.vy *= -0.6;
    this.vx *= 0.75;
    this.y = settings.groundLevel - settings.particleSize;
  }
  if (this.x - (settings.particleSize) <= settings.leftWall) {
    this.vx *= -1;
    this.x = settings.leftWall + (settings.particleSize);
  }

  if (this.x + (settings.particleSize) >= settings.rightWall) {
    this.vx *= -1;
    this.x = settings.rightWall - settings.particleSize;
  }

        this.vy += settings.gravity;
        this.life++;
        if (this.life >= this.maxLife) {
          delete particles[this.id];
        }

        // Create the splashing water
var color;
var waterStream;  
function waterColor(){  
  var stream = Math.random();
    if (stream < .25){
         color = 'rgb(13, 26, 129)';
    }
    else if (stream < .5){
         color = 'rgb(0,0,255)';
    }
    else if (stream< .75){
         color ='rgb(71, 113, 165)';
    }
    else{
      color = 'white';
    }
    
  return color; 
}
waterColor();
        
function size(){
  if (color === 'white'){
    size = Math.round(Math.random()*15);
  }
  else{
    size = Math.round(Math.random()*30);
  }
}  
size();    
        context.beginPath();
        context.fillStyle=color;
        context.arc(this.x, this.y, size, 0, Math.PI*2, true); 
        context.closePath();
        context.fill();

      }
      setInterval(function() {
        context.fillStyle = "black";
        context.fillRect(0, 0, canvas.width, canvas.height);

        // Draw the particles
        for (var i = 0; i < settings.density; i++) {
          if (Math.random() > 0.97) {
            // Introducing a random chance of creating a particle
            // corresponding to an chance of 1 per second,
            // per "density" value
            new Particle();
          }
        }
        
        for (var i in particles) {
          particles[i].draw();
        }
      }, 30);
    };

//THE FIRE!!
function blaze() {
  var canvas = document.createElement("canvas");
      var context = canvas.getContext("2d");
      canvas.width = window.innerWidth;
      canvas.height = window.innerHeight;
  document.body.appendChild(canvas);

  var particles = {},
particleIndex = 0,
settings = {
            density: 800,
            particleSize: 8,
            startingX: 250,
            startingY: 300,
            gravity: -1.5,
          };
function Particle() {
        this.x = settings.startingX;
        this.y = settings.startingY;

        this.vx = Math.random() * 20 - 10;
        this.vy = Math.random() * 20 - 5;

        particleIndex ++;
        particles[particleIndex] = this;
        this.id = particleIndex;
      }
      Particle.prototype.draw = function() {
        this.x += this.vx;
        this.y += this.vy;
        this.vy += settings.gravity;
var color; 
function fire(){  
  var flame = Math.random();
    if (flame < .25){
         color = 'rgb(255, 0, 0)';
    }
    else if (flame < .5){
         color = 'rgb(255, 255, 51)';
    }
    else if (flame< .75){
         color ='rgb(255, 128, 0)';
    }
  else{
         color = 'rgb(255, 255, 204)';
  }  
  return color; 
}
fire();
var size = Math.round(Math.random()*15);        
        context.beginPath();
        context.fillStyle=color;
        context.arc(this.x, this.y, size, 0, Math.PI*2, true); 
        context.closePath();
        context.fill();

      }
      setInterval(function() {
        context.fillStyle = "black";
        context.fillRect(0, 0, canvas.width, canvas.height);
        for (var i = 0; i < settings.density; i++) {
          if (Math.random() > 0.97) {
            new Particle();
          }
        }
        
        for (var i in particles) {
          particles[i].draw();
        }
      }, 85);
    };

//turn the water on
function extinguish(){
setInterval(function(){
  spray();
})
splash();  
};

blaze();

      

            
          
!
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