From 4c775d927f56a97fedaae4ac371daba44a61d1cd Mon Sep 17 00:00:00 2001 From: trych Date: Sat, 30 Sep 2017 16:54:12 +0200 Subject: [PATCH] Transferring all example scripts --- color/blendMode.jsx | 37 ++++++ color/color.jsx | 47 ++++++++ color/fill.jsx | 15 +++ color/fillTint.jsx | 18 +++ color/gradient.jsx | 53 +++++++++ color/lerpColor.jsx | 21 ++++ color/opacity.jsx | 20 ++++ color/stroke.jsx | 17 +++ color/strokeTint.jsx | 18 +++ data/HashList.jsx | 49 ++++++++ data/csv.jsx | 51 +++++++++ data/json.jsx | 49 ++++++++ document/groups.jsx | 30 +++++ document/labels.jsx | 27 +++++ document/nameOnPage.jsx | 37 ++++++ document/selections.jsx | 23 ++++ document/story.jsx | 31 +++++ environment/canvasMode.jsx | 42 +++++++ environment/guide.jsx | 19 ++++ environment/modes.jsx | 39 +++++++ environment/pages.jsx | 51 +++++++++ environment/size.jsx | 41 +++++++ environment/units.jsx | 21 ++++ environment/width-and-height.jsx | 9 ++ image/image.jsx | 33 ++++++ image/imageMode.jsx | 21 ++++ image/transformImage.jsx | 12 ++ input/loadStringURL.jsx | 23 ++++ input/loadStrings.jsx | 33 ++++++ input/shellExecute.jsx | 19 ++++ loop/animated nonsense ball.jsx | 48 ++++++++ loop/fontsize interactive.jsx | 21 ++++ loop/server.jsx | 61 ++++++++++ loop/simple pong.jsx | 93 +++++++++++++++ output/download.jsx | 27 +++++ output/inspect.jsx | 15 +++ output/savePDF.jsx | 18 +++ output/saveStrings.jsx | 16 +++ random/random.jsx | 18 +++ shape/arc.jsx | 35 ++++++ shape/bounds.jsx | 34 ++++++ shape/ellipseMode.jsx | 18 +++ shape/golan_bezier_arc.jsx | 152 +++++++++++++++++++++++++ shape/line.jsx | 23 ++++ shape/rectMode.jsx | 15 +++ shape/strokeWeight.jsx | 18 +++ shape/vertex.jsx | 51 +++++++++ structure/delay.jsx | 13 +++ structure/forEach-loops.jsx | 32 ++++++ template.jsx | 9 ++ transform/itemPositioning.jsx | 46 ++++++++ transform/pushMatrix and popMatrix.jsx | 53 +++++++++ typography/RandomFonts.jsx | 22 ++++ typography/linkTextFrames.jsx | 22 ++++ typography/placeholder.jsx | 29 +++++ typography/styles.jsx | 65 +++++++++++ typography/text.jsx | 20 ++++ typography/textAlign.jsx | 66 +++++++++++ typography/typo.jsx | 48 ++++++++ 59 files changed, 1994 insertions(+) create mode 100644 color/blendMode.jsx create mode 100644 color/color.jsx create mode 100644 color/fill.jsx create mode 100644 color/fillTint.jsx create mode 100644 color/gradient.jsx create mode 100644 color/lerpColor.jsx create mode 100644 color/opacity.jsx create mode 100644 color/stroke.jsx create mode 100644 color/strokeTint.jsx create mode 100644 data/HashList.jsx create mode 100644 data/csv.jsx create mode 100644 data/json.jsx create mode 100644 document/groups.jsx create mode 100644 document/labels.jsx create mode 100644 document/nameOnPage.jsx create mode 100644 document/selections.jsx create mode 100644 document/story.jsx create mode 100644 environment/canvasMode.jsx create mode 100644 environment/guide.jsx create mode 100644 environment/modes.jsx create mode 100644 environment/pages.jsx create mode 100644 environment/size.jsx create mode 100644 environment/units.jsx create mode 100644 environment/width-and-height.jsx create mode 100644 image/image.jsx create mode 100644 image/imageMode.jsx create mode 100644 image/transformImage.jsx create mode 100644 input/loadStringURL.jsx create mode 100644 input/loadStrings.jsx create mode 100644 input/shellExecute.jsx create mode 100644 loop/animated nonsense ball.jsx create mode 100644 loop/fontsize interactive.jsx create mode 100644 loop/server.jsx create mode 100644 loop/simple pong.jsx create mode 100644 output/download.jsx create mode 100644 output/inspect.jsx create mode 100644 output/savePDF.jsx create mode 100644 output/saveStrings.jsx create mode 100644 random/random.jsx create mode 100644 shape/arc.jsx create mode 100644 shape/bounds.jsx create mode 100644 shape/ellipseMode.jsx create mode 100644 shape/golan_bezier_arc.jsx create mode 100644 shape/line.jsx create mode 100644 shape/rectMode.jsx create mode 100644 shape/strokeWeight.jsx create mode 100644 shape/vertex.jsx create mode 100644 structure/delay.jsx create mode 100644 structure/forEach-loops.jsx create mode 100644 template.jsx create mode 100644 transform/itemPositioning.jsx create mode 100644 transform/pushMatrix and popMatrix.jsx create mode 100644 typography/RandomFonts.jsx create mode 100644 typography/linkTextFrames.jsx create mode 100644 typography/placeholder.jsx create mode 100644 typography/styles.jsx create mode 100644 typography/text.jsx create mode 100644 typography/textAlign.jsx create mode 100644 typography/typo.jsx diff --git a/color/blendMode.jsx b/color/blendMode.jsx new file mode 100644 index 0000000..f3dd5b4 --- /dev/null +++ b/color/blendMode.jsx @@ -0,0 +1,37 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + b.clear(b.doc()); + + var red = b.color(255, 0, 0); + var lightBlue = b.color(0, 255, 255); + + b.fill(red); + b.ellipse(b.width / 3, b.height / 2, 333, 333); + b.fill(lightBlue); + var circle = b.ellipse(b.width / 3 * 2, b.height / 2, 333, 333); + + /* + BlendMode.NORMAL + BlendMode.MULTIPLY + BlendMode.SCREEN + BlendMode.OVERLAY + BlendMode.SOFT_LIGHT + BlendMode.HARD_LIGHT + BlendMode.COLOR_DODGE + BlendMode.COLOR_BURN + BlendMode.DARKEN + BlendMode.LIGHTEN + BlendMode.DIFFERENCE + BlendMode.EXCLUSION + BlendMode.HUE + BlendMode.SATURATION + BlendMode.COLOR + BlendMode.LUMINOSITY + */ + + b.blendMode(circle, BlendMode.HARD_LIGHT); +} + +b.go(); diff --git a/color/color.jsx b/color/color.jsx new file mode 100644 index 0000000..0dab3fe --- /dev/null +++ b/color/color.jsx @@ -0,0 +1,47 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + // get the number of swatches, to see later how many new ones have been created + var swatchCount = b.doc().swatches.length; + b.println("Document has " + swatchCount + " swatches"); + + b.println("Default colormode is: " + b.colorMode()); + + // create RGB colors + b.colorMode(b.RGB); + var red = b.color(255, 2, 3); + var green = b.color(0, 255, 0, "my green"); // set the name of the RBG color, see colour window + var rgbGrey = b.color(128); + + b.stroke(rgbGrey); + b.fill(red); + b.rect(0, 0, b.width, 50); + b.fill(green); + b.rect(0, 50, b.width, 50); + + + // create CMYK colors + b.colorMode(b.CMYK); + var magenta = b.color(1, 100, 3, 4); + var yellow = b.color(0, 0, 100, 0, "my yellow"); // set the name of the CMYK color, see colour window + var cmykGrey = b.color(80, "my light grey"); + + b.stroke(cmykGrey); + b.fill(magenta); + b.rect(0, 200, b.width, 50); + b.fill(yellow); + b.rect(0, 250, b.width, 50); + + // get a color from the document via the name + b.fill(b.color("my green")); + b.rect(0, 500, b.width, 50); + // a few colors like "Black" are predefined in every indesign document + var black = b.color("Black"); + b.fill(black); + b.rect(0, 550, b.width, 50); + + b.println(b.doc().swatches.length - swatchCount + " colors added to the swatches of the document"); +} + +b.go(); diff --git a/color/fill.jsx b/color/fill.jsx new file mode 100644 index 0000000..c707cd8 --- /dev/null +++ b/color/fill.jsx @@ -0,0 +1,15 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + // create new random RGB color + var newRandomColor = b.color(b.random(0, 255), + b.random(0, 255), + b.random(0, 255)); + + // fill rect with it + b.fill(newRandomColor); + b.rect(0, 0, b.width, b.height); +} + +b.go(); diff --git a/color/fillTint.jsx b/color/fillTint.jsx new file mode 100644 index 0000000..2ccccbf --- /dev/null +++ b/color/fillTint.jsx @@ -0,0 +1,18 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + var counter = 50; + b.noStroke(); + var rectHeight = b.height / counter; + + for (var i = 0; i < counter; i++) { + var y = b.map(i, 0, counter - 1, 0, b.height - rectHeight); + var fillTint = b.map(i, 0, counter - 1, 100, 0); + + b.fillTint(fillTint); + b.rect(0, y, b.width, rectHeight); + } +} + +b.go(); diff --git a/color/gradient.jsx b/color/gradient.jsx new file mode 100644 index 0000000..00be1e9 --- /dev/null +++ b/color/gradient.jsx @@ -0,0 +1,53 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + b.clear(b.doc()); + b.noStroke(); + + var dist = b.height / 4; + + // create two colors + var red = b.color(255, 0, 0); + var blue = b.color(0, 0, 255); + + // create array with 10 random colors + var randomColors = []; + for (var i = 0; i < 10; i++) { + randomColors.push(b.color(b.random(0, 255), b.random(0, 255), b.random(0, 255))); + } + + // create array with 10 random numbers (0-100) + var randomNumbers = []; + for (var j = 0; j < 10; j++) { + randomNumbers.push(b.random(0, 100)); + } + + // draw rectangles and fill them with different types of gradients + + // grandient from color1 to color2 + b.fill(b.gradient(red, blue, "RedBlueLinear")); + b.rect(0, dist * 0, b.width, dist); + + // gradient from array of colors + b.fill(b.gradient(randomColors, "RandomCol")); + b.rect(0, dist * 1, b.width, dist); + + // gradient from same array of colors with random gradient stop positions + b.fill(b.gradient(randomColors, randomNumbers, "RandomCol/Pos")); + b.rect(0, dist * 2, b.width, dist); + + // radial gradient from color1 to color2 + b.gradientMode(b.RADIAL); + b.fill(b.gradient(red, blue, "RedBlueRadial")); + b.rect(0, dist * 3, b.width, dist); + + // stroke gradient + b.noFill(); + b.strokeWeight(4); + b.gradientMode(b.LINEAR); + b.stroke(b.gradient(blue, red, "BlueRedLinear")); + b.ellipse(b.width / 2, b.height / 2, dist * 2, dist * 2); +} + +b.go(); diff --git a/color/lerpColor.jsx b/color/lerpColor.jsx new file mode 100644 index 0000000..3c4b438 --- /dev/null +++ b/color/lerpColor.jsx @@ -0,0 +1,21 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + var c1 = b.color(0, 255, 0); + var c2 = b.color(255, 128, 0); + + var counter = 10; + b.noStroke(); + var rectHeight = b.height / counter; + + for (var i = 0; i < counter; i++) { + var y = b.map(i, 0, counter - 1, 0, b.height - rectHeight); + var amt = b.map(i, 0, counter - 1, 0, 1); + + b.fill(b.lerpColor(c1, c2, amt)); + b.rect(0, y, b.width, rectHeight); + } +} + +b.go(); diff --git a/color/opacity.jsx b/color/opacity.jsx new file mode 100644 index 0000000..7469b55 --- /dev/null +++ b/color/opacity.jsx @@ -0,0 +1,20 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + b.clear(b.doc()); + + var red = b.color(255, 0, 0); + var black = b.color("Black"); + + b.fill(red); + b.ellipse(b.width / 2, b.height / 2, 333, 333); + + b.fill(black); + var rect = b.rect(b.width / 2, 0, b.width / 2, b.height); + + // set the opacity + b.opacity(rect, 37); +} + +b.go(); diff --git a/color/stroke.jsx b/color/stroke.jsx new file mode 100644 index 0000000..1d9c744 --- /dev/null +++ b/color/stroke.jsx @@ -0,0 +1,17 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + // create new random RGB color + var newRandomColor = b.color(b.random(0, 255), + b.random(0, 255), + b.random(0, 255)); + + b.stroke(newRandomColor); + b.strokeWeight(10); + // draw a cross with random color + b.line(0, 0, b.width, b.height); + b.line(0, b.height, b.width, 0); +} + +b.go(); diff --git a/color/strokeTint.jsx b/color/strokeTint.jsx new file mode 100644 index 0000000..c82e5d6 --- /dev/null +++ b/color/strokeTint.jsx @@ -0,0 +1,18 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + var counter = 50; + b.strokeWeight(7); + + for (var i = 0; i < counter; i++) { + var y = b.map(i, 0, counter - 1, 0, b.height); + var newStrokeTint = b.map(i, 0, counter - 1, 100, 0); + + // set stroke tint of current color + b.strokeTint(newStrokeTint); + b.line(0, y, b.width, y); + } +} + +b.go(); diff --git a/data/HashList.jsx b/data/HashList.jsx new file mode 100644 index 0000000..4a7269b --- /dev/null +++ b/data/HashList.jsx @@ -0,0 +1,49 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +// example shows how to use a HashList to count the occurrence of words in a text + +function draw() { + + b.canvasMode(b.MARGIN); + + var hash = new HashList(); + + var longString = "Lor!$$em! ipsum!! dolor? ??!! sit amet, consetetur... --- ... sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. watch. watch."; + var tf1 = b.text(longString, 0, 0, b.width, 200); + var tf2 = b.text(longString, 0, 220, b.width, 200); + var tf3 = b.text("", 0, 440, b.width, 200); + var words = longString.split(" "); + + var str; + for(var i = 0; i < words.length; i++) { + str = words[i]; + str = b.trimWord(str); + if (str === "") { + continue; + } // special case: nothing left after trimWord + // count the number of occurances + if(hash.hasKey(str)) { + b.println(str); + hash.set(str, hash.get(str) + 1); + } else { + hash.set(str, 1); + } + } + + var keys = (hash.getKeysByValues()); // sorts it by the number of its occurences. + var result1 = ""; + var result2 = ""; + for (var j = 0; j < keys.length; j++) { + var word = keys[j]; + for (var n = 0; n < hash.get(word); n++) { + result1 += word + " "; + } + result2 += (word + " : " + hash.get(word) + ", "); + } + tf2.contents = result1; + tf3.contents = result2; + +} + +b.go(); diff --git a/data/csv.jsx b/data/csv.jsx new file mode 100644 index 0000000..fdb4623 --- /dev/null +++ b/data/csv.jsx @@ -0,0 +1,51 @@ +/** + * example shows how to parse a raw CSV string to a javascript object. + * no idea what CSV is? then have a read here: http://en.wikipedia.org/wiki/Comma-separated_values + */ + +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +// to load an external csv file use +// var jsonString = b.loadString("path/to/file.csv") + +var csvString = ""; +csvString += "firstName,lastName,middleInitial,firstNameFirst,lastNameFirst\n"; +csvString += "Kristina,Chung,H,Kristina H. Chung,\"Chung, Kristina H.\"\n"; +csvString += "Paige,Chen,H,Paige H. Chen,\"Chen, Paige H.\"\n"; +csvString += "Sherri,Melton,E,Sherri E. Melton,\"Melton, Sherri E.\"\n"; +csvString += "Gretchen,Hill,I,Gretchen I. Hill,\"Hill, Gretchen I.\"\n"; +csvString += "Karen,Puckett,U,Karen U. Puckett,\"Puckett, Karen U.\"\n"; +csvString += "Patrick,Song,O,Patrick O. Song,\"Song, Patrick O.\"\n"; +csvString += "Elsie,Hamilton,A,Elsie A. Hamilton,\"Hamilton, Elsie A.\"\n"; +csvString += "Hazel,Bender,E,Hazel E. Bender,\"Bender, Hazel E.\"\n"; +csvString += "Malcolm,Wagner,A,Malcolm A. Wagner,\"Wagner, Malcolm A.\"\n"; +csvString += "Dolores,McLaughlin,C,Dolores C. McLaughlin,\"McLaughlin, Dolores C.\"\n"; +csvString += "Francis,McNamara,C,Francis C. McNamara,\"McNamara, Francis C.\"\n"; +csvString += "Sandy,Raynor,A,Sandy A. Raynor,\"Raynor, Sandy A.\"\n"; +csvString += "Marion,Moon,O,Marion O. Moon,\"Moon, Marion O.\"\n"; +csvString += "Beth,Woodard,O,Beth O. Woodard,\"Woodard, Beth O.\"\n"; +csvString += "Julia,Desai,E,Julia E. Desai,\"Desai, Julia E.\"\n"; +// ... an excerpt of randomNames.csv +// from http://www.opensourcecf.com/1/2009/05/10000-Random-Names-Database.cfm + +function setup() { + b.clear(b.doc()); + + // set the delimiter + // very common for .csv files is ',' (=default) or ';' and for .tsv files '\t' + // b.CSV.delimiter(',') + + // parse CSV + var csvData = b.CSV.decode(csvString); + + // create textframes for "firstNameFirst" column + for (var i = 0; i < csvData.length; i++) { + b.text(csvData[i].firstNameFirst, 0, i * 20, b.width, 19); + } + + // convert an array of key value objects to a CSV-string + b.println(b.CSV.encode(csvData)); +} + +b.go(); diff --git a/data/json.jsx b/data/json.jsx new file mode 100644 index 0000000..ad03473 --- /dev/null +++ b/data/json.jsx @@ -0,0 +1,49 @@ +/** + * example shows how to parse a raw JSON string to a javascript object. + * no idea what JSON is? then have a read here: http://en.wikipedia.org/wiki/JSON + */ + +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +// to load an external json file use +// var jsonString = b.loadString("path/to/file.json") + +var jsonString = "{\ + \"firstName\": \"John\",\ + \"lastName\": \"Smith\",\ + \"age\": 25,\ + \"address\": {\ + \"streetAddress\": \"21 2nd Street\",\ + \"city\": \"New York\",\ + \"state\": \"NY\",\ + \"postalCode\": \"10021\"\ + },\ + \"phoneNumber\": [\ + {\ + \"type\": \"home\",\ + \"number\": \"212 555-1234\"\ + },\ + {\ + \"type\": \"fax\",\ + \"number\": \"646 555-4567\"\ + }\ + ]\ + }"; +// please note: +// you don't have normally a '\' at the end of a line ... +// this is just the character to have a multiline-string + +function setup() { + // parse JSON + var jsonData = b.JSON.decode(jsonString); + + b.text(jsonData.firstName, 0, 0, b.width, 50); + b.text(jsonData.address.city, 0, 50, b.width, 50); + b.text(jsonData.phoneNumber[0].number, 0, 100, b.width, 50); + + // convert an object to a JSON-string + b.println(b.JSON.encode(jsonData)); +} + +b.go(); diff --git a/document/groups.jsx b/document/groups.jsx new file mode 100644 index 0000000..f935f04 --- /dev/null +++ b/document/groups.jsx @@ -0,0 +1,30 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +// groups can be handled in a number a different ways +// finding, creating, releasing + +function draw() { + + // create array of objects + var arr = []; + + arr.push(b.rect(20, 20, 20, 20)); + arr.push(b.rect(60, 20, 20, 20)); + arr.push(b.rect(100, 20, 20, 20)); + + // group them and modify group + var circles = b.group(arr, "rects"); + b.itemPosition(circles, 0, 0); + circles.fillColor = b.color(0, 255, 178); + + // get the bounds of our Group + b.println(b.bounds(circles).width); + + // ungroup our selected items + var items = b.ungroup("rects"); + b.println(items); + +} + +b.go(); diff --git a/document/labels.jsx b/document/labels.jsx new file mode 100644 index 0000000..df30502 --- /dev/null +++ b/document/labels.jsx @@ -0,0 +1,27 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +// you can get all elements you have marked with a script label (Window -> Utilities -> Script Label) +// with b.labels(). there a two different ways to use the b.labels() function + +function draw() { + var myScriptLabel = "a script label"; + b.println("script Label: " + myScriptLabel); + b.println("---"); + + // a + var myTaggedItems = b.labels(myScriptLabel); + for (var i = 0; i < myTaggedItems.length; i++) { + b.println("element " + i + " is a: " + myTaggedItems[i]); + } + + b.println("---"); + + // b + b.labels(myScriptLabel, function(item, counter) { + b.println("element " + counter + " is a: " + item); + }); + +} + +b.go(); diff --git a/document/nameOnPage.jsx b/document/nameOnPage.jsx new file mode 100644 index 0000000..9843a06 --- /dev/null +++ b/document/nameOnPage.jsx @@ -0,0 +1,37 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +// The example shows how to select a pageitem on a specific page by the name. +// Hint: you can manually name a pageitem in the Layers pane (Window -> Layer). + +function draw() { + b.textSize(220); + + + // -- create something to play with -- + // add 4 new pages, now threre a 5 pages in the document + for (var i = 0; i < 4; i++) { + b.addPage(); + } + + // create on every page a textframe + // give the textframe a name for future reference + // you can change/check the names in the 'Layers' window of indesign + for (var j = 1; j <= 5; j++) { + b.page(j); + var txtFrame = b.text("this is page #" + j, 0, 0, b.width, b.height); + txtFrame.name = "page count big"; + } + + + // -- let's change the textframe on page 3 -- + // go to the page + b.page(3); + // select the the textframe with the name "page count big" + var txtOnPage3 = b.nameOnPage("page count big"); + // change it + txtOnPage3.contents = "Found it! :)"; + +} + +b.go(); diff --git a/document/selections.jsx b/document/selections.jsx new file mode 100644 index 0000000..d516cfb --- /dev/null +++ b/document/selections.jsx @@ -0,0 +1,23 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +// you can get all the elements you have selected in indesign via b.selection() +// there a two different ways to use the b.selections() function + +function draw() { + // a + var mySelection = b.selections(); + for (var i = 0; i < mySelection.length; i++) { + b.println("element " + i + " is a: " + mySelection[i]); + } + + b.println("---"); + + // b + b.selections(function(item, counter) { + b.println("element " + counter + " is a: " + item); + }); + +} + +b.go(); diff --git a/document/story.jsx b/document/story.jsx new file mode 100644 index 0000000..4087aec --- /dev/null +++ b/document/story.jsx @@ -0,0 +1,31 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + // show the count of all stories in the current document + b.println(b.storyCount()); // 0 + + // create two textframes + var txtFrameA = b.text("hi this is txtFrameA! ", 0, 0, 300, 100); + var txtFrameB = b.text("this is text from txtFrameB! ", 100, 150, 300, 100); + b.println(b.storyCount()); // 2, because we have two unlinked textframes, each has its own story + + // link both textframes into one story + b.linkTextFrames(txtFrameA, txtFrameB); + b.println(b.storyCount()); // 1, because txtFrameB is now part of txtFrameA's story + + // add something to the story of txtFrameA + for (var i = 0; i < 20; i++) { + var tmpRect = b.rect(0, 0, 30, 30); // position of rect is ignored + b.addToStory(txtFrameA.parentStory, tmpRect); + b.addToStory(txtFrameA.parentStory, " | "); + } + + b.addToStory(txtFrameA.parentStory, " - and some text at the end --> "); + + // You can control the position of the insert via the last parameter. + // It accepts either an InsertionPoint or one the following constants: b.AT_BEGINNING and b.AT_END. + b.addToStory(txtFrameA.parentStory, "<-- some text at the front - ", b.AT_BEGINNING); +} + +b.go(); diff --git a/environment/canvasMode.jsx b/environment/canvasMode.jsx new file mode 100644 index 0000000..22d1e1c --- /dev/null +++ b/environment/canvasMode.jsx @@ -0,0 +1,42 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + + b.doc(app.documents.add()); // use a fresh document + b.doc().documentPreferences.facingPages = true; + + b.noFill(); + b.stroke(0, 255, 0); + b.strokeWeight(4); + b.margins(20); + b.bleeds(20); + + b.page(1); + + b.canvasMode(b.MARGIN); + b.rect(0, 0, b.width, b.height); + + b.canvasMode(b.PAGE); + b.rect(0, 0, b.width, b.height); + + b.canvasMode(b.BLEED); + b.rect(0, 0, b.width, b.height); + + b.addPage(); + b.addPage(); + + b.page(2); + + b.canvasMode(b.FACING_MARGINS); + b.rect(0, 0, b.width, b.height); + + b.canvasMode(b.FACING_PAGES); + b.rect(0, 0, b.width, b.height); + + b.canvasMode(b.FACING_BLEEDS); + b.rect(0, 0, b.width, b.height); + + +} +b.go(); diff --git a/environment/guide.jsx b/environment/guide.jsx new file mode 100644 index 0000000..905b66a --- /dev/null +++ b/environment/guide.jsx @@ -0,0 +1,19 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + for (var i = 0; i < 11; i++) { + var x = fibonacci(i) * 10, y = x; + b.guideX(x); + b.guideY(y); + } +} + +function fibonacci(n) { + if (n <= 1) { + return n; + } + return fibonacci(n - 2) + fibonacci(n - 1); +} + +b.go(); diff --git a/environment/modes.jsx b/environment/modes.jsx new file mode 100644 index 0000000..ca0758a --- /dev/null +++ b/environment/modes.jsx @@ -0,0 +1,39 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + // keep indesign busy + for (var i = 0; i < 500; i++) { + var x = b.random(0, b.width); + var y = b.random(0, b.height); + b.ellipse(x, y, 17, 17); + } +} + +// -- MODEVISIBLE -- +// Processes Document with Screen redraw, use this option to see direct +// results during the process. This will slow down the process in terms +// of processing time. + +// -- MODESILENT -- +// Disables ScreenRedraw during processing. A bit faster, as the document is +// not redrawn during processing. + +// -- MODEHIDDEN -- +// Processes Document in background mode. Document will not be +// visible until the script is done. If you are firing on a open document +// you'll need to save it before calling b.go(). The document will be removed +// from the display list and added again after the script is done. In this +// mode you will likely look at indesign with no open document for quite some +// time - do not work in indesign during this time. You may want to use +// b.println("yourMessage") in your script and look at the Console in estk to +// get information about the process. + +// and now, compare the executing times in the console ... +// on my machine i had 10s (MODEVISIBLE), 8s (MODESILENT), 3.5s (MODEHIDDEN) + +b.go(); // same as writing: b.go(b.MODEVISIBLE) + +// b.go(b.MODESILENT); + +// b.go(b.MODEHIDDEN); diff --git a/environment/pages.jsx b/environment/pages.jsx new file mode 100644 index 0000000..8ac26c3 --- /dev/null +++ b/environment/pages.jsx @@ -0,0 +1,51 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + + // run this on an empty document with only one page + b.doc().documentPreferences.facingPages = false; // force non-facing pages, sorry guys! + b.page(); + + // add one page at the end of the document + b.addPage(); + b.text("Example 1", b.width / 2, b.height / 2, 100, 100); + // removes current page + b.removePage(); + + // fill up again... + b.addPage(); + // removes page 1 + b.removePage(1); + + // fill up again and save reference in myPage + var myPage = b.addPage(); + // removes myPage right away... you won't see it ever + b.removePage(myPage); + + // add pages until 20 + for(var i = b.pageCount(); i < 20; i++) { + b.addPage(); + b.text("Example 2-" + i, b.width / 2, b.height / 2, 100, 100); + } + + // set location of insertion + b.addPage(b.AT_END); // default + b.text("Example AT_END", b.width / 2, b.height / 2, 100, 100); + b.addPage(b.AT_BEGINNING); + b.text("Example AT_BEGINNING", b.width / 2, b.height / 2, 100, 100); + + // adds a page before page 15 + b.page(10); // set current page + b.addPage(b.BEFORE); // this refers to the current page + b.text("Example BEFORE 10 becomes the new 10", b.width / 2, b.height / 2, 100, 100); + + // guess what! + b.page(15); + b.addPage(b.AFTER); + b.text("Example AFTER 15 becomes 16", b.width / 2, b.height / 2, 100, 100); + + b.println(b.pageCount()); + +} +b.go(); diff --git a/environment/size.jsx b/environment/size.jsx new file mode 100644 index 0000000..2bcaf5d --- /dev/null +++ b/environment/size.jsx @@ -0,0 +1,41 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + + +// The b.size([width,[height]]) function allows to get/set the size of +// the current document. +// +// If no argument is given it returns the current values of +// b.width and b.height in an object {"width":Number,"height":Number}. +// +// If one argument is provided the width and height both get set this this value. +// +// If two arguments are provided the first value is the width the second is the height. +// +// Lets try this out: +// +function setup() { + // For starters - lets get the size + var documentSize = b.size(); + b.println(documentSize.toSource()); // lets see what we've got + // to see the changes of that document we add a text in the exact size + b.text(documentSize.toSource(), 0, 0, documentSize.width, documentSize.height); + // next we pass only one argument + b.size(documentSize.width * 2); + // lets get the size again for the next text frame. + documentSize = b.size(); + // and draw the text again + b.text(documentSize.toSource(), 0, 0, documentSize.width, documentSize.height); + // finally lets set the size for width and height separately + b.size(documentSize.width, documentSize.height * 3); + // get the size again + documentSize = b.size(); + // and draw another box + b.text(documentSize.toSource(), 0, 0, documentSize.width, documentSize.height); +} + +function draw() { + // nothing to see here +} + +b.go(); diff --git a/environment/units.jsx b/environment/units.jsx new file mode 100644 index 0000000..0f8eb2e --- /dev/null +++ b/environment/units.jsx @@ -0,0 +1,21 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + b.units(b.PT); // default + b.text("points", 10, 20, 300, 300); + + b.units(b.PX); + b.text("pixels", 10, 20, 300, 300); + + b.units(b.MM); + b.text("millimenters", 10, 20, 300, 300); + + b.units(b.CM); + b.text("centimenters", 10, 20, 300, 300); + + b.units(b.IN); + b.text("inches", 1, 2, 300, 300); +} + +b.go(); diff --git a/environment/width-and-height.jsx b/environment/width-and-height.jsx new file mode 100644 index 0000000..26844d4 --- /dev/null +++ b/environment/width-and-height.jsx @@ -0,0 +1,9 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + b.println("page size: " + b.width + " x " + b.height); + b.rect(0, 0, b.width, b.height); +} + +b.go(); diff --git a/image/image.jsx b/image/image.jsx new file mode 100644 index 0000000..dc32e86 --- /dev/null +++ b/image/image.jsx @@ -0,0 +1,33 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +// to run this example +function draw() { + + b.println("Please note: In order to run this example you have to save your InDesign document first and put a picture file named 'image-example.jpg' next to it in a folder called 'data'."); + + // when doc is saved images can be added by name from data directory in same folder as document + // add image and fit image size to width and height + b.image("image-example.jpg", 0, 0, 200, 300); + + // add image in original image size + b.image("image-example.jpg", 0, 350); + + // change fitoption of the image inside the frame + var img = b.image("image-example.jpg", 400, 0, 200, 300); + /* + FitOptions.CONTENT_TO_FRAME + FitOptions.CENTER_CONTENT + FitOptions.PROPORTIONALLY + FitOptions.FRAME_TO_CONTENT + FitOptions.FILL_PROPORTIONALLY + FitOptions.APPLY_FRAME_FITTING_OPTIONS + */ + img.fit(FitOptions.PROPORTIONALLY); + + // place image inside an circle + var circle = b.ellipse(50, 50, 150, 150); + b.image("image-example.jpg", circle); +} + +b.go(); diff --git a/image/imageMode.jsx b/image/imageMode.jsx new file mode 100644 index 0000000..3bc0312 --- /dev/null +++ b/image/imageMode.jsx @@ -0,0 +1,21 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + + +function draw() { + + b.println("Please note: In order to run this example you have to save your InDesign document first and put a picture file named 'image-example.jpg' next to it in a folder called 'data'."); + + // default is CORNER, image should be placed at top left corner + b.image("image-example.jpg", 0, 0, 200, 200); + + // set to CENTER, image should be just below 1st image + b.imageMode(b.CENTER); + b.image("image-example.jpg", 100, 300, 200, 200); + + // set to CORNERS, image should be just below 2nd image and bigger + b.imageMode(b.CORNERS); + b.image("image-example.jpg", 0, 400, 300, 700); +} + +b.go(); diff --git a/image/transformImage.jsx b/image/transformImage.jsx new file mode 100644 index 0000000..7e05c7f --- /dev/null +++ b/image/transformImage.jsx @@ -0,0 +1,12 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + + b.println("Please note: In order to run this example you have to save your InDesign document first and put a picture file named 'image-example.jpg' next to it in a folder called 'data'."); + var img = b.image("image-example.jpg", 100, 350); + b.transformImage(img, 0, 0, 500, 500); + +} + +b.go(); diff --git a/input/loadStringURL.jsx b/input/loadStringURL.jsx new file mode 100644 index 0000000..62696a0 --- /dev/null +++ b/input/loadStringURL.jsx @@ -0,0 +1,23 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + b.println("-- load an URL into a string --"); + var url = "http://basiljs.ch"; + b.println(b.isURL(url)); + b.println(b.loadString(url)); + + b.println("-- load lines of an text file into an array --"); + var loadedArray = b.loadStrings("https://raw.github.com/basiljs/basil.js/master/examples/demos/B08_bar_chart_from_csv_data/data/LA_Pools-Pools_per_Hood.csv"); + b.println(loadedArray.length); + b.println(loadedArray[0]); + b.println(loadedArray[1]); + + b.println("-- load JSON data --"); + var urlWeatherBasel = "http://api.openweathermap.org/data/2.5/weather?q=Basel,CH&units=metric"; + var weatherData = b.JSON.decode(b.loadString(urlWeatherBasel)); + b.println("wind speed: " + weatherData.wind.speed); + b.inspect(weatherData); +} + +b.go(); diff --git a/input/loadStrings.jsx b/input/loadStrings.jsx new file mode 100644 index 0000000..b6e9b3b --- /dev/null +++ b/input/loadStrings.jsx @@ -0,0 +1,33 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + /* + Please note: + You have to put a text file 'some_test_file.txt' + with some plain content in a folder 'data' next to + your saved InDesign document. + */ + b.println("put some text file in the data folder!"); + + // load lines of the file in array + var linesArray = b.loadStrings("some_test_file.txt"); + addTextForEachLine(linesArray); + + // load file content + var textString = b.loadString("some_test_file.txt"); + // if you prefer not to use the data folder mechanism + // then use this code snippet: + // var txtFile = new File("/Users/bene/Desktop/some_test_file.txt"); + // var text = b.loadString(txtFile); + + b.println(textString); +} + +function addTextForEachLine(lines) { + forEach(lines, function(line, i) { + b.text(line, 0, i * 100, 300, 100); + }); +} + +b.go(); diff --git a/input/shellExecute.jsx b/input/shellExecute.jsx new file mode 100644 index 0000000..2b72680 --- /dev/null +++ b/input/shellExecute.jsx @@ -0,0 +1,19 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + // Example shows how to executes a shell command ... + // CURRENTYL MAC ONLY! + // BE CAREFUL! + + b.println("-- get the current time from the shell --"); + b.println(b.shellExecute("date")); + + b.println("-- list all files on your desktop --"); + b.println(b.shellExecute("ls ~/Desktop")); + + b.println("-- some around in the internetz? --"); + b.println(b.shellExecute("ping -c 1 www.basiljs.ch")); +} + +b.go(); diff --git a/loop/animated nonsense ball.jsx b/loop/animated nonsense ball.jsx new file mode 100644 index 0000000..57d49ea --- /dev/null +++ b/loop/animated nonsense ball.jsx @@ -0,0 +1,48 @@ +// @targetengine "loop"; +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + + +var pos, vel; +var ellipse; +var ellipseRadius = 20; + +function setup() { + pos = new b.Vector(b.random(b.width), b.random(b.height)); + vel = new b.Vector(b.random(3, 10), b.random(3, 10)); + ellipse = b.ellipse(pos.x, pos.y, ellipseRadius * 2, ellipseRadius * 2); + b.fillTint(50); + b.rectMode(b.CENTER); +} + +function draw() { + pos.add(vel); + + // detect boundary collision + // right + if (pos.x > b.width - ellipseRadius) { + pos.x = b.width - ellipseRadius; + vel.x *= -1; + } + // left + if (pos.x < ellipseRadius) { + pos.x = ellipseRadius; + vel.x *= -1; + } + // top + if (pos.y < ellipseRadius) { + pos.y = ellipseRadius; + vel.y *= -1; + } + // bottom + if (pos.y > b.height - ellipseRadius) { + pos.y = b.height - ellipseRadius; + vel.y *= -1; + } + + b.rect(pos.x, pos.y, 10, 10); + // [y1, x1, y2, x2] + ellipse.geometricBounds = [pos.y - ellipseRadius, pos.x - ellipseRadius, pos.y + ellipseRadius, pos.x + ellipseRadius]; +} + +b.loop(60); // try to run in 60 FPS :) diff --git a/loop/fontsize interactive.jsx b/loop/fontsize interactive.jsx new file mode 100644 index 0000000..b3b5e37 --- /dev/null +++ b/loop/fontsize interactive.jsx @@ -0,0 +1,21 @@ +// @targetengine "loop"; +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +var ctrl, textFramePage; + +function setup() { + b.textSize(20); + ctrl = b.text("move me!", -250, 100, 100, 50); + textFramePage = b.text("basel", 0, 0, b.width, b.height); +} + +function draw() { + var y = ctrl.geometricBounds[0]; + y = b.round(y); + textFramePage.contents = "basel " + y; + textFramePage.paragraphs[0].pointSize = y; + ctrl.contents = "move me!\n" + y; +} + +b.loop(); diff --git a/loop/server.jsx b/loop/server.jsx new file mode 100644 index 0000000..9de9300 --- /dev/null +++ b/loop/server.jsx @@ -0,0 +1,61 @@ +// targetengine "loop"; +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +// note: use telnet on terminal to send strings after the server was started +// telnet localhost 1024 +// then type and press return + +var server = null; +var conn = null; + +var tWidth; +var tHeight; + +function setup() { + b.doc(); + server = new Socket(); + server.listen(1024); + server.timeout = 999999; + b.println("server started at localhost 1024"); + + tWidth = b.width - 150; + tHeight = 400; +} + +function draw() { + + b.println("poll loop"); + + if(conn === null) { + conn = server.poll(); + } + if(conn !== null && conn.connected) { + conn.timeout = 0.05; // time for connected client to wait for linefeed, otherwise blocks InDesign for 10 seconds + var s = conn.readln(); + if (s !== null && s !== "") { + b.println(s); + + b.addPage(); + var tf = b.text(s, b.width / 2 - tWidth / 2, b.height / 2 - tHeight / 2, tWidth, tHeight); + b.typo(tf, "appliedFont", "Helvetica\tBold"); + b.typo(tf, "pointSize", "72"); + b.typo(tf, "justification", Justification.CENTER_ALIGN); + } + } + +} + +function cleanUp() { + if(conn !== null) { + conn.close(); + } + if(server !== null) { + server.close(); + } + server = null; + conn = null; + b.println("stopped server"); +} + +b.loop(15); diff --git a/loop/simple pong.jsx b/loop/simple pong.jsx new file mode 100644 index 0000000..72e63b3 --- /dev/null +++ b/loop/simple pong.jsx @@ -0,0 +1,93 @@ +// @targetengine "loop"; +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +var pos, vel; +var ball; +var ballRadius = 40; +var paddle; +var paddleWidth = 300; +var paddleHeight = 40; +var counter = 0; +var countBox; + +function setup() { + + b.doc(); + b.units(b.PX); + + // create ball + initBall(); + + // init paddle + paddle = b.rect(b.width / 2 - paddleWidth / 2, b.height - paddleHeight - 10, paddleWidth, paddleHeight); + + // init countBox + countBox = b.text("0", b.width - 320, 20, 300, 80); + b.typo(countBox, "appliedFont", "Helvetica\tBold"); + b.typo(countBox, "pointSize", "72"); + b.typo(countBox, "justification", Justification.RIGHT_ALIGN); + +} + +function draw() { + + pos.add(vel); + + // detect boundary collision + // right + if (pos.x > b.width - ballRadius * 2) { + pos.x = b.width - ballRadius * 2; + vel.x *= -1; + } + // left + if (pos.x < 0) { + pos.x = 0; + vel.x *= -1; + } + // top + if (pos.y < 0) { + pos.y = 0; + vel.y *= -1; + } + // bottom => you loose + if (pos.y > b.height - ballRadius * 2) { + ball.remove(); + counter = 0; +// initBall(); + } + + // check paddle + if (paddle !== null + && pos.y > b.itemY(paddle) - ballRadius * 2 + && pos.x > b.itemX(paddle) - ballRadius + && pos.x < b.itemX(paddle) + ballRadius + b.itemWidth(paddle)) { + + vel.y *= -1; + vel.mult(1.0); // getting harder... + counter++; + pos.y = b.itemY(paddle) - ballRadius * 2; + + } + + b.itemPosition(ball, pos.x, pos.y); + countBox.contents = String(counter); + +} + +function initBall() { + pos = new b.Vector(b.width / 2, b.height / 2); + vel = new b.Vector(b.random(-20, 20), -18); + ball = b.ellipse(pos.x, pos.y, ballRadius * 2, ballRadius * 2); + b.itemPosition(ball, pos.x, pos.y); +} + +// this is called when the stop.jsx script is invoked. use this to remove all the runtime items. +function cleanUp() { + ball.remove(); + paddle.remove(); + countBox.remove(); +} + + +b.loop(30); diff --git a/output/download.jsx b/output/download.jsx new file mode 100644 index 0000000..75bf3cf --- /dev/null +++ b/output/download.jsx @@ -0,0 +1,27 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + // Example shows how to shows how to download an url to a file + // CURRENTYL MAC ONLY! + b.println("the project folder: " + b.projectPath()); + + + var url = "https://raw.github.com/basiljs/basil.js/master/changelog.txt"; + + // download the url to a default location, filename according to url: + // -> "the project folder" + data/download/changelog.txt + b.download(url); + + // download url to a specific location in the project folder: + // -> "the project folder" + data/download_txt_files/my changelog.txt + b.download(url, "download_txt_files/my changelog.txt"); + + // download url to a specific location e.g. to your desktop + // -> ~/Desktop/basiljs_changelog.txt + var newFile = new File("~/Desktop/basiljs_changelog.txt"); + b.download(url, newFile); + +} + +b.go(); diff --git a/output/inspect.jsx b/output/inspect.jsx new file mode 100644 index 0000000..6fd9e65 --- /dev/null +++ b/output/inspect.jsx @@ -0,0 +1,15 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + b.clear(b.doc()); + + var textFrame = b.text("hi!", 0, 0, 50, 50); + var someObject = {prop: "hello", fun: function() {}, num: 5, arr: [0, 1, 2, 3, 4, 5, function() {}], c: new Color()}; + + b.inspect(someObject); + // b.inspect( textFrame ); + // b.inspect( b.doc().allPageItems ); +} + +b.go(); diff --git a/output/savePDF.jsx b/output/savePDF.jsx new file mode 100644 index 0000000..92778cc --- /dev/null +++ b/output/savePDF.jsx @@ -0,0 +1,18 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + + b.textSize(64); + var tf = b.text("this content will be overwritten", b.width / 2 - 250, b.height / 2 - 150, 500, 300); + + for(var i = 0; i < 20; i++) { + tf.contents = "hello pdf " + i; + b.savePDF("hello-pdf-" + i + ".pdf"); + } + + // show export options + // b.savePDF("hello.pdf",true); +} + +b.go(); diff --git a/output/saveStrings.jsx b/output/saveStrings.jsx new file mode 100644 index 0000000..c5e6dd9 --- /dev/null +++ b/output/saveStrings.jsx @@ -0,0 +1,16 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + var words = b.split("apple bear cat dog", " "); + + b.println("Please note: You have to have your InDesign document saved already, so that basil.js can create a data folder for you next to it."); + + b.doc().save(); + + // when doc is saved files can be saved to the same folder where the indesign document is around + b.saveStrings("saveStrings-example-2.txt", words); +} + + +b.go(); diff --git a/random/random.jsx b/random/random.jsx new file mode 100644 index 0000000..e587a64 --- /dev/null +++ b/random/random.jsx @@ -0,0 +1,18 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + var count = 23; + + b.doc(); + b.println(b.width + " x " + b.height); + + for (var i = 0; i < 23; i++) { + var x = b.random(0, b.width); + var y = b.random(0, b.height); + var size = b.random(10, 123); + b.ellipse(x, y, size, size); + } +} + +b.go(); diff --git a/shape/arc.jsx b/shape/arc.jsx new file mode 100644 index 0000000..edccad0 --- /dev/null +++ b/shape/arc.jsx @@ -0,0 +1,35 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + b.noFill(); + + b.rectMode(b.CENTER); // show bounding boxes + b.stroke(128); + b.rect(35, 35, 50, 50); + b.rect(105, 35, 50, 50); + b.rect(175, 35, 50, 50); + b.rect(105, 105, 100, 50); + + b.stroke(0); + b.arc(35, 35, 50, 50, 0, b.HALF_PI); // lower quarter circle + b.arc(105, 35, 50, 50, -b.PI, 0); // upper half of circle + b.arc(175, 35, 50, 50, -b.PI / 6, b.PI / 6); // 60 degrees + b.arc(105, 105, 100, 50, b.HALF_PI, 3 * b.HALF_PI); // 180 degrees + + + b.arc(35, 175, 50, 50, 0, b.HALF_PI); + b.arc(35, 175, 60, 60, b.HALF_PI, b.PI); + b.arc(35, 175, 70, 70, b.PI, b.PI + b.QUARTER_PI); + b.arc(35, 175, 80, 80, b.PI + b.QUARTER_PI, b.TWO_PI); + + b.arc(175, 175, 80, 80, 0, b.PI + b.QUARTER_PI, b.OPEN); + + b.arc(315, 175, 80, 80, 0, b.PI + b.QUARTER_PI, b.CHORD); + + b.arc(455, 175, 80, 80, 0, b.PI + b.QUARTER_PI, b.PIE); + +} + + +b.go(); diff --git a/shape/bounds.jsx b/shape/bounds.jsx new file mode 100644 index 0000000..246c14a --- /dev/null +++ b/shape/bounds.jsx @@ -0,0 +1,34 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + b.textSize(21); + b.strokeWeight(1); + var oval = b.ellipse(400, 50, 150, 80); + + var textFrame = b.text(b.LOREM, 50, 70, 300, 500); + + b.typo(textFrame, "hyphenation", false); + + // text related bounds + b.noFill(); + b.words(textFrame, function (word) { + var textBounds = b.bounds(word); + b.rect(textBounds.left, textBounds.top, textBounds.width, textBounds.height); + b.ellipse(textBounds.left, textBounds.xHeight, 3, 3); + }); + + b.fill("Black"); + + // bounds of the oval + var ovalBounds = b.bounds(oval); + b.text("ovalBounds", ovalBounds.left, ovalBounds.top, ovalBounds.width, ovalBounds.height); + + // bounds of page items + var pageBounds = b.bounds(b.page()); + b.inspect(pageBounds); + + b.text("pageBounds", pageBounds.left, pageBounds.top, pageBounds.width, pageBounds.height); +} + +b.go(); diff --git a/shape/ellipseMode.jsx b/shape/ellipseMode.jsx new file mode 100644 index 0000000..994df89 --- /dev/null +++ b/shape/ellipseMode.jsx @@ -0,0 +1,18 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + b.ellipseMode(b.CENTER); // default + b.ellipse(0, 0, 100, 100); + + b.ellipseMode(b.RADIUS); + b.ellipse(200, 200, 100, 100); + + b.ellipseMode(b.CORNER); + b.ellipse(0, 0, 100, 100); + + b.ellipseMode(b.CORNERS); + b.ellipse(0, 300, 400, 350); +} + +b.go(); diff --git a/shape/golan_bezier_arc.jsx b/shape/golan_bezier_arc.jsx new file mode 100644 index 0000000..0c4fdf1 --- /dev/null +++ b/shape/golan_bezier_arc.jsx @@ -0,0 +1,152 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function setup() { +} + +// -------------------------- +// Global variables: +// The true coordinates of the Bezier control points: +var px0, py0; +var px1, py1; +var px2, py2; +var px3, py3; +var radius = 300; // radius of the circular arc +var cx = 0; // center point of the circular arc +var cy = 0; + +// -------------------------- +function draw() { + + var pt = calculateEllipticalArc(radius * 2, radius * 0.5, b.radians(0), b.radians(90)); + + // Draw the Bezier control points. + b.stroke(0, 0, 0, 64); + b.fill(0, 0, 0, 64); + + b.ellipse( + cx + pt.startx, + cy + pt.starty, + 8, 8); + b.ellipse( + cx + pt.handle1x, + cy + pt.handle1y, + 8, 8); + b.ellipse( + cx + pt.handle2x, + cy + pt.handle2y, + 8, 8); + b.ellipse( + cx + pt.endx, + cy + pt.endy, + 8, 8); + + b.line( + 0, + 0, + cx + pt.startx, + cy + pt.starty + ); + b.line( + cx + pt.startx, + cy + pt.starty, + cx + pt.handle1x, + cy + pt.handle1y + ); + b.line( + cx + pt.handle1x, + cy + pt.handle1y, + cx + pt.handle2x, + cy + pt.handle2y + ); + b.line( + cx + pt.handle2x, + cy + pt.handle2y, + cx + pt.endx, + cy + pt.endy + ); + b.line( + cx + pt.endx, + cy + pt.endy, + 0, + 0 + ); + + + b.beginShape(b.CLOSE); + b.vertex( + cx, + cy + ); + b.vertex( + cx + pt.startx, + cy + pt.starty, + cx + pt.startx, + cy + pt.starty, + cx + pt.handle1x, + cy + pt.handle1y + ); + b.vertex( + cx + pt.endx, + cy + pt.endy, + cx + pt.handle2x, + cy + pt.handle2y, + cx + pt.endx, + cy + pt.endy + ); + b.endShape(); + +} + +function calculateEllipticalArc(w, h, startAngle, endAngle) { + // Establish arc parameters. + // (Note: assert theta != TWO_PI) + // var theta = b.radians(100/3.0); // spread of the arc. + // startAngle = b.radians(200/8.0); // as in arc() + // endAngle = startAngle + theta; // as in arc() + var theta = (endAngle - startAngle); // spread of the arc. + + + // Compute raw Bezier coordinates. + var x0 = b.cos(theta / 2.0); + var y0 = b.sin(theta / 2.0); + var x3 = x0; + var y3 = 0 - y0; + var x1 = (4.0 - x0) / 3.0; + var y1 = ((1.0 - x0) * (3.0 - x0)) / (3.0 * y0); // y0 != 0... + var x2 = x1; + var y2 = 0 - y1; + + // Compute rotationally-offset Bezier coordinates, using: + // x' = cos(angle) * x - sin(angle) * y; + // y' = sin(angle) * x + cos(angle) * y; + var bezAng = startAngle + theta / 2.0; + var cBezAng = b.cos(bezAng); + var sBezAng = b.sin(bezAng); + var rx0 = cBezAng * x0 - sBezAng * y0; + var ry0 = sBezAng * x0 + cBezAng * y0; + var rx1 = cBezAng * x1 - sBezAng * y1; + var ry1 = sBezAng * x1 + cBezAng * y1; + var rx2 = cBezAng * x2 - sBezAng * y2; + var ry2 = sBezAng * x2 + cBezAng * y2; + var rx3 = cBezAng * x3 - sBezAng * y3; + var ry3 = sBezAng * x3 + cBezAng * y3; + + var rw = w / 2; // (Math.sqrt(w * w + h * h) / 2); + var rh = h / 2; // (Math.sqrt(w * w + h * h) / 2); + // Compute scaled and translated Bezier coordinates. + return { + startx: rw * rx0, + starty: rh * ry0, + handle1x: rw * rx1, + handle1y: rh * ry1, + + handle2x: rw * rx2, + handle2y: rh * ry2, + endx: rw * rx3, + endy: rh * ry3 + }; +} + + +b.go(); diff --git a/shape/line.jsx b/shape/line.jsx new file mode 100644 index 0000000..ed778e3 --- /dev/null +++ b/shape/line.jsx @@ -0,0 +1,23 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + var tileCount = 10; + var randomX = b.random(0, b.width); + var randomY = b.random(0, b.height); + + b.strokeWeight(2); + + for (var gridY = 0; gridY < tileCount; gridY++) { + for (var gridX = 0; gridX < tileCount; gridX++) { + var posX = b.width / tileCount * gridX; + var posY = b.height / tileCount * gridY; + b.line(posX, posY, randomX, randomY); + } + } + + b.fill(0, 255, 0); + b.ellipse(randomX, randomY, 30, 30); +} + +b.go(); diff --git a/shape/rectMode.jsx b/shape/rectMode.jsx new file mode 100644 index 0000000..63a48c2 --- /dev/null +++ b/shape/rectMode.jsx @@ -0,0 +1,15 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + b.rectMode(b.CORNER); // default + b.rect(0, 0, 100, 100); + + b.rectMode(b.CENTER); + b.rect(0, 0, 100, 100); + + b.rectMode(b.CORNERS); + b.rect(200, 250, 300, 300); +} + +b.go(); diff --git a/shape/strokeWeight.jsx b/shape/strokeWeight.jsx new file mode 100644 index 0000000..d26eabc --- /dev/null +++ b/shape/strokeWeight.jsx @@ -0,0 +1,18 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + var counter = 50; + var weightStart = 0.1; + var weightEnd = 12; + + for (var i = 0; i < counter; i++) { + var y = b.map(i, 0, counter - 1, 0, b.height); + var weight = b.map(i, 0, counter - 1, weightStart, weightEnd); + + b.strokeWeight(weight); + b.line(0, y, b.width, b.height / 2); + } +} + +b.go(); diff --git a/shape/vertex.jsx b/shape/vertex.jsx new file mode 100644 index 0000000..072e18a --- /dev/null +++ b/shape/vertex.jsx @@ -0,0 +1,51 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + b.noFill(); + + // open shape + b.beginShape(); + b.vertex(30, 20); + b.vertex(85, 20); + b.vertex(85, 75); + b.endShape(); + + // closed shape + b.beginShape(b.CLOSE); + b.vertex(130, 20); + b.vertex(185, 20); + b.vertex(185, 75); + b.endShape(); + + // bezier shape + // vertex(x, y, xAnchorLeft, yAnchorLeft, xAnchorRight, yAnchorRight) + // you can also mix the two approaches: + b.beginShape(); + b.vertex(230, 320); + b.vertex(285, 320, 270, 290, 300, 350); + b.vertex(285, 375); + b.endShape(); + + b.translate(200, 0); // just move down a bit + + + // multi-component shape (~30% faster than adding multiple PageItems) + b.beginShape(); + b.vertex(30, 20); + b.vertex(85, 20); + b.vertex(85, 75); + b.addPath(); + b.vertex(130, 120); + b.vertex(185, 120); + b.vertex(185, 175); + b.addPath(); + b.vertex(230, 220); + b.vertex(285, 220); + b.vertex(285, 275); + b.endShape(); + + +} + +b.go(); diff --git a/structure/delay.jsx b/structure/delay.jsx new file mode 100644 index 0000000..99fcb27 --- /dev/null +++ b/structure/delay.jsx @@ -0,0 +1,13 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function setup() { + b.println(b.hour() + ":" + b.minute() + ":" + b.second()); + + // wait 3 sec + b.delay(3000); + + b.println(b.hour() + ":" + b.minute() + ":" + b.second()); +} + +b.go(); diff --git a/structure/forEach-loops.jsx b/structure/forEach-loops.jsx new file mode 100644 index 0000000..a2fa650 --- /dev/null +++ b/structure/forEach-loops.jsx @@ -0,0 +1,32 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function setup() { + var contents = "This is the first paragraph of the text frame.\rThis is the second one."; + b.text(contents, 0, 0, 400, 200); + b.text(contents, 0, 400, 400, 200); + + var doc = b.doc(); + + b.stories(doc, function(story, si) { + b.println("Story " + si); + }); + + b.paragraphs(doc, function(para, pi) { + b.println("Paragraph " + pi); + }); + + b.lines(doc, function(line, li) { + b.println("Line " + li); + }); + + b.words(doc, function(word, wi) { + b.println("Word " + wi); + }); + + b.characters(doc, function(ch, ci) { + b.println("Character " + ci); + }); +} + +b.go(); diff --git a/template.jsx b/template.jsx new file mode 100644 index 0000000..ac679c1 --- /dev/null +++ b/template.jsx @@ -0,0 +1,9 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + + +} + +b.go(); diff --git a/transform/itemPositioning.jsx b/transform/itemPositioning.jsx new file mode 100644 index 0000000..15e3d58 --- /dev/null +++ b/transform/itemPositioning.jsx @@ -0,0 +1,46 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + + b.doc(); + b.clear(b.doc()); + + b.units(b.MM); // use millimeter + b.noStroke(); + b.fill(100); // black + + b.rectMode(b.CORNER); // Please note that only b.CORNER positioning is fully supported for moving around items + var ell = b.rect(b.width / 2, b.height / 2, 30, 30); + + b.delay(1000); + + b.itemX(ell, 30); + b.delay(1000); + + b.itemY(ell, 30); + b.delay(1000); + + b.itemPosition(ell, b.width / 2, b.height / 2); + b.delay(1000); + + b.itemWidth(ell, 50); + b.delay(1000); + + b.itemHeight(ell, 50); + b.delay(1000); + + b.itemSize(ell, 30, 30); + b.delay(1000); + + for(var i = 0; i < 50; i++) { + + b.itemX(ell, b.itemX(ell) + 2); + b.delay(30); + } + + ell.remove(); + +} + +b.go(); diff --git a/transform/pushMatrix and popMatrix.jsx b/transform/pushMatrix and popMatrix.jsx new file mode 100644 index 0000000..20d3622 --- /dev/null +++ b/transform/pushMatrix and popMatrix.jsx @@ -0,0 +1,53 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + var tileCount = 10; + var rectWidth = 80; + var randomX = b.random(0, b.width); + var randomY = b.random(0, b.height); + + b.noStroke(); + b.rectMode(b.CENTER); + + var black = b.color("Black"); + var red = b.color(255, 0, 0); + var green = b.color(0, 255, 0); + var white = b.color(0); // cmyk white + + b.textSize(9); + + for (var gridY = 0; gridY < tileCount; gridY++) { + for (var gridX = 0; gridX < tileCount; gridX++) { + var posX = b.width / tileCount * gridX; + var posY = b.height / tileCount * gridY; + var angle = b.atan2(randomY - posY, randomX - posX); + + b.pushMatrix(); + b.translate(posX, posY); + b.rotate(angle); + + b.fill(black); + b.rect(0, 0, rectWidth, 10); + + b.fill(white); + b.ellipse(0, 0, 5, 5); + + b.pushMatrix(); + b.translate(rectWidth / 2, 0); + b.fill(red); + b.ellipse(0, 0, 12, 12); + b.popMatrix(); + + b.rotate(b.HALF_PI); + b.fill(black); + b.text(b.nfc(posX, 1) + "/" + b.nfc(posY, 1), 0, 0, rectWidth * 0.5, 15); + b.popMatrix(); + } + } + + b.fill(green); + b.ellipse(randomX, randomY, 30, 30); +} + +b.go(); diff --git a/typography/RandomFonts.jsx b/typography/RandomFonts.jsx new file mode 100644 index 0000000..05820b4 --- /dev/null +++ b/typography/RandomFonts.jsx @@ -0,0 +1,22 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + var textFramesCount = 20; + var fonts = app.fonts; + + for (var i = 0; i < textFramesCount; i++) { + var posX = b.random(0, 600); + var posY = b.random(0, 850); + var randomFontSize = b.round(b.random(2, 20)); + var randomIndex = b.floor(b.random(app.fonts.length)); + var fontName = fonts[randomIndex].fullName; + b.println(fontName); + + b.textSize(randomFontSize); + b.textFont(fonts[randomIndex]); + var textFrame = b.text(fontName + " " + randomFontSize, posX, posY, 300, 20); + } +} + +b.go(); diff --git a/typography/linkTextFrames.jsx b/typography/linkTextFrames.jsx new file mode 100644 index 0000000..971cd40 --- /dev/null +++ b/typography/linkTextFrames.jsx @@ -0,0 +1,22 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + b.textFont("Helvetica\tBold"); + b.textSize(16); + + var textframeA = b.text(b.LOREM, 0, 0, 100, 100); + var textframeB = b.text("", 100, 100, 100, 100); + b.linkTextFrames(textframeA, textframeB); + var textframeC = b.text("", 200, 200, 100, 100); + b.linkTextFrames(textframeB, textframeC); + var textframeD = b.text("", 300, 300, 100, 100); + b.linkTextFrames(textframeC, textframeD); + var textframeE = b.text("", 400, 400, 100, 100); + b.linkTextFrames(textframeD, textframeE); + var textframeF = b.text("", 500, 500, 100, 100); + b.linkTextFrames(textframeE, textframeF); + +} + +b.go(); diff --git a/typography/placeholder.jsx b/typography/placeholder.jsx new file mode 100644 index 0000000..0b9398b --- /dev/null +++ b/typography/placeholder.jsx @@ -0,0 +1,29 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + + b.units(b.MM); + + // filling an empty text frame with placeholder text + var textFrameA = b.text("", 0, 0, 60, 60); + var placeholderA = b.placeholder(textFrameA); + + // filling a non-empty text frame with placeholder text + var textFrameB = b.text("Placeholder text is added behind existing text: ", 0, 80, 60, 60); + var placeholderB = b.placeholder(textFrameB); + + // filling linked text frames with placeholder text + var textFrameC = b.text("Placeholder text filling linked text frames: ", 0, 160, 60, 60); + var textFrameD = b.text("", 60, 220, 60, 60); + b.linkTextFrames(textFrameC, textFrameD); + var placeholderC = b.placeholder(textFrameC); + + // styling placeholder text + b.typo(placeholderA, "fillColor", b.color(255, 0, 0)); + b.typo(placeholderB, "fillColor", b.color(0, 200, 0)); + b.typo(placeholderC, "fillColor", b.color(0, 0, 255)); + +} + +b.go(); diff --git a/typography/styles.jsx b/typography/styles.jsx new file mode 100644 index 0000000..f04d480 --- /dev/null +++ b/typography/styles.jsx @@ -0,0 +1,65 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + + b.units(b.MM); + var tf = b.text("", b.width / 2 - 60, b.height / 2 - 100, 120, 200); + b.placeholder(tf); + + + // create a new style by name + b.paragraphStyle("emptyStyle"); + + + // create styles by name with custom properties + var redProps = { + fillColor: b.color(255, 0, 0), + pointSize: 14, + skew: 15 + }; + var redStyle = b.paragraphStyle("red", redProps); + + var greenProps = { + fillColor: b.color(0, 255, 0), + pointSize: 18, + skew: -15 + }; + var greenStyle = b.characterStyle("green", greenProps); + + + // apply styles + b.applyParagraphStyle(tf, "red"); + + var words = b.words(tf); + for (var i = 0; i < words.length; i += 5) { + b.applyCharacterStyle(words[i], greenStyle); + } + + + b.delay(1000); + + + // update style with new properties + b.characterStyle("green", {fillColor: b.color(0, 0, 255), name: "blue"}); + + + // creating an objectStyle by name with custom properties + var objectProps = { + topLeftCornerOption: CornerOptions.ROUNDED_CORNER, + topLeftCornerRadius: 20, + bottomRightCornerOption: CornerOptions.FANCY_CORNER, + bottomRightCornerRadius: 20, + fillColor: b.gradient(b.color(255, 255, 220), b.color(200, 255, 255)), + gradientFillAngle: 45 + }; + b.objectStyle("cornerStyle", objectProps); + b.applyObjectStyle(tf, "cornerStyle"); + + + // get style from text object + var parStyle = b.characterStyle(tf.characters[10]); + b.println("Received character style \"" + parStyle.name + "\"."); +} + +b.go(); diff --git a/typography/text.jsx b/typography/text.jsx new file mode 100644 index 0000000..9be2fd2 --- /dev/null +++ b/typography/text.jsx @@ -0,0 +1,20 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + var myColor = b.color(10, 20, 30, "blackmagic"); + b.fill(myColor); + b.textFont("Helvetica", "Bold"); + b.textSize(96); + b.text("why hello basil.js", 0, 0, 350, 350); + + var myString = "i love \n using variables \n in basil.js"; // note the \n for a newline + b.fill(b.color(255, 25, 25, "redspecial")); + b.textAlign(Justification.RIGHT_ALIGN, VerticalJustification.CENTER_ALIGN); + b.textLeading(150); + b.textTracking(1000); + b.textSize(24); + b.text(myString, 0, b.height / 2, b.width, b.height / 2); +} + +b.go(); diff --git a/typography/textAlign.jsx b/typography/textAlign.jsx new file mode 100644 index 0000000..ad6bdaf --- /dev/null +++ b/typography/textAlign.jsx @@ -0,0 +1,66 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + + /* + Justification.AWAY_FROM_BINDING_SIDE + Justification.CENTER_ALIGN + Justification.CENTER_JUSTIFIED + Justification.FULLY_JUSTIFIED + Justification.LEFT_ALIGN + Justification.RIGHT_ALIGN + Justification.RIGHT_JUSTIFIED + Justification.TO_BINDING_SIDE + + VerticalJustification.BOTTOM_ALIGN + VerticalJustification.CENTER_ALIGN + VerticalJustification.JUSTIFY_ALIGN + VerticalJustification.TOP_ALIGN + */ + + var sayThis = "basil.js"; + var changeCol = 100; + var changeVal = 10; + var box; + var strokeW = 0.25; + + b.fill(changeCol); + b.textFont("Helvetica", "Bold"); + b.textSize(48); + + box = b.text(sayThis, 0, 0, b.width, 80); + changeCol -= changeVal; + box.strokeWeight = strokeW; + + b.fill(changeCol); + b.textAlign(Justification.CENTER_ALIGN); + box = b.text(sayThis, 0, 100, b.width, 80); + changeCol -= changeVal; + box.strokeWeight = strokeW; + + b.fill(changeCol); + b.textAlign(Justification.RIGHT_ALIGN); + box = b.text(sayThis, 0, 200, b.width, 80); + changeCol -= changeVal; + box.strokeWeight = strokeW; + + b.fill(changeCol); + b.textAlign(Justification.FULLY_JUSTIFIED); + box = b.text(sayThis, 0, 300, b.width, 80); + changeCol -= changeVal; + box.strokeWeight = strokeW; + + b.fill(changeCol); + b.textAlign(Justification.FULLY_JUSTIFIED, VerticalJustification.CENTER_ALIGN); + box = b.text(sayThis, 0, 400, b.width, 80); + changeCol -= changeVal; + box.strokeWeight = strokeW; + + b.fill(changeCol); + b.textAlign(Justification.FULLY_JUSTIFIED, VerticalJustification.BOTTOM_ALIGN); + box = b.text(sayThis, 0, 500, b.width, 80); + box.strokeWeight = strokeW; +} + +b.go(); diff --git a/typography/typo.jsx b/typography/typo.jsx new file mode 100644 index 0000000..c48b3d9 --- /dev/null +++ b/typography/typo.jsx @@ -0,0 +1,48 @@ +// @includepath "~/Documents/;%USERPROFILE%Documents"; +// @include "basiljs/basil.js"; + +function draw() { + var content = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr,\r"; + content += "sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat."; + + var doc = b.doc(); + + // add 5 pages to doc + for (var i = 0; i < 5; i++) { + doc.pages.add(); + } + + // add 2 text frame on each page + for (var j = 0, len = doc.pages.length; j < len; j++) { + b.page(j); + b.text(content, 0, 0, 600, 300); + b.text(content, 0, 350, 600, 300); + } + + var green = b.color(0, 255, 0, "green"); + var red = b.color(255, 0, 0, "red"); + + // change pointSize in all text frames in document + b.typo(doc, "pointSize", 48); + + // change fillColor on 2nd spread + b.typo(doc.spreads[1], "fillColor", red); + + // change strokeColor on 4th page + b.typo(doc.pages[3], "strokeColor", green); + + // change some more fine granular stuff in text frame on 1st page + var textFrame = doc.pages[0].textFrames[0]; + b.typo(textFrame, "pointSize", 36); + b.typo(textFrame.words[1], "appliedFont", "Helvetica\tBold"); + b.typo(textFrame.words[1], "underline", true); + b.typo(textFrame.lines[1], "pointSize", 48); + b.typo(textFrame.characters[50], "pointSize", 96); + b.typo(textFrame.paragraphs[1], "strokeColor", red); + +// todo: add more relevant fields as a list here +// b.typo(textFrame, 'justification', Justification.RIGHT_ALIGN); + +} + +b.go();