An RGB color spectrum mixer, controlled by your mouse movements. Move left to turn up red, right to turn up green, and down to turn up blue. Great for music visualization, become your own lighting D…
window.onload=function(){w=window;d=document.getElementById("c");c=d.getContext("2d");W=w.innerWidth;H=w.innerHeight;d.style.width=W+"px";d.style.height=H+"px";document.onmousemove=function(g){c.drawImage(image,0,0);var a=(g.pageX/W)*255-127,k=(g.pageY/H)*255-127,h=c.getImageData(0,0,d.width,d.height),f=h.data;for(var b=0,j=f.length;b<j;b+=4){h.data[b]=f[b]-a;h.data[b+1]=f[b+1]+a;h.data[b+2]=f[b+2]+k}c.putImageData(h,0,0)};image=(function(){var k=document.createElement("canvas").getContext("2d"),a=300,h=a/2,f=(1/360)*Math.PI*2,j=W/H,e=-h/4,l=-h/2;d.width=k.canvas.width=h*j;d.height=k.canvas.height=h;k.fillRect(0,0,W,H);for(var b=0;b<=359;b++){var i=k.createLinearGradient(e+h,l,e+h,l+h);i.addColorStop(0,"#000");i.addColorStop(0.5,"hsl("+((b+70)%360)+",100%,50%)");i.addColorStop(1,"#FFF");k.beginPath();k.moveTo(e+h,l);k.lineTo(e+h,l+h);k.lineTo(e+h+2,l+h);k.lineTo(e+h+5,l);k.fillStyle=i;k.fill();k.translate(e+h,l+h);k.rotate(f);k.translate(-(e+h),-(l+h))}return k.canvas})();c.drawImage(image,0,0)};
d2luZG93Lm9ubG9hZD1mdW5jdGlvbigpe3c9d2luZG93O2Q9ZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoImMiKTtjPWQuZ2V0Q29udGV4dCgiMmQiKTtXPXcuaW5uZXJXaWR0aDtIPXcuaW5uZXJIZWlnaHQ7ZC5zdHlsZS53aWR0aD1XKyJweCI7ZC5zdHlsZS5oZWlnaHQ9SCsicHgiO2RvY3VtZW50Lm9ubW91c2Vtb3ZlPWZ1bmN0aW9uKGcpe2MuZHJhd0ltYWdlKGltYWdlLDAsMCk7dmFyIGE9KGcucGFnZVgvVykqMjU1LTEyNyxrPShnLnBhZ2VZL0gpKjI1NS0xMjcsaD1jLmdldEltYWdlRGF0YSgwLDAsZC53aWR0aCxkLmhlaWdodCksZj1oLmRhdGE7Zm9yKHZhciBiPTAsaj1mLmxlbmd0aDtiPGo7Yis9NCl7aC5kYXRhW2JdPWZbYl0tYTtoLmRhdGFbYisxXT1mW2IrMV0rYTtoLmRhdGFbYisyXT1mW2IrMl0ra31jLnB1dEltYWdlRGF0YShoLDAsMCl9O2ltYWdlPShmdW5jdGlvbigpe3ZhciBrPWRvY3VtZW50LmNyZWF0ZUVsZW1lbnQoImNhbnZhcyIpLmdldENvbnRleHQoIjJkIiksYT0zMDAsaD1hLzIsZj0oMS8zNjApKk1hdGguUEkqMixqPVcvSCxlPS1oLzQsbD0taC8yO2Qud2lkdGg9ay5jYW52YXMud2lkdGg9aCpqO2QuaGVpZ2h0PWsuY2FudmFzLmhlaWdodD1oO2suZmlsbFJlY3QoMCwwLFcsSCk7Zm9yKHZhciBiPTA7Yjw9MzU5O2IrKyl7dmFyIGk9ay5jcmVhdGVMaW5lYXJHcmFkaWVudChlK2gsbCxlK2gsbCtoKTtpLmFkZENvbG9yU3RvcCgwLCIjMDAwIik7aS5hZGRDb2xvclN0b3AoMC41LCJoc2woIisoKGIrNzApJTM2MCkrIiwxMDAlLDUwJSkiKTtpLmFkZENvbG9yU3RvcCgxLCIjRkZGIik7ay5iZWdpblBhdGgoKTtrLm1vdmVUbyhlK2gsbCk7ay5saW5lVG8oZStoLGwraCk7ay5saW5lVG8oZStoKzIsbCtoKTtrLmxpbmVUbyhlK2grNSxsKTtrLmZpbGxTdHlsZT1pO2suZmlsbCgpO2sudHJhbnNsYXRlKGUraCxsK2gpO2sucm90YXRlKGYpO2sudHJhbnNsYXRlKC0oZStoKSwtKGwraCkpfXJldHVybiBrLmNhbnZhc30pKCk7Yy5kcmF3SW1hZ2UoaW1hZ2UsMCwwKX07
window.onload = function () {
w = window;
d = document.getElementById("c");
c = d.getContext("2d");
W = w.innerWidth;
H = w.innerHeight;
d.style.width = W + "px";
d.style.height = H + "px";
document.onmousemove = function(e) {
c.drawImage(image, 0, 0);
var x = (e.pageX / W) * 255 - 127, // grab mouse pixel coords, center at midpoint
y = (e.pageY / H) * 255 - 127,
o = c.getImageData(0, 0, d.width, d.height), // get image data
data = o.data;
for(var i = 0, n = data.length; i < n; i += 4) {
o.data[i] = data[i] - x; // red (left)
o.data[i + 1] = data[i + 1] + x; // green (right)
o.data[i + 2] = data[i + 2] + y; // blue (down)
}
c.putImageData(o, 0, 0);
};
image = (function() {
// process sphere
var c = document.createElement("canvas").getContext("2d"),
width = 300,
halfWidth = width / 2,
rotate = (1 / 360) * Math.PI * 2, // per degree
ratio = W / H,
left = -halfWidth / 4,
top = -halfWidth / 2;
d.width = c.canvas.width = halfWidth * ratio;
d.height = c.canvas.height = halfWidth;
c.fillRect(0, 0, W, H); // draw black rect (default)
for (var n = 0; n <= 359; n ++) {
var g = c.createLinearGradient(left + halfWidth, top, left + halfWidth, top + halfWidth);
g.addColorStop(0, "#000");
g.addColorStop(.5, "hsl("+((n + 70) % 360)+",100%,50%)");
g.addColorStop(1, "#FFF");
c.beginPath();
c.moveTo(left + halfWidth, top);
c.lineTo(left + halfWidth, top + halfWidth);
c.lineTo(left + halfWidth + 2, top + halfWidth);
c.lineTo(left + halfWidth + 5, top);
c.fillStyle = g;
c.fill();
c.translate(left + halfWidth, top + halfWidth);
c.rotate(rotate);
c.translate(-(left + halfWidth), -(top + halfWidth));
}
return c.canvas;
})();
c.drawImage(image, 0, 0);
}