Created
March 20, 2026 22:56
-
-
Save lardratboy/0a1dc44408696480e9b55d29cf739c38 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * Variable Bit-Depth Generator | |
| * @param {string} shape - 'lorenz', 'thomas', 'noise' | |
| * @param {number} depth - 8, 16, 32 | |
| * @param {num} number of points | |
| * @param {littleEndian} true or false | |
| */ | |
| function uintShapeGenerator(shape, depth, num, littleEndian ) { | |
| const compSize = depth / 8; | |
| const buf = new ArrayBuffer(num * compSize * 3); | |
| const v = new DataView(buf); | |
| const writeMethod = depth === 32 ? 'setUint32' : depth === 16 ? 'setUint16' : 'setUint8'; | |
| const maxVal = depth === 32 ? 4294967295 : depth === 16 ? 65535 : 255; | |
| let x=0.1, y=0, z=0; | |
| for(let i=0; i<num; i++) { | |
| if (shape === 'lorenz') { | |
| let dx=10*(y-x), dy=x*(28-z)-y, dz=x*y-(8/3)*z; | |
| x+=dx*0.005; y+=dy*0.005; z+=dz*0.005; | |
| // Map to [0, 1] then to Max range | |
| const nx = (x+25)/50, ny = (y+30)/60, nz = z/50; | |
| v[writeMethod](i*compSize*3, nx * maxVal, littleEndian); | |
| v[writeMethod](i*compSize*3 + compSize, ny * maxVal, littleEndian); | |
| v[writeMethod](i*compSize*3 + compSize*2, nz * maxVal, littleEndian); | |
| } else if (shape === 'thomas') { | |
| const b=0.208186; | |
| let dx=Math.sin(y)-b*x, dy=Math.sin(z)-b*y, dz=Math.sin(x)-b*z; | |
| x+=dx*0.05; y+=dy*0.05; z+=dz*0.05; | |
| v[writeMethod](i*compSize*3, ((x+2.5)/5) * maxVal, littleEndian); | |
| v[writeMethod](i*compSize*3 + compSize, ((y+2.5)/5) * maxVal, littleEndian); | |
| v[writeMethod](i*compSize*3 + compSize*2, ((z+2.5)/5) * maxVal, littleEndian); | |
| } else { | |
| v[writeMethod](i*compSize*3, Math.random() * maxVal, littleEndian); | |
| v[writeMethod](i*compSize*3 + compSize, Math.random() * maxVal, littleEndian); | |
| v[writeMethod](i*compSize*3 + compSize*2, Math.random() * maxVal, littleEndian); | |
| } | |
| } | |
| return buf; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment