Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <canvas></canvas>
              
            
!

CSS

              
                html, body {
	width: 100%;
	height: 100%;
	border: 0;
	padding: 0;
	margin: 0;
	overflow: hidden;
}
html, body, canvas {
	-webkit-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	-o-user-select: none;
	user-select: none;
}
              
            
!

JS

              
                function DoomSpiral(canvas) {
	Shoe.Layer.call(this);
	
	this.element = canvas;
	this.iterations = 50;
	this.vertices = 1000;
	this.radius = 75;
	this.value = 0;
	this.positionArray = this.plot();
	
	this.registerAnimatableProperty("positionArray"); 
	
	this.shiftKeyPressed = false;
	this.toggleKeys = function(e) {
		this.shiftKeyPressed = e.shiftKey;
	}
	document.addEventListener("keydown",this.toggleKeys.bind(this));
	document.addEventListener("keyup",this.toggleKeys.bind(this));
	document.addEventListener("mousedown", this.layout.bind(this));
	window.addEventListener("resize", this.resize.bind(this));
	
	this.resize();
}

DoomSpiral.prototype = Object.create(Shoe.Layer.prototype);
DoomSpiral.prototype.constructor = DoomSpiral;

DoomSpiral.prototype.resize = function(e) {
	this.element.width = window.innerWidth;
	this.element.height = window.innerHeight;
	
	Shoe.disableAnimation(true);
	this.positionArray = this.plot();
};

DoomSpiral.prototype.layout = function(e) {
	this.value = Math.random();
	this.positionArray = this.plot();
};

DoomSpiral.prototype.animationForKey = function(key,value) {
	return new Shoe.ArrayType( Shoe.NumberType, this.vertices * 2 - 2, {
		duration: 5.0 * (this.shiftKeyPressed ? 10 : 1),
		easing: wobble
	});
};

DoomSpiral.prototype.plot = function() {
	var canvas = this.element;
	var context = canvas.getContext("2d");
	var width = canvas.width;
	var height = canvas.height;
	var centerX = width/2;
	var centerY = height/2;
	var phi = this.value * Math.PI;
	var array = [];
	var slice = (Math.PI * 2) / this.vertices;
	var j = this.vertices;
	var theta = 0;
	while (--j) {
		theta -= slice;
		var i = this.iterations;
		var x = centerX;
		var y = centerY;
		do {
			var doom = (i * theta) + (i * i * phi);
			x += ( Math.sin(doom) / i ) * this.radius;
			y += ( Math.cos(doom) / i ) * this.radius;
		} while (--i);
		array.push(x);
		array.push(y);
	}
	return array;
};

DoomSpiral.prototype.render = function() {
	var canvas = this.element;
	var context = canvas.getContext("2d");
	var width = canvas.width;
	var height = canvas.height;
	context.clearRect(0, 0, width, height);
	
	var array = this.positionArray;
	var length = array.length;
	if (length > 1) {
		context.beginPath();
		context.moveTo(array[0],array[1]);
		for (var i = 2; i<length; i+=2) {
			context.lineTo(array[i],array[i+1]);
		}
		context.closePath();
		context.stroke();
	}
};

function wobble(progress) {
	var omega = 30;
	var zeta = 0.5;
	var beta = Math.sqrt(1.0 - zeta * zeta);
	//progress = 1 - Math.cos(progress * Math.PI / 2);
	progress = 1 / beta * Math.exp(-zeta * omega * progress) *	Math.sin( beta * omega * progress + Math.atan(beta / zeta));
	return 1 - progress;
}

var canvas = document.querySelector("canvas");
var doomSpiral = new DoomSpiral(canvas);
              
            
!
999px

Console