static webglWidth = 256 * 4
static webglHeight = 256 * 4
static gl = new OffscreenCanvas(this.webglWidth, this.webglHeight).getContext('webgl2')
+ static work0 = new Uint8Array(4)
+ static work1 = new Uint8Array(4)
static hexify (arr: number[] | Uint8Array): string {
let out = ''
const work1Location = this.gl.getUniformLocation(program, 'u_work1')
// Draw output until success or progressCallback says to stop
- const work0 = new Uint8Array(4)
- const work1 = new Uint8Array(4)
const draw = (): void => {
if (this.gl == null) throw new Error('webgl2_required')
const start = performance.now()
- crypto.getRandomValues(work0)
- crypto.getRandomValues(work1)
+ crypto.getRandomValues(this.work0)
+ crypto.getRandomValues(this.work1)
- this.gl.uniform4uiv(work0Location, work0)
- this.gl.uniform4uiv(work1Location, work1)
+ this.gl.uniform4uiv(work0Location, this.work0)
+ this.gl.uniform4uiv(work1Location, this.work1)
this.gl.clear(this.gl.COLOR_BUFFER_BIT)
this.gl.drawArrays(this.gl.TRIANGLES, 0, 6)
console.log(`frame time: ${performance.now() - start}`)
// Return the work value with the custom bits
typeof callback === 'function' &&
- callback(this.hexify(work1) + this.hexify([
+ callback(this.hexify(this.work1) + this.hexify([
pixels[i + 2],
pixels[i + 3],
- work0[2] ^ (pixels[i] - 1),
- work0[3] ^ (pixels[i + 1] - 1)
+ this.work0[2] ^ (pixels[i] - 1),
+ this.work0[3] ^ (pixels[i + 1] - 1)
]))
return
}