p5.j​​s:这段代码怎么可以简化为' for'环?

时间:2017-09-06 02:56:05

标签: javascript

我有以下使用p5.js的代码。我怎样才能将其简化为' for'使用数组的循环?

The code I want simplified.

我已经尝试过但没有工作:

   var colorDiv = [redDiv, orangeDiv, yellowDiv, yellowGreenDiv, greenDiv, turquoiseDiv, cyanDiv, cobaltDiv, blueDiv, violetDiv, magentaDiv, crimsonDiv, blackDiv, whiteDiv, brownDiv, lightGreyDiv, darkGreyDiv];

var colorRGB = ["rgb(255,0,0)", "rgb(255,125,0)", "rgb(255,255,0)", "rgb(125,255,0)", "rgb(0,255,0)", "rgb(0,255,125)", "rgb(0,255,255)", "rgb(0,125,255)", "rgb(0,0,255)", "rgb(125,0,255)", "rgb(255,0,255)", "rgb(255,0,125)", "rgb(0,0,0)", "rgb(255,255,255)", "rgb(114, 64, 25)", "rgb(175,175,175)", "rgb(110,110,110)"]; ]

for (var i = colorDiv.length - 1; i >= 0; i--) {
    var string = String(colorDiv[i]);
    string = string.replace("Div", "");
    var colorDiv[i] = createDiv(string); // Red
    colorDiv[i].id();
    colorDiv[i].style("width", "30px");
    colorDiv[i].style("height", "30px");
    colorDiv[i].style("background-color", "" + colorRGB[i]);
}

0 个答案:

没有答案