optimizes drawnTemp a bit more

This commit is contained in:
Francisco Dans 2015-02-25 12:45:45 +01:00
parent 9479b214fa
commit d048652ba9

View File

@ -12,7 +12,7 @@ function BallRenderer(thecanvas){
this.size = this.width * this.height; this.size = this.width * this.height;
this.pointLayer = new Uint8ClampedArray(this.size * 4); this.pointLayer = new Uint8ClampedArray(this.size * 4);
this.radius = 30; this.radius = 30;
this.drawnTemp = []; this.drawnTemp = {};
this.prof = 0; this.prof = 0;
this.gradient = {}; this.gradient = {};
} }
@ -51,19 +51,18 @@ BallRenderer.prototype = {
return Math.sqrt( xs + ys ); return Math.sqrt( xs + ys );
} }
// Assumes xi is on the left and xf is on the right // Assumes xi is on the left and xf is on the right
var xPointer = xi;
if(typeof this.drawnTemp[yi] === "undefined"){ if(typeof this.drawnTemp[yi] === "undefined"){
while (xPointer <= xf){ while (xi <= xf){
var alpha = this.map_range(lineDistance(xPointer, yi), 0, this.radius, 30, 0); var alpha = this.map_range(lineDistance(xi, yi), 0, this.radius, 30, 0);
this.addPoint(xPointer, yi, alpha); this.addPoint(xi, yi, alpha);
xPointer ++; xi ++;
} }
this.drawnTemp[yi]=true; this.drawnTemp[yi]=true;
} }
}, },
contour: function(granularity){ contour: function(granularity){
var step = 255/granularity; var step = 255/granularity;
var i = 0, a = new Uint8ClampedArray(granularity+1), c=0; var i = 1, a = new Uint8ClampedArray(granularity+1), c=0;
while (i<255){ while (i<255){
a[c] = i; a[c] = i;
i += step; i += step;