body {
background:#000;
color:#fff;
margin:0;
padding:0;
}
canvas {
cursor:crosshair;
}
#canvas1, video {
display:none;
}
#canvas2 {
display:block;
}
JavaScript
function randomXToY(minVal, maxVal, floatVal) {
var randVal = minVal + (Math.random() * (maxVal - minVal));
return typeof floatVal === 'undefined' ? randVal >> 0 : randVal.toFixed(floatVal);
}
// Returns an array containing the x and y coordinates of an event (e.g. mouse click)
// Code from: http://answers.oreilly.com/topic/1929-how-to-use-the-canvas-and-draw-elements-in-html5/
function getCoords(event) {
var x, y;
if (event.touches) {
x = event.touches[0].pageX;
y = event.touches[0].pageY;
} else if (event.pageX || event.pageY) {
x = event.pageX;
y = event.pageY;
} else {
x = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
y = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}
x -= canvas1.offsetLeft;
y -= canvas1.offsetTop;
return [x, y];
}
/* MAIN SCRIPT */
document.addEventListener('DOMContentLoaded', function(){
// Global variables
var windowwidth = window.outerWidth;
var windowheight = window.outerHeight;
var shards = [];
var coords = [];
var MAX_ROTATION = 0.05; // In radians
var DRAW_SPEED = 1000 / 20; // Draw at 20 fps
var mouse_down = ('createTouch' in document ? 'ontouchstart' : 'onmousedown');
var video = document.querySelector('video');
var canvas1 = document.getElementById('canvas1');
var context1 = canvas1.getContext('2d');
var canvas2 = document.getElementById('canvas2');
var context2 = canvas2.getContext('2d');
var HEALING_DELAY = 600; // Milliseconds
var HEALING_TIME = 1000; // Milliseconds
var opacity = 1;
var timer_delay = HEALING_DELAY;
var timer_heal = HEALING_TIME;
var heal_step = DRAW_SPEED / HEALING_TIME;
// Shard constructor
function Shard() {
this.rotation = 0;
this.corner1 = []; // Make this an empty array
this.corner2 = [];
this.corner3 = [];
}
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.