@@ -12,6 +12,7 @@ const U_RANDOM_RG = "rg";
1212const U_FORCE_FIELD = "g" ; /** gravity */
1313const U_ORIGIN = "o" ;
1414const U_ANGLE_RANGE = "aR" ;
15+ const U_PARTICLE_COLOR = "c" ;
1516
1617// inputs
1718const IN_POSITION = "p" ;
@@ -30,6 +31,8 @@ let mouseX = 0,
3031type Vector2D = [ number , number ] ;
3132
3233export interface ParticlesOptions {
34+ /** particle Color @defaultValue [1, 0, 0, 1] -> red */
35+ rgba ?: [ number , number , number , number ] ;
3336 /** @defaultValue 100_000 */
3437 maxParticles ?: number ;
3538 /** @defaultValue 0.5 */
@@ -50,6 +53,7 @@ export interface ParticlesOptions {
5053}
5154
5255const defaultOptions : ParticlesOptions = {
56+ rgba : [ 1 , 0 , 0 , 1 ] ,
5357 maxParticles : 100_000 ,
5458 generationRate : 0.5 ,
5559 forceField : [ 0 , - 0.1 ] ,
@@ -247,6 +251,8 @@ const simulate = (gl: WebGL2RenderingContext, options: ParticlesOptions) => {
247251 gl . bindBufferBase ( gl . TRANSFORM_FEEDBACK_BUFFER , 0 , null ) ;
248252 gl . bindVertexArray ( vertexArrayObjects [ readIndex + 2 ] ) ;
249253 gl . useProgram ( renderProgram ) ;
254+ // skipcq: JS-0339 -- set in default options
255+ gl . uniform4f ( gl . getUniformLocation ( renderProgram , U_PARTICLE_COLOR ) , ...options . rgba ! ) ;
250256 gl . drawArrays ( gl . POINTS , 0 , bornParticles ) ;
251257 [ readIndex , writeIndex ] = [ writeIndex , readIndex ] ;
252258
0 commit comments