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.

            
              <div id="interference">

	<div id="gradients">
		<div class="gradient" id="rear-gradient"></div>
		<div class="gradient" id="front-gradient"></div>
	</div>

	<div id="controls">
		<button id="regenerate">REGENERATE</button>
		<button id="separate" data-down="OVERLAP">SEPARATE</button>
	</div>

</div>

            
          
!
            
              html, body {
    margin:0;
    height: 100%;
}

#interference, #gradients {
    position:absolute;
    left:0;
    top:0;
    right:0;
    bottom:0;
}

#interference {
	background-color: #182020;
}

.gradient {
    position: absolute;
    left:0;
    top:0;
    right:0;
    bottom:0;
    background-attachment: fixed;
    -webkit-transform:translateZ(0px);
    transform:translateZ(0px);
}

#gradients.separate .gradient {
    width: 85%;
    height: 70%;
}

#gradients.separate #rear-gradient {
    top: 5%;
    left: 5%;
}

#gradients.separate #front-gradient {
    top: 20%;
    left: 10%;
}

#controls {
    position: absolute;
    bottom: 52px;
    width: 100%;
    text-align: center;
    display: none;
}

#controls button {
    width: 86px;
    height: 26px;
    margin: 1px;
  	border: none;
    background-color: rgba(0,0,0,.5);
    color: rgba(255,255,255,.75);
    font-family: "Verdana", "sans-serif";
    font-size: 10px;
}

#controls button:hover {
    background-color: rgba(0,0,0,.75);
    color: #FFF;
}

#controls button:focus {
    outline:0;
}
            
          
!
            
              /*
	GRADIENT INTERFERENCE
	CSS3 repeating-linear-gradient() experiment.

	Author:   Antonio Belluscio
	Creation: 2015
	Version:  2017
	License:  MIT License
*/


// CORE VARIABLES AND CLASSES

var rearColors;
var frontColors;

var rearPercs;
var frontPercs;

function ColorStop( baseHue )
{
	this.h = ((Math.random()*180+270) + baseHue) % 360;
	this.s = Math.random()*100;
	this.l = Math.random()*100;
}

function PercStop( minVal, maxVal )
{
	this.minVal = minVal;
	this.maxVal = maxVal;
	this.val = Math.random()*(this.maxVal-this.minVal)+this.minVal;
	this.velVal = Math.random()*(this.maxVal*0.0005)+0.0001;
 	if (Math.random()<0.5) {
		this.velVal = -this.velVal;
	}
	this.update = function() {
		this.val += this.velVal;
		if (this.val>this.maxVal || this.val<this.minVal) {
			this.velVal = -this.velVal;
			this.val += this.velVal;
		}
	};
}


// INTERFACE VARIABLES

var browser_webkit = /webkit/.test(navigator.userAgent.toLowerCase());
var browser_msie = /trident/.test(navigator.userAgent.toLowerCase());
var browser_mozilla = /mozilla/.test(navigator.userAgent.toLowerCase()) && !browser_webkit && !browser_msie;
var browser_opera = /opera/.test(navigator.userAgent.toLowerCase());
var browser_touch = ('ontouchstart' in window);

var gradientsDiv;
var rearGradientDiv;
var frontGradientDiv;
var controlsDiv;
var regenerateBtn;
var separateBtn;
var separateCaption;
var separateDownCaption;
var controlsMouseOver = false;
var buttonsWaiting;
var gradientPrefix;


// CORE FUNCTIONS

window.addEventListener("load", setupWork, false );

function setupWork()
{
	initInterface();

	gradientPrefix = "repeating-linear-gradient(to right, ";
	rearGradientDiv.style.backgroundImage = gradientPrefix+"#000, #000 0%, #000 1%)";
	if (rearGradientDiv.style.backgroundImage.indexOf("gradient") === -1) {
		if (browser_webkit) {
			gradientPrefix = "-webkit-repeating-linear-gradient(right, ";
		} else if (browser_opera) {
			gradientPrefix = "-o-repeating-linear-gradient(right, ";
		} else if (browser_mozilla) {
			gradientPrefix = "-moz-repeating-linear-gradient(right, ";
		}
	}

	regenerate();
	requestAnimationFrame(update);
}

function update()
{
	for (var i=0; i<rearPercs.length; ++i) {
		rearPercs[i].update();
		frontPercs[i].update();
	}

	var currPerc = 50 - (rearPercs[0].val + rearPercs[1].val + rearPercs[2].val + rearPercs[3].val) / 2;
	var rearHSL = new Array(4);
	for (var i=0; i<4; ++i) {
		currPerc += rearPercs[i].val;
		var j = i % 3;
		rearHSL[i] = "hsl("+rearColors[j].h+","+rearColors[j].s+"%,"+rearColors[j].l+"%) "+currPerc+"%";
	}

	currPerc = 50 - (frontPercs[0].val+frontPercs[1].val+frontPercs[2].val+frontPercs[3].val)/2;
	var frontHSL = new Array(4);
	for (var i=0; i<4; ++i) {
	 	currPerc += frontPercs[i].val;
	 	var j = i % 3;
	 	frontHSL[i] = "hsla("+frontColors[j].h+","+frontColors[j].s+"%,"+frontColors[j].l+"%,0.5) "+currPerc+"%";
	}

	rearGradientDiv.style.backgroundImage = gradientPrefix + rearHSL[0] +", "+ rearHSL[1] +", "+ rearHSL[2] +", "+ rearHSL[3] +")";
	frontGradientDiv.style.backgroundImage = gradientPrefix + frontHSL[0] +", "+ frontHSL[1] +", "+ frontHSL[2] +", "+ frontHSL[3] +")";

	updateInterface();
	requestAnimationFrame(update);
}

function regenerate()
{
	var baseHue = Math.random()*360;
	rearColors = [new ColorStop(baseHue), new ColorStop(baseHue), new ColorStop(baseHue)];
	baseHue = Math.random()*360;
	frontColors = [new ColorStop(baseHue), new ColorStop(baseHue), new ColorStop(baseHue)];

	rearPercs = [new PercStop(0.1,10), new PercStop(0.1,10), new PercStop(0.1,10), new PercStop(0.1,10)];
	frontPercs = [new PercStop(0.1,5), new PercStop(0.1,5), new PercStop(0.1,5), new PercStop(0.1,5)];
}


// INTERFACE FUNCTIONS

function initInterface()
{
	gradientsDiv =  document.getElementById("gradients");
	rearGradientDiv = document.getElementById("rear-gradient");
	frontGradientDiv = document.getElementById("front-gradient");
	controlsDiv = document.getElementById("controls");
	regenerateBtn = document.getElementById("regenerate");
	separateBtn = document.getElementById("separate");
	separateCaption = separateBtn.innerHTML;
	separateDownCaption = separateBtn.getAttribute('data-down');

	if (browser_touch) {
		gradientsDiv.addEventListener( "touchend", canvasTouchEnded, false );
		regenerateBtn.addEventListener( 'touchend',  regenerateAction, false);
		separateBtn.addEventListener( 'touchend',  separateAction, false);
	} else {
		gradientsDiv.onmousemove = canvasMouseMoved;
		regenerateBtn.addEventListener( 'click',  regenerateAction, false);
		separateBtn.addEventListener( 'click',  separateAction, false);
		controlsDiv.addEventListener('mouseover', function() {
			controlsMouseOver = true;
		}, false);
		controlsDiv.addEventListener('mouseout', function() {
			controlsMouseOver = false;
		}, false);
	}

	buttonsWaiting = 30000;
}

function updateInterface()
{
	if (buttonsWaiting > 0) {
		controlsDiv.style.display = 'block';
		if (!controlsMouseOver) {
			buttonsWaiting -= 33;
		}
	} else {
		controlsDiv.style.display = 'none';
	}
}

function canvasMouseMoved( evt )
{
	buttonsWaiting = 500;
}

function canvasTouchEnded(evt)
{
	if (buttonsWaiting > 0) {
		buttonsWaiting = 0;
	} else {
		buttonsWaiting = 60000;
	}
}

function regenerateAction()
{
	regenerate();

	if (browser_touch) {
		buttonsWaiting = 60000;
	}
}

function separateAction()
{
	gradientsDiv.classList.toggle("separate");
	if (separateBtn.innerHTML == separateCaption) {
		separateBtn.innerHTML = separateDownCaption;
	} else {
		separateBtn.innerHTML = separateCaption;
	}

	if (browser_touch) {
		buttonsWaiting = 60000;
	}
}
            
          
!
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