Question

It's a pretty self-explanatory question.

I am curious as to why there is no built-in function to create gradients. The only way I found to "fake it" is to create a series of lines or rectangles each with a unique color calculated with b.lerpColor.

I saw that the InDesign Object Model has of course the gradient class but I don't know how to access it using basiljs.

Maybe if someone could show me? Many thanks.

Was it helpful?

Solution

Check out this reference http://jongware.mit.edu/idcs6js/pc_Gradient.html

And try it like this:

#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();

The script creates a new gradient swatch every time you run it.

edit:added gradientFillAngle

Take a look here.

gradientFillAngle number r/w The angle of a linear gradient applied to the fill of the Rectangle. (Range: -180 to 180)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top