不多啰啰,直接上硬货!
export function getRandomNum(min, max) {
let result;
if (min <= max) {
result = Math.floor(Math.random() * (max - min + 1) + min);
} else {
result = Math.floor(Math.random() * (min - max + 1) + max);
}
return result;
}
export function randomRGBA(alpha) {
const r = getRandomNum(0, 255);
const g = getRandomNum(0, 255);
const b = getRandomNum(0, 255);
return `rgba(${r},${g},${b},${alpha})`;
}
export function randomCoolColor(alpha) {
const r = 50;
const g = getRandomNum(0, 255);
const b = getRandomNum(150, 255);
return `rgba(${r},${g},${b},${alpha})`;
}
export function randomWarmColor(alpha) {
const r = 255;
const g = getRandomNum(0, 230);
const b = 50;
return `rgba(${r},${g},${b},${alpha})`;
}
export function randomTransparentGradient(alpha1, alpha2) {
const r = getRandomNum(0, 255);
const g = getRandomNum(0, 255);
const b = getRandomNum(0, 255);
return [`rgba(${r},${g},${b},${alpha1})`, `rgba(${r},${g},${b},${alpha2})`];
}
export function randomTransparentCoolGradient(alpha1, alpha2) {
const r = 50;
const g = getRandomNum(0, 255);
const b = getRandomNum(150, 255);
return [`rgba(${r},${g},${b},${alpha1})`, `rgba(${r},${g},${b},${alpha2})`];
}
export function randomTransparentWarmGradient(alpha1, alpha2) {
const r = 255;
const g = getRandomNum(0, 230);
const b = 50;
return [`rgba(${r},${g},${b},${alpha1})`, `rgba(${r},${g},${b},${alpha2})`];
}
export function randomGradient(alpha) {
const r = getRandomNum(0, 255);
const g = getRandomNum(0, 255);
const b = getRandomNum(0, 255);
return [`rgba(${r},${g},${b},${alpha})`, `rgba(${r},${g},${b},${alpha})`];
}
export function randomCoolGradient(alpha) {
const r = 50;
const g = getRandomNum(0, 255);
const b = getRandomNum(150, 255);
return [`rgba(${r},${g},${b},${alpha})`, `rgba(${r},${g},${b},${alpha})`];
}
export function randomWarmGradient(alpha) {
const r = 255;
const g = getRandomNum(0, 230);
const b = 50;
return [`rgba(${r},${g},${b},${alpha})`, `rgba(${r},${g},${b},${alpha})`];
}
export function randomWarmColorToRandomCoolColor(warmColorAlpha, coolColorAlpha) {
const wr = 255;
const wg = getRandomNum(0, 230);
const wb = 50;
const cr = 50;
const cg = getRandomNum(0, 255);
const cb = getRandomNum(150, 255);
return [`rgba(${wr},${wg},${wb},${warmColorAlpha})`, `rgba(${cr},${cg},${cb},${coolColorAlpha})`];
}
export function randomCoolColorToRandomWarmColor(coolColorAlpha, warmColorAlpha) {
const wr = 255;
const wg = getRandomNum(0, 230);
const wb = 50;
const cr = 50;
const cg = getRandomNum(0, 255);
const cb = getRandomNum(150, 255);
return [`rgba(${cr},${cg},${cb},${coolColorAlpha})`, `rgba(${wr},${wg},${wb},${warmColorAlpha})`];
}