caches balls by radii
This commit is contained in:
parent
66d27019fc
commit
3db32964f0
@ -4,24 +4,23 @@
|
|||||||
// developed by Francisco Dans
|
// developed by Francisco Dans
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
var work = require('webworkify');
|
|
||||||
|
|
||||||
function BallRenderer(thecanvas){
|
function BallRenderer(thecanvas){
|
||||||
this.canvas = thecanvas;
|
this.canvas = thecanvas;
|
||||||
this.ctx = this.canvas.getContext("2d");
|
this.ctx = this.canvas.getContext("2d");
|
||||||
this.width = this.canvas.width;
|
this.width = this.canvas.width;
|
||||||
|
this.chWidth = this.canvas.width * 4;
|
||||||
this.height = this.canvas.height;
|
this.height = this.canvas.height;
|
||||||
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 = 15;
|
|
||||||
this.drawnTemp = {};
|
this.drawnTemp = {};
|
||||||
this.prof = 0;
|
this.prof = 0;
|
||||||
this.gradient = {};
|
this.gradient = {};
|
||||||
this.ballsSoFar = 0;
|
this.ballsSoFar = 0;
|
||||||
this.balls = 0;
|
this.balls = 0;
|
||||||
this.cumulative = true;
|
this.cumulative = true;
|
||||||
this.RW4 = this.radius * this.width *4;
|
|
||||||
this.availableWorkers = 10;
|
this.availableWorkers = 10;
|
||||||
|
this.mode = "heat";
|
||||||
|
this.cachedBalls = [];
|
||||||
}
|
}
|
||||||
BallRenderer.prototype = {
|
BallRenderer.prototype = {
|
||||||
getBallIndices: function(x, y){
|
getBallIndices: function(x, y){
|
||||||
@ -29,8 +28,10 @@ BallRenderer.prototype = {
|
|||||||
|
|
||||||
return indices;
|
return indices;
|
||||||
},
|
},
|
||||||
addBall: function(x0, y0){
|
addBall: function(x0, y0, st){
|
||||||
if(this.cachedBall){
|
this.radius = st["marker-width"];
|
||||||
|
this.RW4 = this.radius * this.width *4;
|
||||||
|
if(this.cachedBalls[this.radius]){
|
||||||
var startingPoint = this.getRIndexPos(x0, y0) - this.RW4 - this.radius*4;
|
var startingPoint = this.getRIndexPos(x0, y0) - this.RW4 - this.radius*4;
|
||||||
var i = 0,
|
var i = 0,
|
||||||
pointer = startingPoint,
|
pointer = startingPoint,
|
||||||
@ -39,7 +40,7 @@ BallRenderer.prototype = {
|
|||||||
endPoint = this.getRIndexPos(x0, y0) + this.RW4 + this.radius;
|
endPoint = this.getRIndexPos(x0, y0) + this.RW4 + this.radius;
|
||||||
while (pointer <= endPoint){
|
while (pointer <= endPoint){
|
||||||
while (pointer <= linemax){
|
while (pointer <= linemax){
|
||||||
this.pointLayer[pointer+3] += this.cachedBall[i+3];
|
this.pointLayer[pointer+3] += this.cachedBalls[this.radius][i+3];
|
||||||
i+=4;
|
i+=4;
|
||||||
pointer+=4;
|
pointer+=4;
|
||||||
}
|
}
|
||||||
@ -52,7 +53,7 @@ BallRenderer.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
precacheBall: function(x0, y0){
|
precacheBall: function(x0, y0){
|
||||||
this.cachedBall = new Uint8ClampedArray(Math.pow(2 * this.radius + 1, 2)*4);
|
this.cachedBalls[this.radius] = new Uint8ClampedArray(Math.pow(2 * this.radius + 1, 2)*4);
|
||||||
x0 = this.radius;
|
x0 = this.radius;
|
||||||
y0 = this.radius;
|
y0 = this.radius;
|
||||||
var orad = this.radius;
|
var orad = this.radius;
|
||||||
@ -89,7 +90,7 @@ BallRenderer.prototype = {
|
|||||||
},
|
},
|
||||||
addPoint: function(x, y, alpha){
|
addPoint: function(x, y, alpha){
|
||||||
var indexPos = (y*(this.radius*2+1)+x)*4;
|
var indexPos = (y*(this.radius*2+1)+x)*4;
|
||||||
this.cachedBall[indexPos + 3] += alpha;
|
this.cachedBalls[this.radius][indexPos + 3] += alpha;
|
||||||
},
|
},
|
||||||
map_range: function(value, low1, high1, low2, high2) {
|
map_range: function(value, low1, high1, low2, high2) {
|
||||||
return low2 + (high2 - low2) * (value - low1) / (high1 - low1);
|
return low2 + (high2 - low2) * (value - low1) / (high1 - low1);
|
||||||
|
Loading…
Reference in New Issue
Block a user