utilities.js 372 B

12345678910111213141516171819
  1. import { Color } from 'three';
  2. const colors = {};
  3. // Return a consistant random color for an index
  4. export function getIndexedRandomColor( index ) {
  5. if ( ! colors[ index ] ) {
  6. const h = Math.random();
  7. const s = 0.5 + Math.random() * 0.5;
  8. const l = 0.375 + Math.random() * 0.25;
  9. colors[ index ] = new Color().setHSL( h, s, l );
  10. }
  11. return colors[ index ];
  12. }