Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function paleta(toreturn = []) { //
- var poss = "0123456789ABCDEF",
- comb = "";
- for (var i = 0, max = poss.length; i < 16777216 * 6; i++) { // 16,777,216 * 6 , ya que cada color necesita 6 iteraciones
- let random = poss[Math.floor(Math.random() * max)]; // letra o numero aleatorio
- comb += random; // concateno la letra o numero que se ha formado aleatoriamente
- if (comb.length === 6 && !toreturn.includes(comb)) { // si el color ya tiene sus 6 digitos y además el color no está en el array
- toreturn.push("#" + comb); // introduzco el color al array
- comb = ""; // y vacio nuevamente para formar OTRO color
- }
- if (comb.length === 6 && toreturn.includes(comb)) i -= 6;
- /* En este if, si el color YA se ha formado y a su vez YA estaba en el array
- de los colores, entonces resto 6 a i , para que todas las iteraciones
- con las que se formó ese color, no se pierdan, ya que ese color YA ESTABA. */
- }
- return toreturn; // retorno el array
- }
- console.log(paleta().length) // Aprox: 4000 colores
Add Comment
Please, Sign In to add comment