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.

            
              <!-- Inspired by Peter Cho www.typotopo.com -->
<canvas></canvas>
            
          
!
            
              	body {
		overflow:hidden;
		margin:0;
	}
	canvas {
		cursor:none;
	}
            
          
!
            
              /*!
 *
 * Author:      Gianluca Guarini
 * Contact:     gianluca.guarini@gmail.com
 * Website:     http://www.gianlucaguarini.com/
 * Twitter:     @gianlucaguarini
 *
 * Copyright (c) 2013 Gianluca Guarini
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 **/

var canvas = document.querySelectorAll('canvas')[0],
	ctx = canvas.getContext('2d'),
	arrows = [],
	ARROWS_GRID = 40;
// requestAnimationFrame polyfill
(function() {
  var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||                      window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
  window.requestAnimationFrame = requestAnimationFrame;
})();

// Mouse Class to get the mouse coordinates
var Mouse = function (el) {
	// Public Vars
	this.el		= el || window;
	this.x		= 0;
	this.y		= 0;

	/*
	*
	* Private Internal Methods
	*
	*/
	var _getPointerEvent = function(event) {
		return event.targetTouches ? event.targetTouches[0] : event;
	};
	/*
	*
	* Set the x and y values of this class according to the mouse coordinates givent to the event object
	*
	*/

	var _setMouseCoordinates = function ( e ) {

		e.preventDefault();
		var pointer = _getPointerEvent(e),
			x = pointer.pageX,
			y = pointer.pageY;

		this.x = x;
		this.y = y;
	};

	
	var events = "mousernter mousemove touchstart touchenter touchmove";

	// bind events
	events.split(' ').forEach(function(eventName){
		this.el.addEventListener(eventName,_setMouseCoordinates.bind(this))
	})

	return this;
}();
// Arrow Class https://github.com/lamberta/html5-animation/blob/master/examples/ch05/classes/arrow.js
var Arrow = function (o) {
	this.x = o.x | 0;
	this.y = o.y | 0;
	this.color = o.color || "#ffffff";
	this.rotation = o.rotation | 0;
	this.draw = function () {
		ctx.save();
		ctx.translate(this.x, this.y);
		ctx.rotate(this.rotation);
		ctx.lineWidth = 1;
		ctx.fillStyle = this.color;
		ctx.beginPath();
		ctx.moveTo(-10, -5);
		ctx.lineTo(0, -5);
		ctx.lineTo(0, -10);
		ctx.lineTo(10, 0);
		ctx.lineTo(0, 10);
		ctx.lineTo(0, 5);
		ctx.lineTo(-10, 5);
		ctx.lineTo(-10, -5);
		ctx.closePath();
		ctx.fill();
		ctx.stroke();
		ctx.restore();
	};
};
/*
*
* Set the viewport size let's make it fullscreen!
*
*/
var setViewport = function () {
	canvas.width = window.innerWidth;
	canvas.height = window.innerHeight;
	createParticles();
};
/*
*
* Make all the arrows
*
*/
var createParticles = function () {
	arrows = [];
	var ROWS = canvas.width / ARROWS_GRID,
		COLS = canvas.height / ARROWS_GRID;
	for (var x = 0; x < ROWS; x++) {
		for (var y = 0; y < COLS; y++){
			arrows.push(new Arrow({
				x:x * ARROWS_GRID,
				y:y * ARROWS_GRID
			}));
		}
	}
};
/*
*
* Rock and roll baby!
*
*/
var loop = function (){
	render();
	window.requestAnimationFrame(loop);
};
/*
*
* Draw the arrows and clean the canvas
*
*/
var render = function () {
	ctx.clearRect(0,0,canvas.width,canvas.height);
	[].forEach.call(arrows,function(arrow){
		arrow.rotation = Math.atan2(Mouse.y - arrow.y,Mouse.x - arrow.x);
		arrow.draw();
	});
};

// Init this shit
setViewport();
createParticles();
loop();

// UI Events
window.addEventListener('resize',setViewport,false);
            
          
!
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