[JavaScript] RGB 색 랜덤하게 가져오기


[JavaScript] RGB 색 랜덤하게 가져오기

자바스크립트로 랜덤하게 컬러(RGB)를 가져오도록 해보자. 사용한 코드 function makeColor() { const r = Math.floor(Math.random() * 256); const g = Math.floor(Math.random() * 256); const b = Math.floor(Math.random() * 256); } rgb 색상은 각각 256가지의 정수 값 3개가 모여 만들어진다. ex) rgb(255, 155, 55) 0 ~ 255 = 256개이므로 Math.random()함수를 사용해 리턴한다.

Math.floor() Math.floor() 함수는 주어진 숫자와 같거나 작은 정수 중에서 가장 큰 수를 반환한다. Math.floor(c) Math.random() Math.r.....


원문링크 : [JavaScript] RGB 색 랜덤하게 가져오기