var Stats = function () { var startTime = Date.now(), prevTime = startTime; var ms = 0, msMin = Infinity, msMax = 0; var fps = 0, fpsMin = Infinity, fpsMax = 0; var frames = 0, mode = 0; var container = document.createElement( 'div' ); container.id = 'stats'; container.addEventListener( 'mousedown', function ( event ) { event.preventDefault(); setMode( ++ mode % 2 ) }, false ); container.style.cssText = 'width:80px;opacity:0.9;cursor:pointer'; var fpsDiv = document.createElement( 'div' ); fpsDiv.id = 'fps'; fpsDiv.style.cssText = 'padding:0 0 3px 3px;text-align:left;background-color:#002'; container.appendChild( fpsDiv ); var fpsText = document.createElement( 'div' ); fpsText.id = 'fpsText'; fpsText.style.cssText = 'color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px'; fpsText.innerHTML = 'FPS'; fpsDiv.appendChild( fpsText ); var fpsGraph = document.createElement( 'div' ); fpsGraph.id = 'fpsGraph'; fpsGraph.style.cssText = 'position:relative;width:74px;height:30px;background-color:#0ff'; fpsDiv.appendChild( fpsGraph ); while ( fpsGraph.children.length < 74 ) { var bar = document.createElement( 'span' ); bar.style.cssText = 'width:1px;height:30px;float:left;background-color:#113'; fpsGraph.appendChild( bar ); } var msDiv = document.createElement( 'div' ); msDiv.id = 'ms'; msDiv.style.cssText = 'padding:0 0 3px 3px;text-align:left;background-color:#020;display:none'; container.appendChild( msDiv ); var msText = document.createElement( 'div' ); msText.id = 'msText'; msText.style.cssText = 'color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px'; msText.innerHTML = 'MS'; msDiv.appendChild( msText ); var msGraph = document.createElement( 'div' ); msGraph.id = 'msGraph'; msGraph.style.cssText = 'position:relative;width:74px;height:30px;background-color:#0f0'; msDiv.appendChild( msGraph ); while ( msGraph.children.length < 74 ) { var bar = document.createElement( 'span' ); bar.style.cssText = 'width:1px;height:30px;float:left;background-color:#131'; msGraph.appendChild( bar ); } var setMode = function ( value ) { mode = value; switch ( mode ) { case 0: fpsDiv.style.display = 'block'; msDiv.style.display = 'none'; break; case 1: fpsDiv.style.display = 'none'; msDiv.style.display = 'block'; break; } } var updateGraph = function ( dom, value ) { var child = dom.appendChild( dom.firstChild ); child.style.height = value + 'px'; } return { REVISION: 11, domElement: container, setMode: setMode, begin: function () { startTime = Date.now(); }, end: function () { var time = Date.now(); ms = time - startTime; msMin = Math.min( msMin, ms ); msMax = Math.max( msMax, ms ); msText.textContent = ms + ' MS (' + msMin + '-' + msMax + ')'; updateGraph( msGraph, Math.min( 30, 30 - ( ms / 200 ) * 30 ) ); frames ++; if ( time > prevTime + 1000 ) { fps = Math.round( ( frames * 1000 ) / ( time - prevTime ) ); fpsMin = Math.min( fpsMin, fps ); fpsMax = Math.max( fpsMax, fps ); fpsText.textContent = fps + ' FPS (' + fpsMin + '-' + fpsMax + ')'; updateGraph( fpsGraph, Math.min( 30, 30 - ( fps / 100 ) * 30 ) ); prevTime = time; frames = 0; } return time; }, update: function () { startTime = this.end(); } } }; /* main */ var stats = new Stats(); stats.setMode(0); stats.domElement.style.position = 'absolute'; stats.domElement.style.left = '0px'; stats.domElement.style.top = '0px'; document.body.appendChild(stats.domElement); /*! * Mantis.js / jQuery / Zepto.js plugin for Constellation * @version 1.2.2 * @author Acauã Montiel * @license http://acaua.mit-license.org/ */ (function ($, window) { var $window = $(window); /** * Makes a nice constellation on canvas * @constructor Constellation */ function Constellation (canvas, options) { var $canvas = $(canvas), context = canvas.getContext('2d'), defaults = { star: { color: 'rgba(255, 255, 255, .5)', width: 1, randomWidth: true }, line: { color: 'rgba(255, 255, 255, .5)', width: 0.2 }, position: { x: 0, y: 0 }, width: window.innerWidth, height: window.innerHeight, velocity: 0.1, length: 100, distance: 120, radius: 150, stars: [] }, config = $.extend(true, {}, defaults, options); function Star () { this.x = Math.random() * canvas.width; this.y = Math.random() * canvas.height; this.vx = (config.velocity - (Math.random() * 0.5)); this.vy = (config.velocity - (Math.random() * 0.5)); this.radius = config.star.randomWidth ? (Math.random() * config.star.width) : config.star.width; } Star.prototype = { create: function(){ context.beginPath(); context.arc(this.x, this.y, this.radius, 0, Math.PI * 2, false); context.fill(); }, animate: function(){ var i; for (i = 0; i < config.length; i++) { var star = config.stars[i]; if (star.y < 0 || star.y > canvas.height) { star.vx = star.vx; star.vy = - star.vy; } else if (star.x < 0 || star.x > canvas.width) { star.vx = - star.vx; star.vy = star.vy; } star.x += star.vx; star.y += star.vy; } }, line: function(){ var length = config.length, iStar, jStar, i, j; for (i = 0; i < length; i++) { for (j = 0; j < length; j++) { iStar = config.stars[i]; jStar = config.stars[j]; if ( (iStar.x - jStar.x) < config.distance && (iStar.y - jStar.y) < config.distance && (iStar.x - jStar.x) > - config.distance && (iStar.y - jStar.y) > - config.distance ) { if ( (iStar.x - config.position.x) < config.radius && (iStar.y - config.position.y) < config.radius && (iStar.x - config.position.x) > - config.radius && (iStar.y - config.position.y) > - config.radius ) { context.beginPath(); context.moveTo(iStar.x, iStar.y); context.lineTo(jStar.x, jStar.y); context.stroke(); context.closePath(); } } } } } }; this.createStars = function () { var length = config.length, star, i; context.clearRect(0, 0, canvas.width, canvas.height); for (i = 0; i < length; i++) { config.stars.push(new Star()); star = config.stars[i]; star.create(); } star.line(); star.animate(); }; this.setCanvas = function () { canvas.width = config.width; canvas.height = config.height; }; this.setContext = function () { context.fillStyle = config.star.color; context.strokeStyle = config.line.color; context.lineWidth = config.line.width; }; this.setInitialPosition = function () { if (!options || !options.hasOwnProperty('position')) { config.position = { x: canvas.width * 0.5, y: canvas.height * 0.5 }; } }; this.loop = function (callback) { callback(); this.rAF = window.requestAnimationFrame(function () { stats.begin(); this.loop(callback); stats.end(); }.bind(this)); }; this.handlers = { window: { mousemove: function(e){ config.position.x = e.pageX - $canvas.offset().left; config.position.y = e.pageY - $canvas.offset().top; }, resize: function () { window.cancelAnimationFrame(this.rAF); } } }; this.bind = function () { $window .on('mousemove', this.handlers.window.mousemove) .on('resize', this.handlers.window.resize.bind(this)); }; this.unbind = function () { $window .off('mousemove', this.handlers.window.mousemove) .off('resize', this.handlers.window.resize); } this.init = function () { this.setCanvas(); this.setContext(); this.setInitialPosition(); this.loop(this.createStars); this.bind(); }; } function instantiate(element, options) { var c = new Constellation(element, options); c.init(); } $.fn.constellation = function (options) { return this.each(function () { $window.on('resize', () => { instantiate(this, options); }); instantiate(this, options); }); }; })($, window); // Init plugin $('.canvas-area canvas').constellation({ star: { width: 7, color: '#27c9dc' }, line: { color: 'transparent' }, length: (window.innerWidth / 12), radius: (window.innerWidth / 5) });