mercredi 11 mai 2022

How do i make the background a Random hex color? Also so there are no duplicates

My PNG is a transparent background. when i run the script, it gives me the same 10 colors. When I set the brightness to 0% then no colors generate. Trying to make it so a random hex # is generated for each image and there are no repeats.

const gif = {
  export: false,
  repeat: 0,
  quality: 100,
  delay: 500,
};

const text = {
  only: false,
  color: getRandomColor(),
  size: 20,
  xGap: 40,
  yGap: 40,
  align: "left",
  baseline: "top",
  weight: "regular",
  family: "Courier",
  spacer: " => ",
};

function getRandomColor() {
  var letters = '0123456789ABCDEF';
  var color = '#';
  for (var i = 0; i < 6; i++) {
    color += letters[Math.floor(Math.random() * 16)];
  }
  return color;
}


'#'+(Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0');



function setRandomColor() {
  $("#colorpad").css("background-color", getRandomColor());
}

const pixelFormat = {
  ratio: 2 / 128,
};

const background = {
  generate: true,
  brightness: "50%",
  static: false,
  default: getRandomColor(),
};



Aucun commentaire:

Enregistrer un commentaire