Skip to content

Instantly share code, notes, and snippets.

@NHQ
Last active August 29, 2015 14:27
Show Gist options
  • Save NHQ/c197f32724465bf8278e to your computer and use it in GitHub Desktop.
Save NHQ/c197f32724465bf8278e to your computer and use it in GitHub Desktop.
should be painting a radial gradient from center....
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) {
var date = Date.now()
for (var y = 0; y < height; ++y) {
for (var x = 0; x < width; ++x) {
var index = (y * width + x) * 4;
var a = Math.abs(angle([x, y], center)) / Math.PI
var z = .05
var v = Math.abs(Math.sin(date))
var g = (a < v + z && a > v - z) ? 1 : 0
var g = a * v% z > z/2 ? 1 : 0
var t = 1//test([x, y])
var value = x * y * a * v & 0xff;
w.data[index] = r.data[index] * g; // red
w.data[++index] = r.data[index] + value * t * g; // green
w.data[++index] = r.data[index] * g; // 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))
}
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;
w.data[index] = value; // red
w.data[++index] = value; // green
w.data[++index] = value; // 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))
}
var canvas = document.querySelector('canvas')
var width = canvas.width
var height= canvas.height
var center = [width / 2, height / 2]
var maxd = distance([0,0], center)
return function (r, w) {
for (var i = 0; i < w.data.length; i += 4) {
var coords = [i / 4 % width, i / 4 % height ]
var dist = distance(coords, center)
var v = Math.floor(dist / maxd * 255)/255
w.data[i] = r.data[i] / v;
w.data[i+1] = r.data[i+1] / v;
w.data[i+2] = r.data[i + 2] / v;
w.data[i+3] = 255;
}
}
function distance(a, b){
return Math.sqrt(Math.pow(b[0] - a[0], 2) + Math.pow(b[1] - a[1], 2))
}
var canvas = document.querySelector('canvas')
var width = canvas.width
var height= canvas.height
var center = [width / 2, height / 2]
var maxd = distance([0,0], center)
return function (r, w) {
for (var i = 0; i < w.data.length; i += 4) {
var coords = [i / 4 % width, i / 4 % height ]
var dist = distance(coords, center)
var v = Math.floor(dist / maxd * 255)
w.data[i] = v;
w.data[i+1] = v;
w.data[i+2] = v;
w.data[i+3] = 255;
}
}
function distance(a, b){
return Math.sqrt(Math.pow(b[0] - a[0], 2) + Math.pow(b[1] - a[1], 2))
}
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 a = Math.abs(angle([x, y], center)) / Math.PI
var g = a < .1 ? 1 : 0
var t = test([x, y])
var value = x * y & 0xff;
w.data[index] = value * t * g; // red
w.data[++index] = value * t * g; // green
w.data[++index] = value * t; // 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