jquery
[Javascript] 랜덤색상 얻기
http://portfolio.wonpaper.net
2024. 2. 9. 03:43
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
// 랜덤색상
function getRandomColor() {
return "#" + Math.floor(Math.random() * 16777215).toString(16);
}
function getRandomColors(numColors) {
const colors = [];
const letters = '0123456789ABCDEF';
for (let i = 0; i < numColors; i++) {
let color = '#';
for (let j = 0; j < 6; j++) {
color += letters[Math.floor(Math.random() * 16)];
}
colors.push(color);
}
return colors;
}
const numColors = 4;
const randomColors = getRandomColors(numColors);
'#3CBD68','#65E390','#C3AD61','#3106C3'
|
cs |