Skip to content

Instantly share code, notes, and snippets.

@nbriz
Last active November 30, 2024 19:24
Show Gist options
  • Select an option

  • Save nbriz/0d92ea0b91a81c7dd6fd to your computer and use it in GitHub Desktop.

Select an option

Save nbriz/0d92ea0b91a81c7dd6fd to your computer and use it in GitHub Desktop.
animate random mesh color, for threjs_playGnd
/* ------------------- INSTRUCTIONS -----
to animate random colors
add the code below to your draw() fucntion
-------------------------------------- */
var randomColor = Math.random() * 0xffffff;
mesh.material.color.setHex(randomColor);
// ** NOTE ** only 'Basic', 'Lambert' and 'Phong'
// material have a color property, the
// 'Normal' material has no color property
/* --------------------------------------
try also, moving and/or spinning your mesh
add the code below to your draw() function
-------------------------------------- */
mesh.position.x = Math.sin( Date.now() * 0.001 ) * 50;
mesh.rotation.z = Date.now() * 0.0005;
/* --------------------------------------
try also leaving trails
replace the 'renderer = new ...' on line 27
in the setup() function, with the code below
-------------------------------------- */
renderer = new THREE.WebGLRenderer( { preserveDrawingBuffer: true } );
renderer.autoClearColor = false;
@superjcybs
Copy link

I still dont get how to implement this. Please help me out
jerrybabatunde1@gmail.com

@nbriz
Copy link
Author

nbriz commented Nov 30, 2024

this code is over 10 years old now, so it likely wont' work unless u're using a very old version of three.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment