0

这是一个不言自明的问题。

我很好奇为什么没有创建渐变的内置函数。我发现“伪造”的唯一方法是创建一系列线条或矩形,每个线条或矩形都具有使用 b.lerpColor 计算的独特颜色。

我看到 InDesign 对象模型当然有渐变类,但我不知道如何使用 basiljs 访问它。

也许如果有人可以告诉我?非常感谢。

4

1 回答 1

1

查看此参考http://jongware.mit.edu/idcs6js/pc_Gradient.html

并尝试这样:

#includepath "~/Documents/;%USERPROFILE%Documents";
#include "basiljs/bundle/basil.js";

function draw() {

  var d = b.doc();
  var r = b.rect(0, 0, b.width, b.height);
  var myGrad = d.gradients.add({
    name: "Col " + (parseInt(Math.random() * 10000)),
    type: GradientType.linear
  });

  myGrad.gradientStops[0].properties = {
    stopColor: d.colors.item(2),
    location: Math.random() * 50
  };
  myGrad.gradientStops[1].properties = {
    stopColor: d.colors.item(4),
    location: 50 + Math.random() * 50
  };
  r.fillColor = myGrad;
  // to set the fill of the gradient use the following line
  r.gradientFillAngle = 50;//b.random(-180,180);

}

b.go();

每次运行该脚本都会创建一个新的渐变色板。

编辑:添加渐变填充角度

看看这里

gradientFillAngle 数字 r/w 应用于矩形填充的线性渐变的角度。(范围:-180 到 180)

于 2014-03-08T16:50:26.993 回答