Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JavaScript生成调色板_Javascript_Colors - Fatal编程技术网

使用JavaScript生成调色板

使用JavaScript生成调色板,javascript,colors,Javascript,Colors,我想每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}

我想每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>

调色板
div{margin:0;width:20px;height:20px;float:left}
.clear{clear:两个}
var r=0,
g=0,
b=0;
函数createBr(){
var b=document.createElement('br');
b、 style.clear='both';
文件.正文.附件(b);
}
函数createDiv(r,g,b){
var a=document.createElement('div');
a、 style.background='rgb('+r+'、'+g+'、'+b+');
文件.正文.附件(a);
}
函数createColorPalette(值){
var v=255/个值;
对于(i=0;i

我没有足够的智慧去弄清楚如何用一个小脚本生成所有3375种颜色。你知道怎么做吗?

循环每种颜色的分数,如下所示:

function createColorPalette(value) {
    var v = 255/value;
    for( var rStep = 0, r = 0; rStep < v; rStep++) {    
        for( var gStep = 0, g = 0; gStep < v; gStep++ ) {       
            for( var bStep = 0, b = 0; bStep < v; bStep++ ) {                                                  
                createDiv(r,g,b);
                b += value;
            }
            g += value;
        }
        r += value;
    }
    createBr();
}
函数createColorPalette(值){
var v=255/个值;
对于(var-rStep=0,r=0;rStep
切勿以“不够聪明”开头。我不太确定我是否理解您所说的第5、15、17或51个RGB值的含义。你能举出一个例子吗?看看这篇惊人的文章:Thansk问K-man!我忘了有256种颜色,而不是255种(我忘了数“0”。5、15、17和51是区分255的好数字。谢谢约瑟夫,我会调查的!你忘了一个结束标签。但无论如何都不行。它只生成许多白色div标签。对不起,我想我已经全部修复了。不确定这是否是你想要的样子,但我认为它符合所有的颜色。这是我问题的答案。。。谢谢:)这是一本书。这个简单的解决方案既不能防止相似的颜色显示,也不能使它们保持光谱顺序。