-
Notifications
You must be signed in to change notification settings - Fork 30
Colorbrewer
fabiantheblind edited this page Nov 19, 2015
·
3 revisions
Colorbrewer is a nice application for creating color schemes. It comes with an .ase (Adobe Swatch Exchange) export. The downside is this export creates cmyk swatches when imported to InDesign. So I wrote up a tiny helper.
Also I wanted to try the Array.prototype.map function. Unfortunately it is not present in ExtendScript so I had to add it as prototype.
// this is what your get if you get when you export from http://colorbrewer2.org
//
// ["rgb(197,27,125)", "rgb(233,163,201)", "rgb(253,224,239)", "rgb(247,247,247)", "rgb(230,245,208)", "rgb(161,215,106)", "rgb(77,146,33)"]
//
// and select the javaScript colors
// lets play with it
/**
* this is our runner function.
* Everything is in here
* @return {None} returns nothing
*/
var run = function() {
// our colors
var cols = [
"rgb(197,27,125)",
"rgb(233,163,201)",
"rgb(253,224,239)",
"rgb(247,247,247)",
"rgb(230,245,208)",
"rgb(161,215,106)",
"rgb(77,146,33)"
];
var d = app.activeDocument; // current document
// unfortunately the Array map function does not exist in ExtendScript
// see this
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
//
cols.map(function(i) {
i = i.replace(/rgb\((.*?)\)/g, "$1"); // remove unused stuff
var vals = i.split(","); // make a new array from it
var colname = "color " + vals.toString(); // create a name
var color = null; // will be the color
try {
// this is a test if the color alredy exists
// if so
color = d.colors.item(colname);
var tempname = color.name; // <-- This will throw an error
} catch (e) {
// the color with that name does not exist.
// Create it
color = d.colors.add({
name: colname,
model: ColorModel.PROCESS,
space: ColorSpace.RGB,
colorValue: [parseInt(vals[0]), parseInt(vals[1]), parseInt(vals[2])]
}); // add a new color
} // end catch
}); // end col.map
}; // end run function
// This is a prototype function
if (!Array.prototype.map) {
Array.prototype.map = function(fun /*, thisArg */ ) {
"use strict";
if (this === void 0 || this === null)
throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function")
throw new TypeError();
var res = new Array(len);
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
for (var i = 0; i < len; i++) {
// NOTE: Absolute correctness would demand Object.defineProperty
// be used. But this method is fairly new, and failure is
// possible only if Object.prototype or Array.prototype
// has a property |i| (very unlikely), so use a less-correct
// but more portable alternative.
if (i in t)
res[i] = fun.call(thisArg, t[i], i, t);
}
return res;
};
}
run(); // <-- run that thing
This wiki is maintained by:
fabiantheblind
Thanks to:
- JohnDarnell for fixing lots of typos.
- jsp for fixing lots of typos.
- ltfschoen for fixing typos.
- wridgers for adding more links.
Thanks to the students from the seminar for asking all those questions and making me start this wiki.
- adinaradke
- AnitaMei
- ce0311
- coerv
- felixharle
- FerdinandP
- Flave
- marche
- monkian
- natael
- OliverMatelowski
- PDXIII
- praktischend
- schlompf
- skaim
You are awesome.
- Arrays
- Classes
- Comments
- Conditionals
- Functions
- Inspect Properties
- Loops
- Objects
- Output And Interaction
- Recursive Functions
- Inspect Properties
- Variables And Operations
- Extended JavaScript Guide
- Bridge Talk
- Create And Read Files
- ExtendScript Toolkit
- File
- Folder
- Includes JSX
- Object Watch
- Read In JSON From File And DONT Eval
- Storing Data In A Target Engine
- Target an application
- XML
- app
- Colorbrewer
- Colors And Swatches
- Delay And View
- Dialogs
- Documents
- Duplicate And Transform
- Event AfterSave
- Export IDML
- ExtendScript in InDesign Scripting DOM
- Fonts
- GeometricBounds and Coordinates
- Get named pageItems
- Graphic Lines
- Groups
- HSL Color Wheel
- Images
- Includes
- InsertionPoints
- Layers
- Line Feeds And Carrige Returns
- Masterspreads
- Matrix
- Objectstyles
- Outlines Groups Alignment
- Pages And Margins
- Pathfinder
- Placeholder Text
- Rectangles Ovals Polygons
- RulerOrigin
- Select words at insertionPoint
- Simple Find And Change Grep with FC Query
- Simple Find And Change Grep
- Simple Find And Change Text
- Spiro
- Styles
- Text Analysis ID FC
- Text Analysis
- Text Find Locations
- Text
- Transformation Matricies
- TransparencySettings
- XML creation and import