Triangle with Shadow

Basil.js, distored, duplicate, form
Fabian Morón Zirfas

Some triangles with shadows

#includepath "~/Documents/;%USERPROFILE%Documents"; // eslint-disable-line
#include "basiljs/bundle/basil.js";
// simple sketch showing the usage of some primitive forms
function draw() {
  b.clear(b.doc()); // clear the current document
  b.units(b.MM); // we want to print. use MM intead of default pixels
  b.rectMode(b.CENTER); // draw rects from the center
  b.ellipseMode(b.CENTER); // draw ellipses from the center
  var doc = b.doc(); // a reference to the current document
  // set some preferneces of the document for better handling
  doc.documentPreferences.properties = {
    pageWidth: 200,
    pageHeight: 200
  };
  doc.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN;
   b.fill(255);
  b.beginShape(b.CLOSE);
  var xcenter = b.width / 2;
  var ycenter = b.height / 2;
  var radius = 100;
  var degree = 120;
  var magicNumber = 30; // to turn the triangle upwards
  var trianglePoints = [];
  for (var i = 0; i < 3; i++) {
    var x = (b.cos(b.radians(degree * i + magicNumber)) * radius / 2) + xcenter;
    var y = (b.sin(b.radians(degree * i + magicNumber)) * radius / 2) + ycenter;
    trianglePoints.push([x, y]);
    b.vertex(x, y);
    // if you want to prolong the points until the end of the page
    // uncomment the following lines
    // var x2 = x;
    // var y2 = y;
    // var offset = 1;
    // var rad = 1;
    // while ((x2 < b.width && x2 > 0) && (y2 < b.height && y2 > 0)) {
    //   x2 = x + (x - (xcenter)) / (b.dist(x, y, xcenter, ycenter)) * offset;
    //   y2 = y + (y - (ycenter)) / (b.dist(x, y, xcenter, ycenter)) * offset;
    //   b.ellipse(x2, y2, rad, rad);
    //   offset += rad;
    // }
  }
  b.endShape();
  b.fill(0);
  for (var j = 0; j < 100; j++) {
    b.beginShape(b.CLOSE);
    for (var k = 0; k < trianglePoints.length; k++) {
      var random = b.random(-20, 20);
      b.vertex(trianglePoints[k][0] + random, trianglePoints[k][1] + random);
    }
    var tri = b.endShape();
    // this is some styling
    tri.sendToBack();
    tri.properties = {
      fillTint:70,
      strokeTint: 50,
      transparencySettings: {
        blendingSettings: {
          opacity: 10,
          blendMode: BlendMode.MULTIPLY
        },
        featherSettings: {
          mode: FeatherMode.STANDARD, // <-- We need this to activate the feather
          chokeAmount: 10,
          cornerType: FeatherCornerType.DIFFUSION
        }
      }
    };
  }
  // b.ellipse(xcenter, ycenter, radius, radius);
  // b.line(0, 0, b.width, b.height);
  // b.line(0, b.height, b.width, 0);
  var fname = File($.fileName).parent.fsName + '/' + // eslint-disable-line
    ($.fileName.split('/')[$.fileName.split('/').length - 1]).split('.')[0] + '.indd';
  b.println(fname);
  doc.save(fname, false, 'basil', true);
  b.savePNG('out.png');
}
b.go();