【发布时间】:2012-06-22 19:11:58
【问题描述】:
我想每 5、15、17 或 51 个 RGB 值生成一个调色板。
类似这样的:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Color Palette</title>
<style type="text/css">
div{margin:0;width:20px;height:20px;float:left}
.clear{clear:both}
</style>
</head>
<body>
<script>
var r = 0,
g = 0,
b = 0;
function createBr() {
var b = document.createElement('br');
b.style.clear = 'both';
document.body.appendChild(b);
}
function createDiv(r,g,b) {
var a = document.createElement('div');
a.style.background = 'rgb(' + r + ',' + g + ',' + b + ')';
document.body.appendChild(a);
}
function createColorPalette(value) {
var v = 255/value;
for(i = 0; i < v; i++) {
r = r + value;
g = g + value;
b = b + value;
createDiv(r,g,b);
}
createBr();
}
// put in 5,15,17 or 51 as value below
window.onload = createColorPalette(17);
</script>
</body>
</html>
我不够聪明,无法弄清楚如何用一个小脚本生成所有 3375 种颜色。任何想法如何做到这一点?
【问题讨论】:
-
永远不要以“不够聪明”开头。我不太确定我理解你所说的第 5、15、17 或 51 RGB 值是什么意思。你能举个例子吗?
-
查看这篇精彩的文章:krazydad.com/tutorials/makecolors.php
-
感谢K-man的提问!我忘了有 256 种颜色而不是 255(我忘了数“0”。5、15、17 和 51 是除 255 的好数字)。
-
谢谢约瑟夫,会调查的!
标签: javascript colors