Search code examples
javascriptadobe-indesignbasil.js

Drawing Starbursts – basil.js


I am trying to draw a starburst by first drawing a polygon and then adjusting its properties.

on indesignjs.de it says a polygon is any shape that is not a rectangle, ellipse, or graphic line. When you add a polygon, InDesign creates a regular polygon based on the current polygon preferences settings. But I can't for the life of me figure out how to draw the damn thing.

I wrote this:

    var myPolygon = polygon(0, 0, 10, 10);
    property(myPolygon, "numberOfSides", 8);
    property(myPolygon, "insetPercentage", 50);

but I get an error in indesign saying that polygon is not a function. Is is truncated like rectangle is (i.e. poly)?


Solution

  • As fabianmoronzirfas pointed out, polygon() is not a basil.js function (as opposed to rect()). So either you would have to draw the shape yourself using basil commands like this:

    beginShape();
      vertex(23, 45);
      vertex(34, 67);
      // draw as many vertices as you need
    endShape(CLOSED);
    

    or you would have to use proper (non-basil) InDesign scripting commands to shape your polygon. The thing you want to achieve can be done by using the convertShape() method, which can be used on any shape, so you could create a rect first and then use this method on the rect:

    // @include ~/Documents/basiljs/basil.js;
    
    function draw() {
    
      var myPoly = rect(50, 50, 200, 200);
      myPoly.convertShape(ConvertShapeOptions.CONVERT_TO_POLYGON, 8, 50);
    
    }