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.

+ 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.

            
              <div class="title">
    <h3>A N O T H E R <strong>C O D E P E N</strong></h3>
  </div>
  <div class="more-pens">
    <a target="_blank" href="https://codepen.io/plasm/" class="white-mode">VIEW OTHER PENS</a>
    <a target="_blank" href="https://codepen.io/collection/nZpPbz/" class="white-mode">VIEW OTHER PARTICLES</a>
  </div>
            
          
!
            
              
@import url('https://fonts.googleapis.com/css?family=Montserrat:200,300,400,600')

.more-pens
  position: fixed
  left: 20px
  bottom: 20px
  z-index: 10
  font-family: "Montserrat"
  font-size: 12px

a.white-mode, a.white-mode:link, a.white-mode:visited, a.white-mode:active
  font-family: "Montserrat"
  font-size: 12px
  text-decoration: none
  background: #212121
  padding: 4px 8px
  color: #f7f7f7
  &:hover
    background: #edf3f8
    color: #212121

body
  margin: 0
  padding: 0
  overflow: hidden
  width: 100%
  height: 100%
  background: #111111


.title
  z-index: 10
  position: absolute
  left: 50%
  top: 50%
  height: 250px
  transform: translateX(-50%) translateY(-50%)
  font-family: "Montserrat"
  text-align: center
  width: 100%


  h3
    position: absolute
    bottom: 0
    width: 100%
    text-align: center
    font-weight: 200
    font-size: 20px
    padding: 0
    margin: 0
    line-height: 1
    color: #EEEEEE
    letter-spacing: 2px

            
          
!
            
              let particles = [];
let frequency = 20
// Popolate particles
setInterval(
  function(){
    popolate()
  }.bind(this),
  frequency
)

let c1 = createCanvas({width: $(window).width(), height: $(window).height()})
let c2 = createCanvas({width: $(window).width(), height: $(window).height()})
let c3 = createCanvas({width: $(window).width(), height: $(window).height()})

let tela   = c1.canvas;
let canvas = c1.context;

// $("body").append(tela);
$("body").append(c3.canvas);
writeText(c2.canvas, c2.context, "PARTICLES\nWRITE\nTEXT")


class Particle{
  constructor(canvas, options){
    let random = Math.random()
    this.canvas = canvas;
    this.x = options.x
    this.y = options.y
    this.s = (3 + Math.random());
    this.a = 0
    this.w = $(window).width()
    this.h = $(window).height()
    this.radius = 0.5 + Math.random()*20
    this.color  = this.radius > 5 ? "#FF5E4C" : "#ED413C" //this.randomColor()
  }

  randomColor() {
    let colors = ["#FF5E4C", "#FFFFFF"];
    return colors[this.randomIntFromInterval(0,colors.length-1)];
  }

  randomIntFromInterval(min,max){
      return Math.floor(Math.random()*(max-min+1)+min);
  }

  render(){
    this.canvas.beginPath();
    this.canvas.arc(this.x, this.y, this.radius, 0, 2 * Math.PI);
    this.canvas.lineWidth = 2;
    this.canvas.fillStyle = this.color;
    this.canvas.fill();
    this.canvas.closePath();
  }

  move(){
    //this.swapColor()
    this.x += Math.cos(this.a) * this.s;
    this.y += Math.sin(this.a) * this.s;
    this.a += Math.random() * 0.8 - 0.4;

    if(this.x < 0 || this.x > this.w - this.radius){
      return false
    }

    if(this.y < 0 || this.y > this.h - this.radius){
      return false
    }
    this.render()
    return true
  }
}

function createCanvas(properties){
  let canvas = document.createElement('canvas');
      canvas.width = properties.width;
      canvas.height = properties.height;
  let context = canvas.getContext('2d');
  return {
    canvas: canvas,
    context: context
  }
}

function writeText(canvas, context, text){
  let size = 100
  context.font = size + "px Montserrat";
  context.fillStyle = "#111111";
  context.textAlign = "center";
  let lineheight = 70
  let lines = text.split('\n');
  for(let i = 0; i<lines.length; i++){
    context.fillText(lines[i], canvas.width/2, canvas.height/2 + lineheight*i - (lineheight*(lines.length-1))/3);
  }
}

function maskCanvas(){
  c3.context.drawImage(c2.canvas, 0, 0, c2.canvas.width, c2.canvas.height);
  c3.context.globalCompositeOperation = 'source-atop';
  c3.context.drawImage(c1.canvas, 0, 0);
  blur(c1.context,c1.canvas, 2)
}

function blur(ctx,canvas, amt) {
  ctx.filter = `blur(${amt}px)`
  ctx.drawImage(canvas, 0, 0)
  ctx.filter = 'none'
}


/*
 * Function to clear layer canvas
 * @num:number number of particles
 */
function popolate(){
  particles.push(
    new Particle(canvas,{
      x: ($(window).width()/2),
      y: ($(window).height()/2)
    })
  )
  return particles.length
}

function clear(){
  canvas.globalAlpha=0.03;
  canvas.fillStyle='#111111';
  canvas.fillRect(0, 0, tela.width, tela.height);
  canvas.globalAlpha=1;
}

function update(){
  clear();
  particles = particles.filter(function(p) {
    return p.move()
  })
  maskCanvas()
  requestAnimationFrame(update.bind(this))
}

update()

            
          
!
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.
Loading ..................

Console