I'm currently exploring three.js and encountering some difficulties when attempting to adjust the color of individual sprites in an array.
My reference point is the example provided on this link from threejs.org.
The specific task I am working on involves changing the color of each sprite based on its scale value. To achieve this, I inserted the following line of code into the final function within the source file:
function render() {
camera.position.x += ( mouseX - camera.position.x ) * .05;
camera.position.y += ( - mouseY - camera.position.y ) * .05;
camera.lookAt( scene.position );
var i = 0;
for ( var ix = 0; ix < AMOUNTX; ix ++ ) {
for ( var iy = 0; iy < AMOUNTY; iy ++ ) {
particle = particles[ i++ ];
particle.position.y = ( Math.sin( ( ix + count ) * 0.3 ) * 50 ) +
( Math.sin( ( iy + count ) * 0.5 ) * 50 );
particle.scale.x = particle.scale.y = ( Math.sin( ( ix + count ) * 0.3 ) + 1 ) * 4 +
( Math.sin( ( iy + count ) * 0.5 ) + 1 ) * 4;
// Added this line in an attempt to change color based on scale //
particle.material.color.setHSL(particle.scale.x * .1, .2, .2);
}
}
renderer.render( scene, camera );
count += 0.1;
}
Despite my efforts, the additional line altered all particles to have identical color values. I presumed that each element in the array would be accessed and modified within the loop, yet this does not appear to be the case.