Created
August 31, 2015 20:00
-
-
Save NHQ/9696f7c0aebdfb30a97a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var canvas = document.querySelector('canvas') | |
var width = canvas.width | |
var height= canvas.height | |
var center = [width / 2, height / 2] | |
var maxd = 100//distance([0,0], center) | |
return function (r, w) { | |
for (var y = 0; y < height; ++y) { | |
for (var x = 0; x < width; ++x) { | |
var index = (y * width + x) * 4; | |
var value = x * y / Math.floor(Date.now() % 256/2) & 0xff; | |
var a = r.data[index] // = value; // red | |
var aa = r.data[++index]// = value; // green | |
var aaa = r.data[++index]// = value; | |
var d = distance([x, y], center) / maxd / 2 / 2 | |
//value = value & 0xff | |
w.data[index] = Math.floor(a * d ); // red | |
w.data[++index] = Math.floor(aa * d); // green | |
w.data[++index] = Math.floor(aaa * d); // blue | |
w.data[++index] = 255; // alpha | |
} | |
} | |
} | |
function test(c){ | |
if(c[0] < width / 2 && c[1] < height / 2) return 1 | |
else return 0 | |
} | |
function angle ( point1, point2 ) { | |
var dx = point2[0] - point1[0]; | |
var dy = point2[1] - point1[1]; | |
return Math.atan2( dy, dx ); | |
} | |
function distance(a, b){ | |
return Math.sqrt(Math.pow(b[0] - a[0], 2) + Math.pow(b[1] - a[1], 2)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment