Skip to content

Commit c8c540e

Browse files
committed
start of tutorial merging..
initial merges.. still need to do a very keen eye overpass for errors and content updates
1 parent 6588285 commit c8c540e

File tree

9 files changed

+497
-0
lines changed

9 files changed

+497
-0
lines changed

tutorials/drawing_color/index.md

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
---
2+
author: admin
3+
layout: drawing_color
4+
title: "Drawing and colors"
5+
---
6+
7+
## General information
8+
9+
- basil.js does not have a screen or canvas
10+
- You cannot draw pixels
11+
- Instead you add InDesign objects to your pages
12+
- These can be used normally within InDesign afterwards
13+
- And you can undo them!
14+
15+
16+
### 1. Filling the paper with a rect() by reading its size
17+
```
18+
// @includepath "~/Documents/;%USERPROFILE%Documents";
19+
// @include "basiljs/basil.js";
20+
21+
function draw() {
22+
println( "width " + width );
23+
println( "height " + height );
24+
rect(0, 0, width, height);
25+
};
26+
```
27+
28+
- As there is no `background()` command in basil.js you should use `rect()` in order to change the background color.
29+
30+
### How to account for margins or bleed settings
31+
32+
```
33+
// @includepath "~/Documents/;%USERPROFILE%Documents";
34+
// @include "basiljs/basil.js";
35+
36+
function draw() {
37+
38+
noFill();
39+
stroke(0, 255, 0);
40+
41+
canvasMode(MARGIN);
42+
rect(0, 0, width, height);
43+
44+
canvasMode(PAGE);
45+
rect(0, 0, width, height);
46+
47+
canvasMode(BLEED);
48+
rect(0, 0, width, height);
49+
50+
// the following examples only work for documents with facing pages
51+
52+
canvasMode(FACING_MARGINS);
53+
rect(0, 0, width, height);
54+
55+
canvasMode(FACING_PAGES);
56+
rect(0, 0, width, height);
57+
58+
canvasMode(FACING_BLEEDS);
59+
rect(0, 0, width, height);
60+
61+
}
62+
```
63+
64+
- Using different canvas modes will position the origin of the coordinate system (think 0,0) to the appropriate spots in the canvas.
65+
- Additionally `width` and `height` will be updated to reflect the new size of the canvas.
66+
- You can still use other spots of the canvas with extreme coordinates as the canvas modes are not limiting you down to them.
67+
68+
### 2. Generate several swatches with color() and paint with rect()
69+
```
70+
// @includepath "~/Documents/;%USERPROFILE%Documents";
71+
// @include "basiljs/basil.js";
72+
73+
function draw() {
74+
75+
colorMode(RGB); // this is the default anyways
76+
77+
// create new RGB color
78+
var red = color(255, 2, 3); // variables can store data to be reused later
79+
var green = color(0, 255, 0, "green");
80+
81+
fill(red);
82+
rect(0, 0, width, 50);
83+
fill(green);
84+
rect(0, 50, width, 50);
85+
86+
// create new CMYK color
87+
var magenta = color(1, 100, 3, 4);
88+
var yellow = color(0, 0, 100, 0, "yellow");
89+
var grey = color(100);
90+
var lightGrey = color(5, "light grey");
91+
92+
fill( magenta );
93+
rect(0, 200, width, 50);
94+
fill( yellow );
95+
rect(0, 250, width, 50);
96+
fill( grey );
97+
rect(0, 300, width, 50);
98+
fill( lightGrey );
99+
rect(0, 350, width, 50);
100+
101+
// get a color from document
102+
var black = color("Black");
103+
fill(black);
104+
rect(0, 500, width, 50);
105+
}
106+
```
107+
108+
- `color()` can accept between one and five parameters.
109+
- basil.js uses the number of given color channels to decide whether to create a RGB or CMYK color.
110+
- If the arguments do not clearly define the desired type of color then the current basil.js color mode is used.
111+
- The default basil.js color mode is RGB
112+
- Please note that CMYK takes channel numbers between 0-100 where higher is darker (subtractive color), while RGB takes numbers between 0-255 where lower is darker (additive color).
113+
<!-- Exercise: Create a horizontal rainbow -->
114+
115+
### 3. Using random() to pick a color and fill the background
116+
```
117+
// @includepath "~/Documents/;%USERPROFILE%Documents";
118+
// @include "basiljs/basil.js";
119+
120+
function draw() {
121+
// create new random RGB color
122+
var newRandomColor = color(random(255), random(255), random(255));
123+
124+
// fill rect with it
125+
fill(newRandomColor);
126+
rect(0, 0, width, height);
127+
}
128+
```
129+
130+
131+
### 4. Using line() to create a cross
132+
```
133+
// @includepath "~/Documents/;%USERPROFILE%Documents";
134+
// @include "basiljs/basil.js";
135+
136+
function draw() {
137+
stroke(100);
138+
strokeWeight(5);
139+
// draw a cross
140+
line(0, 0, width, height);
141+
line(0, height, width, 0);
142+
}
143+
```
144+
145+
<!-- Exercise: Create a Haus of Nikolaus -->
146+
147+
### 5. Using random() and ellipse() to fill the page with circles
148+
```
149+
// @includepath "~/Documents/;%USERPROFILE%Documents";
150+
// @include "basiljs/basil.js";
151+
152+
function draw() {
153+
var count = 23;
154+
155+
doc();
156+
println(width + " x " + height);
157+
158+
for (var i = 0; i < 23; i++) {
159+
var x = random(0, width);
160+
var y = random(0, height);
161+
var size = random(10, 123);
162+
ellipse(x, y, size, size);
163+
}
164+
}
165+
```
166+
167+
- This creates confetti
168+
169+
170+
### 6. Using a for-loop and map() to create a gradient
171+
```
172+
// @includepath "~/Documents/;%USERPROFILE%Documents";
173+
// @include "basiljs/basil.js";
174+
175+
function draw() {
176+
var counter = 50;
177+
noStroke();
178+
var rectHeight = height/counter;
179+
180+
for (var i = 0; i < counter; i++) {
181+
var y = map(i, 0, counter-1, 0, height - rectHeight);
182+
var fillTint = map(i, 0, counter-1, 100, 0);
183+
184+
fill(fillTint);
185+
rect(0, y, width, rectHeight);
186+
}
187+
}
188+
```
189+
190+
191+
### 8. Using random() and nested for loops to create a matrix of lines
192+
```
193+
// @includepath "~/Documents/;%USERPROFILE%Documents";
194+
// @include "basiljs/basil.js";
195+
196+
function draw() {
197+
var tileCount = 10;
198+
var randomX = random(0, width);
199+
var randomY = random(0, height);
200+
201+
strokeWeight(1);
202+
203+
for (var gridY = 0; gridY <= tileCount; gridY++) {
204+
for (var gridX = 0; gridX <= tileCount; gridX++) {
205+
var posX = width / tileCount * gridX;
206+
var posY = height / tileCount * gridY;
207+
line(posX, posY, randomX, randomY);
208+
}
209+
}
210+
211+
};
212+
```

tutorials/finding_help/index.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
author: admin
3+
layout: finding_help
4+
title: "Finding Help"
5+
---
6+
7+
## InDesign scripting inspirations
8+
- [The "Jongware" reference](http://jongware.mit.edu/idcs6js/)
9+
- [InDesign Secrets](http://indesignsecrets.com/)
10+
- [Extendables](http://extendables.org/)
11+
- [Typography and Automation at FH Potsdam](http://fabiantheblind.github.com/Typography-And-Automation/)
12+
- [Fabian The Blind's Wiki](https://github.com/fabiantheblind/auto-typo-adbe-id/wiki)
13+
- [Fabian The Blind's Scripts](http://fabiantheblind.info/coding.html)
14+
- [Adobe InDesign Skriptwerkstatt (german)](http://www.hilfdirselbst.ch/foren/gforum.cgi?forum=61;)
15+
16+
## Processing inspirations
17+
- [Creative Coding](http://www.creativecoding.org/)
18+
- [Processing](http://processing.org/)
19+
20+
Please note the cheatsheets available on our [Downloads](../download/) page
21+
40.5 KB
Loading
38 KB
Loading
30.6 KB
Loading

tutorials/getting_started/index.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
author: admin
3+
layout: getting_started
4+
title: "Getting Started"
5+
---
6+
7+
## Installation
8+
9+
Although basil.js scripts can simply be opened and run from ExtendScript Toolkit through the Finder / Explorer, you may wish to have access to our examples and your scripts within the Scripts window of InDesign.
10+
11+
1. Get the latest copy of basil.js from our [Downloads](http://basiljs.ch/downloads) section.
12+
13+
2. Use Finder (resp. Explorer) and create a folder called "basiljs" in the Documents folder of your home directory. This will be the central place where you store all basil related files. Please make sure that this folder matches *USER_FOLDER*/Documents/basiljs exactly. Note that the Documents folder might have a different name depending on your language setting and operating system, but that's ok.
14+
15+
3. Place the bundle folder of the zip inside the new basiljs folder.
16+
17+
4. Create a folder called "user" next to the bundle folder. Use this new folder for your projects and experiments. The separation of basil.js' internal and the user's files will make it easy for you to update to new versions by just overwriting the bundle.
18+
19+
5. Open up InDesign and activate the Scripts panel from the menu. This should look like this:
20+
21+
![Picture of Utilities menu](images/install1.png)
22+
23+
![Picture of Scripts panel](images/install2.png)
24+
25+
6. Right-click the "User" folder and click on "Reveal in Finder" resp. "Reveal in Explorer".
26+
27+
7. Create a Symbolic Link between your basiljs folder and the Scripts Panel folder by entering the following command in Terminal (/Applications/Utilities/):
28+
`ln -s basiljs_PATH Scripts_Panel_PATH`
29+
This can also be done by first entering `ln -s ` add a space, drag + drop your basiljs folder over the Terminal window, make sure there is another space and drag+drop the Scripts Panel folder. You'll see what looks like a normal alias, but is now recognized in InDesign CC 10+
30+
31+
8. Check if InDesign has detected your basiljs folder:
32+
33+
![Picture of basil.js with open bundle folders in Script panel](images/install3.png)
34+
35+
9. Run one of the scripts in example/color to check if basil.js is installed correctly. Congratulations!
36+
37+
## Overview
38+
39+
Let's have a look at what is in the box. The file basil.js carries the actual library, it's a quite big file that you usually should not open unless you know what you are doing. The examples/ folder shows a number of little scripts that explain how the features of basil.js work and can be used as a good starting point. The lib/ folder is meant for external libraries that are bundled with basil.js and should not be used by users. If you want to add your own libraries you should put them into user/libraries instead. (Please note that the screenshot above shows a developer version of basil with more folders than you have received.)

tutorials/hello_world/index.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
author: admin
3+
layout: hello_world
4+
title: "Hello World"
5+
---
6+
7+
Open up the Adobe ExtendScript Editor, which is the script editor that comes with the Adobe Creative Suite. We will use this editor for our tutorials, but basically you could use any JavaScript editor.
8+
9+
Create a new file and save it to helloworld.jsx within your user folder. Copy and paste the following code into your newly created file.
10+
11+
12+
## Simple Hello World example
13+
14+
```
15+
// @includepath "~/Documents/;%USERPROFILE%Documents";
16+
// @include "basiljs/basil.js";
17+
18+
function draw() {
19+
println( "Hello World!" );
20+
}
21+
```
22+
23+
The include statements found in this examples always have to be at the very beginning of each basil.js file. They will load the actual library from your basil.js installation.
24+
25+
Afterwards you will find two function blocks. setup() is pretty much the same as in Processing. It's the first user function that is called once right after your code is started. You should use this to initialize variables, etc. Afterwards the draw() function is executed. But unlike in Processing it is only called once, since basil.js is not interactive by default (There is an interactive mode available for advanced use though).
26+
27+
Now run the script... either by pressing the play button from within the ExtendScript editor or by double-clicking your script from the InDesign scripts panel. You will be able to read an output in the console of the ExtendScript editor saying "Hello World!".
28+
29+
No wonder, the statement
30+
31+
```
32+
println( "Hello World!" );
33+
```
34+
35+
is exactly meant for that.
36+
37+
Printing to the console is nice, but actually far from what basil.js is designed for. We should output our Hello World message to an InDesign textbox!
38+
39+
---
40+
41+
## Hello World example using a textbox
42+
43+
```
44+
// @includepath "~/Documents/;%USERPROFILE%Documents";
45+
// @include "basiljs/basil.js";
46+
47+
function draw() {
48+
doc();
49+
text("Hello World", 100, 100, 200, 50);
50+
}
51+
```
52+
53+
This is exactly what the example above is doing. Paste it over your existing code and run it by pressing play or double-clicking it from the scripts panel after saving. A text frame object will be added to your existing document - or if none was existing, a new document will be created - and filled with the Hello World message.
54+
55+
The `doc()` call makes sure that at least one document is open and the call to `text("Hello World", 100, 100, 200, 50);` will create a textframe with the default basil.js type settings (more on this in the typo tutorial), add it to the current layer and page, move it to 100, 100 (using the basil.js' default units), size it to 200, 50 and fill it with "Hello World!"
56+

0 commit comments

Comments
 (0)