cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              .edblock
  %textarea#editor
  .presets
    .btn#preRain
      .fa.fa-tint
    .btn#preFire
      .fa.fa-fire
    .btn#preGlow
      .fa.fa-bug
    .btn#preStar
      .fa.fa-star
    .btn#preSnow
      .span{'style':'font-size:1.5em'}❄
%canvas#field
            
          
!
            
              body{background:black;overflow:hidden;}
.pageBKG{
  z-index:-1;
  display:block;position:absolute;
  left:0;right:0;top:0;bottom:0;
  
  background-image:url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/138405/sea-and-landscape.jpg');
  background-size:cover;
}
#editor{
  display:block;position:absolute;
  width:467px;
  height:auto;
  min-height:50vh;
  left:10px;top:15px;bottom:0;
  color:#EEE;
  color:rgba(250,250,250,0.75);
  background:transparent;
  outline:none;border:none;
  resize:none;
}
.presets{
  display:flex;position:absolute;
  width:2.5em;top:-1px;
  background:rgba(250,250,250,0.1);
  right:40px;bottom:0;
  flex-direction:column;
  justify-content:flex-end;
  align-items:center;
  .btn{
    box-sizing:border-box;
    display:inline-block;
    width:2em;height:2em;
    margin:0.25em;
    text-align:center;
    line-height:1.9em;
    color:rgba(250,250,250,0.15);
    border:2px solid;
    border-radius:2em;
    background-color:transparent;
    transition:color 200ms, background-color 200ms;
    user-select:none;
    cursor:pointer;
  }
}
#preRain:hover{
  color:#FFF;
  background-color:#27F;
}
#preFire:hover{
  color:#FF4;
  background-color:#850;
}
#preGlow:hover{
  color:#AF3;
  background-color:#793;
}
#preStar:hover{
  color:#AAD;
  background-color:#101;
}
#preSnow:hover{
  color:#8FF;
  background-color:#3AA;
}
.edblock{  
  box-sizing:border-box;
  display:block;position:fixed;
  bottom:0;left:0;
  min-height:50vh;width:500px;
  background-color:rgba(0,30,40,0.5);
  transition:background-color 120ms;
  background-image:linear-gradient(45deg,
    rgba(100,150,200,0) 0%,
    rgba(100,150,200,0.05) 60%,
    rgba(100,150,200,0.1) 60%,
    rgba(100,150,200,0.1) 80%,
    rgba(100,150,200,0.05) 80%,
    rgba(100,150,200,0) 100%
  );
  border-radius:0 1px 0 0;
  border:none;
  border-top:1px solid rgba(250,250,250,0.3);
  border-right:1px solid rgba(250,250,250,0.3);
  box-shadow:
    0 0 5px #000,
    inset -10px 10px 10px -10px rgba(250,250,250,0.3);
  outline:none;
  padding:1em;color:rgba(250,250,250,0.9);
}
#editor{
  font-family:monospace;
&::-webkit-scrollbar {
  width: 5px;
}
&::-webkit-scrollbar-thumb {
  background: rgba(250,250,250,0.25);
  border-radius:2px;
}
&::-webkit-scrollbar-track {
  background: transparent;
}
}
@media screen and (max-width:550px){
  .edblock{
    display:block;
    position:fixed;
    left:0;right:0;
    width:auto;
    border-radius:0;
    box-shadow:none;
    border-right:none;
    height:50vh;
  }
  .presets{
    position:fixed;
    font-size:20px;
    left:0;right:0;
    width:auto;
    top:0;height:3em;
    flex-direction:row;
    justify-content:space-around;
  }
}
            
          
!
            
              var $editor = $('#editor');
var $field = $('#field');
var canvas = document.getElementById('field');
var ctx = canvas.getContext('2d');
var EdCon = {
  "emitters": [
    {
      "name": "rain",
      "left": 1,
      "width": $(document).width(),
      "top": -10,
      "height": 0,
      "max": 300,
      "color": 'rgba(100,150,200,0.8)',
      "likelihood":1,
      "life": 220,
      "startsize": 2,
      "fullsize": 1,
      "endsize": 0,
      "mature at": 50,
      "decay at": 99,
      "Y speed": -2,
      "X speed": 0,
      "Y velocity": -0.01,
      "X velocity": 0,
      "Y random" : 0,
      "X random" : 0,
      "lively" : 0,
      "curious" : 0
    }
  ]
};
$editor.attr("spellcheck",false);
$editor.val(JSON.stringify(EdCon,null,2));
$editor.on('change keydown paste input', function(){
  var newEdCon = JSON.parse($editor.val());
  for(it in newEdCon.emitters){
    var testTop = newEdCon.emitters[it].top.toString();
    if (testTop.indexOf('%') !== -1){
      testTop = 100/Number(testTop.slice(0, -1));
      newEdCon.emitters[it].top = $(window).innerHeight()/testTop;
    };
    var testLeft = newEdCon.emitters[it].left.toString();
    if (testLeft.indexOf('%') !== -1){
      testLeft = 100/Number(testLeft.slice(0, -1));
      newEdCon.emitters[it].left = $(window).innerWidth()/testLeft;
    };
    var testWidth = newEdCon.emitters[it].width.toString();
    if (testWidth.indexOf('%') !== -1){
      testWidth = 100/Number(testWidth.slice(0, -1));
      newEdCon.emitters[it].width = $(window).innerWidth()/testWidth;
    };
    var testHeight = newEdCon.emitters[it].height.toString();
    if (testHeight.indexOf('%') !== -1){
      testHeight = 100/Number(testHeight.slice(0, -1));
      newEdCon.emitters[it].height = $(window).innerHeight()/testHeight;
    };
  };
  EdCon = newEdCon;
  updateAllPtc();
});
$field.attr("height",$(window).innerHeight());
$field.attr("width",$(document).width());
$(window).resize(function(){
  $field.attr("height",$(window).innerHeight());
  $field.attr("width",$(document).width());
});

function freshCan(){
  ctx.fillStyle = "rgba(0,0,0,0.5)";
  if(EdCon.import){
    var newEdCon = $.getJSON(EdCon.import);
    EdCon = newEdCon;
  };
  if(EdCon.background){
    var img = new Image();
    img.src = EdCon.background;
    ctx.drawImage(img,0, 0, canvas.width, canvas.height);
  }else{
    ctx.clearRect(0, 0, canvas.width, canvas.height);
  };
  updateAllPtc();
  updateCan();
  drawCan();
  requestAnimationFrame(freshCan);
}
var allPtc = {main:[]};
updateAllPtc();
function particle(f,li,x,y,sx,sy,vx,vy,rx,ry,sb,sf,sd,ma,da,l,c,lv,cr,i){
  this.from = f || 'main';
  this.repeats = 1;
  this.repeated = 0;
  this.age = 0;
  this.perc = 0;
  this.chance = li || 0;
  this.life = l || 500;
  this.xOrig = x||0;
  this.yOrig = y||0;
  this.x = x||0;
  this.y = y||0;
  this.speedX = sx || 0;
  this.speedY = sy || -3;
  this.pSpeedX = sx || 0;
  this.pSpeedY = sy || -3;
  this.velX = vx || 0;
  this.velY = vy || -0.01;
  this.randX = rx || 0.001;
  this.randY = ry || 0;
  this.sizeA = sb || 3;
  this.sizeB = sb || 2;
  this.sizeF = sf || 3;
  this.sizeD = sd || 0;
  this.mature = ma || 30;
  this.decay = da || 70;
  this.lively = lv || 0;
  this.curious = cr || 0;
  this.color = c || "#FFFFFF";
  if(i){
    this.image = i;
  };
  var aListName = this.from;
  var actingList = allPtc[aListName];
  allPtc[this.from].push(this);
};
function updateAllPtc(){
  for(it in EdCon.emitters){
    if(!(allPtc[EdCon.emitters[it]['name']])){
      allPtc[EdCon.emitters[it]['name']] = [];
    }
  }
}
function updateCan(){
  for(it in EdCon.emitters){
    var field = EdCon.emitters[it];
    if(field.image){
      var img = new Image();
      img.src = field.image;
    };
    if(allPtc[field.name].length<field.max){
      if(field.likelihood >= Math.random()){
        var indp = new particle(field.name);
      if(field.image){
        indp.image = img;
      };
      indp.from = field.name || "main";
      indp.color = field.color || "#FFFFFF";
      indp.sizeD = field.endsize || 0;
      indp.sizeF = field.fullsize || 0;
      indp.sizeB = field.startsize || 0;
      indp.life = field.life || 0;
      indp.mature = field['mature at'] || 0;
      indp.decay = field['decay at'] || 0;
      indp.speedY = field['Y speed'] || 0;
      indp.speedX = field['X speed'] || 0;
      indp.pSpeedY = field['Y speed'] || 0;
      indp.pSpeedX = field['X speed'] || 0;
      indp.velY = field['Y velocity'] || 0;
      indp.velX = field['X velocity'] || 0;
      indp.randY = field['Y random'] || 0;
      indp.randX = field['X random'] || 0;
      indp.lively = field.lively || 0;
      indp.curious = field.curious || 0;
      indp.chance = field.likelihood || 0;
      indp.x = ((Math.random()*field.width)+field.left);
      indp.y = ((Math.random()*field.height)+field.top);
      };
    }
  }
}
function drawCan(){
  for(it in allPtc){
    var lookFor = allPtc[it];
    for(i=0;i<lookFor.length;i++){
    if(lookFor[i]['repeated']>(lookFor[i]['repeats'])-1){
      lookFor.splice(i,1);
    }else{
      drawParticle(lookFor[i]);
    };
    };
  }
};
function drawParticle(ptc){
  if(ptc.age < ptc.life){
    ptc.age++;
    ptc.perc = 100-(ptc.age/ptc.life)*100;
    ptc.x -= ptc.pSpeedX;
    ptc.y -= ptc.pSpeedY;
    var influenceCX = (Math.random()*(ptc.randX)-ptc.randX/2)*(ptc.age*ptc.curious/100);
    var influenceLX = ((Math.random()*(ptc.randX)-ptc.randX/2)/(100-ptc.perc))*ptc.lively;
    var influenceRX = (influenceCX+influenceLX);
    var influenceCY = (Math.random()*(ptc.randY)-ptc.randY/2)*(ptc.age*ptc.curious/100);
    var influenceLY = ((Math.random()*(ptc.randY)-ptc.randY/2)/(100-ptc.perc))*ptc.lively;
    var influenceRY = (influenceCY+influenceLY);
    ptc.pSpeedX += influenceRX;
    ptc.pSpeedY += influenceRY;
    ptc.pSpeedX += ptc.velX;
    ptc.pSpeedY += ptc.velY;
    var invPerc = 100-ptc.perc;
    var adjSize = ((ptc.sizeB*ptc.perc)/100)
                + ((ptc.sizeD*invPerc)/100);
    if(invPerc > ptc.mature){
      if(invPerc < ptc.decay){
        adjSize = ptc.sizeF;
      }else if(invPerc >= ptc.decay){
      var botPerc = (ptc.perc/(100-ptc.decay))*100;
      adjSize = ((ptc.sizeD*(100-botPerc))/100)
              + ((ptc.sizeF*botPerc)/100);
      };
    } else if(invPerc <= ptc.mature){
      var topPerc = (invPerc/ptc.mature)*100;
      adjSize = ((ptc.sizeB*(100-topPerc))/100)
              + ((ptc.sizeF*topPerc)/100);
    };
    if(ptc.perc == 0){adjSize = 0};
    ptc.sizeA = adjSize;
  }else{
    ptc.age=0;
    ptc.repeated++;
    ptc.x = ptc.xOrig;
    ptc.y = ptc.yOrig;
    ptc.pSpeedX = ptc.speedX;
    ptc.pSpeedY = ptc.speedY;
  }
  if(!ptc.image){
    ctx.beginPath();
    ctx.arc(ptc.x,ptc.y,ptc.sizeA,0,2*Math.PI);
    ctx.fillStyle = ptc.color;
    ctx.fill();
  }else{
    ctx.drawImage(
      ptc.image,
      (ptc.x-(ptc.sizeA/2)),
      (ptc.y-(ptc.sizeA/2)),
      ptc.sizeA,ptc.sizeA);
  }
};
$(document).ready(function(){
  freshCan();
  $('#preRain').click(function(){
    EdCon = {
  "emitters": [
    {
      "name": "rain",
      "left": 1,
      "width": $(document).width(),
      "top": -10,
      "height": 0,
      "max": 300,
      "color": 'rgba(100,150,200,0.5)',
      "likelihood":1,
      "life": 180,
      "startsize": 2,
      "fullsize": 1,
      "endsize": 0,
      "mature at": 50,
      "decay at": 99,
      "Y speed": -3,
      "X speed": 0,
      "Y velocity": -0.01,
      "X velocity": 0,
      "Y random" : 0,
      "X random" : 0,
      "lively" : 0,
      "curious" : 0
    }
  ]
};
    $editor.val(JSON.stringify(EdCon,null,2));
  });
  $('#preFire').click(function(){
    EdCon = {
  "emitters": [
    {
      "name": "flame",
      "left": (($(document).width())/2) - 5,
      "width": 10,
      "top": 200,
      "height": 0,
      "max": 100,
      "color": "rgba(200,10,0,0.5)",
      "likelihood":1,
      "life": 60,
      "startsize": 3,
      "fullsize": 10,
      "endsize": 0,
      "mature at": 15,
      "decay at": 30,
      "Y speed": 1,
      "Y velocity": -0.001,
      "X random": 4,
      "lively": 0.1,
    },
    {
      "name": "flame2",
      "left": (($(document).width())/2) - 5,
      "width": 10,
      "top": 195,
      "height": 0,
      "max": 100,
      "color": "rgba(200,170,0,0.1)",
      "likelihood":1,
      "life": 50,
      "startsize": 3,
      "fullsize": 10,
      "endsize": 0,
      "mature at": 20,
      "decay at": 30,
      "Y speed": 1,
      "Y velocity": -0.001,
      "X random": 2,
      "lively": 0.1
    },
    {
      "name": "sparks1",
      "left": (($(document).width())/2) - 5,
      "width": 10,
      "top": 195,
      "height": 0,
      "max": 100,
      "color": "rgba(230,200,0,0.3)",
      "likelihood":0.3,
      "life": 60,
      "startsize": 1,
      "fullsize": 1,
      "endsize": 0,
      "mature at": 50,
      "decay at": 70,
      "Y speed": 0.9,
      "Y velocity": -0.002,
      "X random": 1,
      "Y random": 1,
      "lively": 1,
      "curious":1
    }
  ]
};
    $editor.val(JSON.stringify(EdCon,null,2));
  });
    $('#preGlow').click(function(){
    EdCon = {
  "emitters": [
    {
      "name": "glowbugs",
      "left": 1,
      "width": $(document).width(),
      "top": 1,
      "height": $(document).height(),
      "max": 90,
      "color": 'rgba(100,150,50,0.2)',
      "likelihood":0.1,
      "life": 80,
      "startsize": 0,
      "fullsize": 2,
      "endsize": 0,
      "mature at": 30,
      "decay at": 70,
      "Y speed": 0,
      "X speed": 0,
      "Y velocity": 0,
      "X velocity": 0,
      "Y random" : 0.5,
      "X random" : 1.5,
      "lively" : 1,
      "curious" : 1
    },
    {
      "name": "glowbugs2",
      "left": 1,
      "width": $(document).width(),
      "top": 1,
      "height": $(document).height(),
      "max": 90,
      "image": 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/138405/glowbug.png',
      "likelihood":0.03,
      "life": 120,
      "startsize": 0,
      "fullsize": 10,
      "endsize": 0,
      "mature at": 30,
      "decay at": 55,
      "Y speed": 0,
      "X speed": 0,
      "Y velocity": 0,
      "X velocity": 0,
      "Y random" : 0.01,
      "X random" : 1.5,
      "lively" : 0.3,
      "curious" : 0
    }
  ]
};
    $editor.val(JSON.stringify(EdCon,null,2));
  });
  $('#preStar').click(function(){
    EdCon = {
  "emitters": [
    {
      "name": "stars",
      "left": 1,
      "width": $(document).width(),
      "top": 1,
      "height": $(document).height(),
      "max": 100,
      "color": 'rgba(250,250,250,0.5)',
      "likelihood":0.2,
      "life": 600,
      "startsize": 5,
      "fullsize": 1.5,
      "endsize": 0,
      "mature at": 2,
      "decay at": 70,
    }
  ]
};
    $editor.val(JSON.stringify(EdCon,null,2));
  });
  $('#preSnow').click(function(){
    EdCon = {
  "emitters": [
    {
      "name": "snow",
      "left": 1,
      "width": 950,
      "top": -10,
      "height": 0,
      "max": 300,
      "likelihood": 1,
      "life": 240,
      "startsize": 0.5,
      "fullsize": 1,
      "endsize": 0,
      "mature at": 30,
      "decay at": 60,
      "Y speed": -2.5,
      "X speed": 0,
      "Y velocity": 0.005,
      "X velocity": 0,
      "Y random": 0,
      "X random": 1,
      "lively": 1,
      "curious": 0.5
    },
    {
      "name": "gather",
      "left": 1,
      "width": 495,
      "top": '50%',
      "height": 0,
      "max": 500,
      "likelihood": 1,
      "life": 420,
      "startsize": 2,
      "fullsize": 2,
      "endsize": 0,
      "mature at": 30,
      "decay at": 60,
      "Y speed": 0.001,
      "X speed": 0,
      "Y velocity": 0,
      "X velocity": 0,
      "Y random": 0.1,
      "X random": 0.01,
      "lively": 0.01,
      "curious": 0
    }
  ]
};
    $editor.val(JSON.stringify(EdCon,null,2));
    $editor.change();
  });
});
            
          
!
999px
Loading ..................

Console