渐变
gradient
文档中包含的渐变定义。脚本可以创建新的渐变。
Gradient.gradientStops
Section titled “Gradient.gradientStops”gradient.gradientStops
此渐变中包含的渐变停止点。
GradientStops; 只读。
Gradient.name
Section titled “Gradient.name”gradient.name
渐变的名称。
字符串。
Gradient.parent
Section titled “Gradient.parent”gradient.parent
包含此渐变的文档。
Document; 只读。
Gradient.type
Section titled “Gradient.type”gradient.type
渐变的类型,径向或线性。
Gradient.typename
Section titled “Gradient.typename”gradient.typename
引用对象的类名。
字符串; 只读。
Gradient.remove()
Section titled “Gradient.remove()”app.activeDocument.gradients[index].remove()
从文档中移除引用的对象。
无。
创建并应用渐变
Section titled “创建并应用渐变”// 在当前文档中创建一个新渐变,然后将渐变应用到最前面的路径项
if (app.documents.length > 0) { // 为渐变的两个端点创建颜色 var startColor = new RGBColor(); startColor.red = 0; startColor.green = 100; startColor.blue = 255;
var endColor = new RGBColor(); endColor.red = 220; endColor.green = 0; endColor.blue = 100;
// 创建一个新渐变 // 新渐变始终有2个停止点 var newGradient = app.activeDocument.gradients.add(); newGradient.name = "NewGradient"; newGradient.type = GradientType.LINEAR;
// 修改第一个渐变停止点 newGradient.gradientStops[0].rampPoint = 30; newGradient.gradientStops[0].midPoint = 60; newGradient.gradientStops[0].color = startColor;
// 修改最后一个渐变停止点 newGradient.gradientStops[1].rampPoint = 80; newGradient.gradientStops[1].color = endColor;
// 构造一个引用新创建的渐变的 Illustrator.GradientColor 对象 var colorOfGradient = new GradientColor(); colorOfGradient.gradient = newGradient;
// 获取第一个路径项,将新渐变应用为其填充 var topPath = app.activeDocument.pathItems[0]; topPath.filled = true; topPath.fillColor = colorOfGradient;}