Skip to content

Commit 76ff82b

Browse files
committed
simplify
1 parent 23f2a9f commit 76ff82b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/src/simulator.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import renderFragmentShaderSource from "./shaders/render-frag.glsl?raw";
66
// constnats
77
const PI = Math.PI;
88
const random = Math.random;
9+
const RANDOM_IMG_SIZE = 200;
910
/** shader names */
1011
// Uniforms
1112
const U_DT = "dt";
@@ -72,9 +73,9 @@ const getInitialData = (maxParticles: number) => {
7273
};
7374

7475
/** generate random RG data for source of randomness within the simulation */
75-
const randomRGData = (sizeX: number, sizeY: number): Uint8Array => {
76+
const randomRGData = (): Uint8Array => {
7677
const data = [];
77-
for (let i = 0; i < sizeX * sizeY; i++) data.push(random() * 255.0, random() * 255.0);
78+
for (let i = 0; i < 2 * RANDOM_IMG_SIZE ** 2; i++) data.push(random() * 255);
7879
return new Uint8Array(data);
7980
};
8081

@@ -212,12 +213,12 @@ const simulate = (
212213
gl.TEXTURE_2D,
213214
0,
214215
gl.RG8,
215-
200,
216-
200,
216+
RANDOM_IMG_SIZE,
217+
RANDOM_IMG_SIZE,
217218
0,
218219
gl.RG,
219220
gl.UNSIGNED_BYTE,
220-
randomRGData(200, 200),
221+
randomRGData(),
221222
);
222223

223224
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.MIRRORED_REPEAT);

0 commit comments

Comments
 (0)