initialises layers JIT, instead of in the constructor
This commit is contained in:
parent
43e6cb7a37
commit
9479b214fa
@ -10,8 +10,7 @@ function BallRenderer(thecanvas){
|
||||
this.width = this.canvas.width;
|
||||
this.height = this.canvas.height;
|
||||
this.size = this.width * this.height;
|
||||
this.pointList = new Uint8ClampedArray(this.size * 4);
|
||||
this.contourLayer = new Uint8ClampedArray(this.size * 4);
|
||||
this.pointLayer = new Uint8ClampedArray(this.size * 4);
|
||||
this.radius = 30;
|
||||
this.drawnTemp = [];
|
||||
this.prof = 0;
|
||||
@ -72,24 +71,28 @@ BallRenderer.prototype = {
|
||||
}
|
||||
a[a.length-1] = 255;
|
||||
var l = -step/2;
|
||||
var gradient = new Uint8ClampedArray(1024);
|
||||
for(var i = 0; i<a.length; i++){
|
||||
var thisAlpha = a[i]/255;
|
||||
this.ctx.fillStyle = "rgba(0, 0, 0, " + thisAlpha + ")";
|
||||
this.ctx.fillRect(0, l, 1, step);
|
||||
l+=step;
|
||||
var y = Math.round(i*step);
|
||||
var thisAlpha = a[i];
|
||||
while(y<step*(i+1)){
|
||||
gradient[y*4+3] = thisAlpha;
|
||||
y++;
|
||||
}
|
||||
var _grad = this.ctx.getImageData(0, 0, 1, 255).data;
|
||||
this.ctx.clearRect(0, 0, 1, 256);
|
||||
|
||||
for (var i = 0; i< this.pointList.length; i+=4){
|
||||
if(this.pointList[i+3] === 0) continue;
|
||||
var currentAlpha = this.pointList[i+3];
|
||||
this.contourLayer[i+3] = this.pointList[i+3] === 255? 255: _grad[currentAlpha*4+3];
|
||||
}
|
||||
if(!this.contourLayer) this.contourLayer = new Uint8ClampedArray(this.size * 4);
|
||||
for (var i = 0; i< this.pointLayer.length; i+=4){
|
||||
if(this.pointLayer[i+3] === 0) continue;
|
||||
var currentAlpha = this.pointLayer[i+3];
|
||||
this.contourLayer[i+3] = gradient[currentAlpha*4+3];
|
||||
}
|
||||
},
|
||||
draw: function(dataArray){
|
||||
if(!dataArray) dataArray = this.pointList;
|
||||
else this.contourLayer = dataArray;
|
||||
if (!dataArray){
|
||||
if (this.isoplethLayer) dataArray = this.isoplethLayer;
|
||||
else if (this.contourLayer) dataArray = this.contourLayer;
|
||||
else dataArray = this.pointLayer;
|
||||
}
|
||||
if(!this.imageData) this.imageData = this.ctx.createImageData(this.width, this.height);
|
||||
this.imageData.data.set(dataArray);
|
||||
this.ctx.putImageData(this.imageData, 0, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user