Toggle navigation
Sign Up
Log In
Explore
Works
Folders
Tools
Collections
Artists
Groups
Groups
Topics
Tasks
Tasks
Jobs
Teams
Jobs
Recommendation
More Effects...
JS
"use strict";"object"!=typeof window.CP&&(window.CP={}),window.CP.PenTimer={programNoLongerBeingMonitored:!1,timeOfFirstCallToShouldStopLoop:0,_loopExits:{},_loopTimers:{},START_MONITORING_AFTER:2e3,STOP_ALL_MONITORING_TIMEOUT:5e3,MAX_TIME_IN_LOOP_WO_EXIT:2200,exitedLoop:function(o){this._loopExits[o]=!0},shouldStopLoop:function(o){if(this.programKilledSoStopMonitoring)return!0;if(this.programNoLongerBeingMonitored)return!1;if(this._loopExits[o])return!1;var t=this._getTime();if(0===this.timeOfFirstCallToShouldStopLoop)return this.timeOfFirstCallToShouldStopLoop=t,!1;var i=t-this.timeOfFirstCallToShouldStopLoop;if(i
this.STOP_ALL_MONITORING_TIMEOUT)return this.programNoLongerBeingMonitored=!0,!1;try{this._checkOnInfiniteLoop(o,t)}catch(o){return this._sendErrorMessageToEditor(),this.programKilledSoStopMonitoring=!0,!0}return!1},_sendErrorMessageToEditor:function(){try{if(this._shouldPostMessage()){var o={action:"infinite-loop",line:this._findAroundLineNumber()};parent.postMessage(JSON.stringify(o),"*")}else this._throwAnErrorToStopPen()}catch(o){this._throwAnErrorToStopPen()}},_shouldPostMessage:function(){return document.location.href.match(/boomerang/)},_throwAnErrorToStopPen:function(){throw"We found an infinite loop in your Pen. We've stopped the Pen from running. Please correct it or contact support@codepen.io."},_findAroundLineNumber:function(){var o=new Error,t=0;if(o.stack){var i=o.stack.match(/boomerang\S+:(\d+):\d+/);i&&(t=i[1])}return t},_checkOnInfiniteLoop:function(o,t){if(!this._loopTimers[o])return this._loopTimers[o]=t,!1;var i=t-this._loopTimers[o];if(i>this.MAX_TIME_IN_LOOP_WO_EXIT)throw"Infinite Loop found on loop: "+o},_getTime:function(){return+new Date}},window.CP.shouldStopExecution=function(o){var t=window.CP.PenTimer.shouldStopLoop(o);return t===!0&&console.warn("[CodePen]: An infinite loop (or a loop taking too long) was detected, so we stopped its execution. Sorry!"),t},window.CP.exitedLoop=function(o){window.CP.PenTimer.exitedLoop(o)}; /* Music is by The XX @see http://thexx.info This is best viewed in Chrome since there is a bug in Safari when using getByteFrequencyData with MediaElementAudioSource @see https://goo.gl/6WLx1 */ (function() { var ALPHA, AudioAnalyser, COLORS, MP3_PATH, NUM_BANDS, NUM_PARTICLES, Particle, SCALE, SIZE, SMOOTHING, SPEED, SPIN; NUM_PARTICLES = 150; NUM_BANDS = 128; SMOOTHING = 0.5; MP3_PATH = 'https://api.soundcloud.com/tracks/42328219/stream?client_id=b1495e39071bd7081a74093816f77ddb'; SCALE = { MIN: 5.0, MAX: 80.0 }; SPEED = { MIN: 0.2, MAX: 1.0 }; ALPHA = { MIN: 0.8, MAX: 0.9 }; SPIN = { MIN: 0.001, MAX: 0.005 }; SIZE = { MIN: 0.5, MAX: 1.25 }; COLORS = ['#69D2E7', '#1B676B', '#BEF202', '#EBE54D', '#00CDAC', '#1693A5', '#F9D423', '#FF4E50', '#E7204E', '#0CCABA', '#FF006F']; AudioAnalyser = (function() { AudioAnalyser.AudioContext = self.AudioContext || self.webkitAudioContext; AudioAnalyser.enabled = AudioAnalyser.AudioContext != null; function AudioAnalyser(audio, numBands, smoothing) { var src; this.audio = audio != null ? audio : new Audio(); this.numBands = numBands != null ? numBands : 256; this.smoothing = smoothing != null ? smoothing : 0.3; if (typeof this.audio === 'string') { src = this.audio; this.audio = new Audio(); this.audio.crossOrigin = "anonymous"; this.audio.controls = true; this.audio.src = src; } this.context = new AudioAnalyser.AudioContext(); this.jsNode = this.context.createScriptProcessor(2048, 1, 1); this.analyser = this.context.createAnalyser(); this.analyser.smoothingTimeConstant = this.smoothing; this.analyser.fftSize = this.numBands * 2; this.bands = new Uint8Array(this.analyser.frequencyBinCount); this.audio.addEventListener('canplay', (function(_this) { return function() { _this.source = _this.context.createMediaElementSource(_this.audio); _this.source.connect(_this.analyser); _this.analyser.connect(_this.jsNode); _this.jsNode.connect(_this.context.destination); _this.source.connect(_this.context.destination); return _this.jsNode.onaudioprocess = function() { _this.analyser.getByteFrequencyData(_this.bands); if (!_this.audio.paused) { return typeof _this.onUpdate === "function" ? _this.onUpdate(_this.bands) : void 0; } }; }; })(this)); } AudioAnalyser.prototype.start = function() { return this.audio.play(); }; AudioAnalyser.prototype.stop = function() { return this.audio.pause(); }; return AudioAnalyser; })(); Particle = (function() { function Particle(x1, y1) { this.x = x1 != null ? x1 : 0; this.y = y1 != null ? y1 : 0; this.reset(); } Particle.prototype.reset = function() { this.level = 1 + floor(random(4)); this.scale = random(SCALE.MIN, SCALE.MAX); this.alpha = random(ALPHA.MIN, ALPHA.MAX); this.speed = random(SPEED.MIN, SPEED.MAX); this.color = random(COLORS); this.size = random(SIZE.MIN, SIZE.MAX); this.spin = random(SPIN.MAX, SPIN.MAX); this.band = floor(random(NUM_BANDS)); if (random() < 0.5) { this.spin = -this.spin; } this.smoothedScale = 0.0; this.smoothedAlpha = 0.0; this.decayScale = 0.0; this.decayAlpha = 0.0; this.rotation = random(TWO_PI); return this.energy = 0.0; }; Particle.prototype.move = function() { this.rotation += this.spin; return this.y -= this.speed * this.level; }; Particle.prototype.draw = function(ctx) { var alpha, power, scale; power = exp(this.energy); scale = this.scale * power; alpha = this.alpha * this.energy * 1.5; this.decayScale = max(this.decayScale, scale); this.decayAlpha = max(this.decayAlpha, alpha); this.smoothedScale += (this.decayScale - this.smoothedScale) * 0.3; this.smoothedAlpha += (this.decayAlpha - this.smoothedAlpha) * 0.3; this.decayScale *= 0.985; this.decayAlpha *= 0.975; ctx.save(); ctx.beginPath(); ctx.translate(this.x + cos(this.rotation * this.speed) * 250, this.y); ctx.rotate(this.rotation); ctx.scale(this.smoothedScale * this.level, this.smoothedScale * this.level); ctx.moveTo(this.size * 0.5, 0); ctx.lineTo(this.size * -0.5, 0); ctx.lineWidth = 1; ctx.lineCap = 'round'; ctx.globalAlpha = this.smoothedAlpha / this.level; ctx.strokeStyle = this.color; ctx.stroke(); return ctx.restore(); }; return Particle; })(); Sketch.create({ particles: [], setup: function() { var analyser, error, i, intro, j, particle, ref, warning, x, y; for (i = j = 0, ref = NUM_PARTICLES - 1; j <= ref; i = j += 1) {if (window.CP.shouldStopExecution(1)){break;} x = random(this.width); y = random(this.height * 2); particle = new Particle(x, y); particle.energy = random(particle.band / 256); this.particles.push(particle); } window.CP.exitedLoop(1); if (AudioAnalyser.enabled) { try { analyser = new AudioAnalyser(MP3_PATH, NUM_BANDS, SMOOTHING); analyser.onUpdate = (function(_this) { return function(bands) { var k, len, ref1, results; ref1 = _this.particles; results = []; for (k = 0, len = ref1.length; k < len; k++) {if (window.CP.shouldStopExecution(2)){break;} particle = ref1[k]; results.push(particle.energy = bands[particle.band] / 256); } window.CP.exitedLoop(2); return results; }; })(this); analyser.start(); document.body.appendChild(analyser.audio); intro = document.getElementById('intro'); intro.style.display = 'none'; if (/Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent)) { warning = document.getElementById('warning2'); return warning.style.display = 'block'; } } catch (error1) { error = error1; } } else { warning = document.getElementById('warning1'); return warning.style.display = 'block'; } }, draw: function() { var j, len, particle, ref, results; this.globalCompositeOperation = 'lighter'; ref = this.particles; results = []; for (j = 0, len = ref.length; j < len; j++) {if (window.CP.shouldStopExecution(3)){break;} particle = ref[j]; if (particle.y < -particle.size * particle.level * particle.scale * 2) { particle.reset(); particle.x = random(this.width); particle.y = this.height + particle.size * particle.scale * particle.level; } particle.move(); results.push(particle.draw(this)); } window.CP.exitedLoop(3); return results; } }); }).call(this);
CSS
@import url(https://fonts.googleapis.com/css?family=Lato:400,700); html, body { font-family: "Lato", sans-serif; background: #13242f; overflow: hidden; } #container:before { background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PHJhZGlhbEdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgY3g9IjUwJSIgY3k9IiIgcj0iOTUlIj48c3RvcCBvZmZzZXQ9IjIwJSIgc3RvcC1jb2xvcj0iIzAwMDAwMCIgc3RvcC1vcGFjaXR5PSIwLjAiLz48c3RvcCBvZmZzZXQ9Ijk1JSIgc3RvcC1jb2xvcj0iIzAwMDAwMCIvPjwvcmFkaWFsR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA=='); background-size: 100%; background-image: -moz-radial-gradient(center, ellipse cover, rgba(0, 0, 0, 0) 20%, #000000 95%); background-image: -webkit-radial-gradient(center, ellipse cover, rgba(0, 0, 0, 0) 20%, #000000 95%); background-image: radial-gradient(ellipse cover at center, rgba(0, 0, 0, 0) 20%, #000000 95%); position: absolute; content: ""; z-index: 0; opacity: 0.9; height: 100%; width: 100%; left: 0; top: 0; } #container:after { background: url("https://s.cdpn.io/1715/noise-1.png"); position: absolute; content: ""; z-index: 1; opacity: 0.8; height: 100%; width: 100%; left: 0; top: 0; } audio { position: absolute; z-index: 2; right: 0; top: 0; } .message { box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); text-transform: uppercase; border-radius: 3px; text-align: center; line-height: 1.2; background: rgba(0, 0, 0, 0.8); position: absolute; margin-left: -180px; margin-top: -30px; font-size: 13px; padding: 20px; display: none; z-index: 3; height: 60px; width: 360px; color: #fff; left: 50%; top: 50%; } .message h1, .message h2 { font-weight: 300; margin: 10px 0; } .message h1 a, .message h2 a { text-decoration: none; font-weight: 700; color: #1B676B; } #intro { display: block; }
HTML
This experiment requires the
Web Audio API
Please try in one of
these browsers
Safari users. You may hear audio but see no visuals. This is due to
this bug
in Safari 6
Simple music visualiser
Loading audio…
Join Effecthub.com
Working with Global Gaming Artists and Developers!
Login
Sign Up
Or Login with Your Email Address:
Email
Password
Remember
Or Sign Up with Your Email Address:
Your Email
This field must contain a valid email
Set Password
Password should be at least 1 character
Stay informed via email