-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert painter and other render classes to ES6 class syntax
- Loading branch information
Showing
5 changed files
with
618 additions
and
615 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,73 @@ | ||
'use strict'; | ||
|
||
module.exports = FrameHistory; | ||
|
||
function FrameHistory() { | ||
this.changeTimes = new Float64Array(256); | ||
this.changeOpacities = new Uint8Array(256); | ||
this.opacities = new Uint8ClampedArray(256); | ||
this.array = new Uint8Array(this.opacities.buffer); | ||
|
||
this.fadeDuration = 300; | ||
this.previousZoom = 0; | ||
this.firstFrame = true; | ||
} | ||
class FrameHistory { | ||
|
||
FrameHistory.prototype.record = function(zoom) { | ||
let now = Date.now(); | ||
constructor() { | ||
this.changeTimes = new Float64Array(256); | ||
this.changeOpacities = new Uint8Array(256); | ||
this.opacities = new Uint8ClampedArray(256); | ||
this.array = new Uint8Array(this.opacities.buffer); | ||
|
||
if (this.firstFrame) { | ||
now = 0; | ||
this.firstFrame = false; | ||
this.fadeDuration = 300; | ||
this.previousZoom = 0; | ||
this.firstFrame = true; | ||
} | ||
|
||
zoom = Math.floor(zoom * 10); | ||
record(zoom) { | ||
let now = Date.now(); | ||
|
||
let z; | ||
if (zoom < this.previousZoom) { | ||
for (z = zoom + 1; z <= this.previousZoom; z++) { | ||
this.changeTimes[z] = now; | ||
this.changeOpacities[z] = this.opacities[z]; | ||
if (this.firstFrame) { | ||
now = 0; | ||
this.firstFrame = false; | ||
} | ||
} else { | ||
for (z = zoom; z > this.previousZoom; z--) { | ||
this.changeTimes[z] = now; | ||
this.changeOpacities[z] = this.opacities[z]; | ||
} | ||
} | ||
|
||
for (z = 0; z < 256; z++) { | ||
const timeSince = now - this.changeTimes[z]; | ||
const opacityChange = timeSince / this.fadeDuration * 255; | ||
if (z <= zoom) { | ||
this.opacities[z] = this.changeOpacities[z] + opacityChange; | ||
zoom = Math.floor(zoom * 10); | ||
|
||
let z; | ||
if (zoom < this.previousZoom) { | ||
for (z = zoom + 1; z <= this.previousZoom; z++) { | ||
this.changeTimes[z] = now; | ||
this.changeOpacities[z] = this.opacities[z]; | ||
} | ||
} else { | ||
this.opacities[z] = this.changeOpacities[z] - opacityChange; | ||
for (z = zoom; z > this.previousZoom; z--) { | ||
this.changeTimes[z] = now; | ||
this.changeOpacities[z] = this.opacities[z]; | ||
} | ||
} | ||
} | ||
|
||
this.changed = true; | ||
this.previousZoom = zoom; | ||
}; | ||
for (z = 0; z < 256; z++) { | ||
const timeSince = now - this.changeTimes[z]; | ||
const opacityChange = timeSince / this.fadeDuration * 255; | ||
if (z <= zoom) { | ||
this.opacities[z] = this.changeOpacities[z] + opacityChange; | ||
} else { | ||
this.opacities[z] = this.changeOpacities[z] - opacityChange; | ||
} | ||
} | ||
|
||
this.changed = true; | ||
this.previousZoom = zoom; | ||
} | ||
|
||
FrameHistory.prototype.bind = function(gl) { | ||
if (!this.texture) { | ||
this.texture = gl.createTexture(); | ||
gl.bindTexture(gl.TEXTURE_2D, this.texture); | ||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | ||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); | ||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); | ||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); | ||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.ALPHA, 256, 1, 0, gl.ALPHA, gl.UNSIGNED_BYTE, this.array); | ||
bind(gl) { | ||
if (!this.texture) { | ||
this.texture = gl.createTexture(); | ||
gl.bindTexture(gl.TEXTURE_2D, this.texture); | ||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | ||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); | ||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); | ||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); | ||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.ALPHA, 256, 1, 0, gl.ALPHA, gl.UNSIGNED_BYTE, this.array); | ||
|
||
} else { | ||
gl.bindTexture(gl.TEXTURE_2D, this.texture); | ||
if (this.changed) { | ||
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 256, 1, gl.ALPHA, gl.UNSIGNED_BYTE, this.array); | ||
this.changed = false; | ||
} else { | ||
gl.bindTexture(gl.TEXTURE_2D, this.texture); | ||
if (this.changed) { | ||
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 256, 1, gl.ALPHA, gl.UNSIGNED_BYTE, this.array); | ||
this.changed = false; | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
module.exports = FrameHistory; |
This file contains 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
Oops, something went wrong.