gpt4 book ai didi

javascript - For 循环代码将每个循环的 x 轴间距加倍

转载 作者:行者123 更新时间:2023-12-02 23:01:41 25 4
gpt4 key购买 nike

我正在尝试在 Photoshop 中创建一个图案脚本,在整个 Canvas 上水平和垂直复制图像。但问题是,在 x 轴上,每次循环它的值都会加倍。如果我删除“j”循环,它就可以正常工作。

这张图片将向您展示我提到的问题/image/ZkPrX.jpg

        var offset = parseInt(prompt("Type in the offset (spacing between pics) value here.\nDefault is 0px.", "0"));
for (var i = 0; i < width / (layerWidth + offset); i++) {
for (var j = 0; j < 3; j++) {
app.activeDocument.layers[i, j].duplicate()
app.activeDocument.layers[i, j].translate(i * (layerWidth + offset), j * (layerHeight + offset));
}
}

最佳答案

正如火山提到的,layers[i, j] 不是访问图层的有效方法。我什至不知道为什么这有效。您应该选择原始图层,制作副本并翻译它。像这样的事情:

var width = activeDocument.width.as("px");
var height = activeDocument.height.as("px");
var layer = app.activeDocument.activeLayer;
var layerWidth = layer.bounds[2] - layer.bounds[0];
var layerHeight = layer.bounds[3] - layer.bounds[1];
var copy, i, j;

var offset = parseInt(prompt("Type in the offset (spacing between pics) value here.\nDefault is 0px.", "0"));

for (i = 0; i < width / (layerWidth + offset); i++)
{
for (j = 0; j < height / (layerHeight + offset); j++)
{
// in the each loop we select the original layer, make a copy and offset it to calculated values
app.activeDocument.activeLayer = layer;
copy = layer.duplicate();
copy.translate(i * (layerWidth + offset), j * (layerHeight + offset));
}
}

layer.remove(); // remove the original layer

结果:

enter image description here

关于javascript - For 循环代码将每个循环的 x 轴间距加倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57755199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com