HSL

Basil.js, color, HSL, color-model
Fabian Morón Zirfas

Some color wheel.

/** eslint-disable */
#includepath "~/Documents/;%USERPROFILE%Documents"; // eslint-disable-line
#include "basiljs/bundle/basil.js";// eslint-disable-line
// Unfortunately InDesign does not know how to use HSL colors
// so we need to use a function we found on the web to make
// harmonic colors
var pw = 200; // for easier handling
var ph = 200; // for easier handling

function draw() {
  b.clear(b.doc()); // clear the current document
  b.units(b.MM); // we want to print. use MM instead of default pixels
  b.ellipseMode(b.CENTER); // draw 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: pw,
    pageHeight: ph
  }; // set the page size
  doc.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN; // upper left corner
  // ----------
  //
  // main code goes here
  var steps = 5;
  var x = 0;
  var distance = 200;
  var counter = 0;
  var saturation = 10;
  var brightness = 50;
  b.noStroke();
  for (var angle = distance; angle <= distance*steps; angle += distance) {
     var colors = color_hsl2rgb(angle%360, saturation, brightness);
    var red = colors.r;
    var green = colors.g;
    var blue = colors.b;
    b.fill(red, green, blue);
    b.rect(x, 0, b.width / steps, b.height);
    x += b.width / steps;
    counter++;
  }
  //
  // ----------
  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');
}



function color_HueToRgb(m1, m2, hue) {
  var v = null;
  if (hue < 0) {
    hue += 1;
  } else if (hue > 1) {
    hue -= 1;
  }
  if (6 * hue < 1) {
    v = m1 + (m2 - m1) * hue * 6;
  } else if (2 * hue < 1) {
    v = m2;
  } else if (3 * hue < 2) {
    v = m1 + (m2 - m1) * (2 / 3 - hue) * 6;
  } else {
    v = m1;
  }
  return 255 * v;
}

function color_hsl2rgb(h, s, l) {
  var m1 = null;
  var m2 = null;
  var hue = null;
  var r = null;
  var g = null;
  var blue = null;

  s /= 100;
  l /= 100;
  if (s === 0) {
    r = g = blue = (l * 255);
  } else {
    if (l <= 0.5) {
      m2 = l * (s + 1);
    } else {
      m2 = l + s - l * s;
    }
    m1 = l * 2 - m2;
    hue = h / 360;
    r = color_HueToRgb(m1, m2, hue + 1 / 3);
    g = color_HueToRgb(m1, m2, hue);
    blue = color_HueToRgb(m1, m2, hue - 1 / 3);
  }
  return {
    r: r,
    g: g,
    b: blue
  };
}

b.go();