Skip to content

Commit a477eba

Browse files
committed
merging tutorials
- renumbered to match website - still needs review for content, links, references, etc.
1 parent b754c70 commit a477eba

File tree

16 files changed

+888
-2
lines changed

16 files changed

+888
-2
lines changed
95.1 KB
Binary file not shown.
File renamed without changes.

tutorials/03-syntax/index.md renamed to tutorials/02-syntax/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
author: admin
33
layout: tutorial
4-
title: "Syntax check basil.js vs. Processing"
4+
title: "Syntax Check basil.js vs. Processing"
55
---
66

77
## Similarities between basil.js and Processing
File renamed without changes.

tutorials/02-drawing-color/index.md renamed to tutorials/05-drawing-color/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
author: admin
33
layout: tutorial
4-
title: "Drawing and colors"
4+
title: "Drawing and Colors"
55
---
66

77
## General information

tutorials/06-page-management/index.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
author: admin
3+
layout: tutorial
4+
title: "Page Management"
5+
---
6+
7+
## Adding pages
8+
```
9+
// @includepath "~/Documents/;%USERPROFILE%Documents";
10+
// @include "basiljs/basil.js";
11+
12+
function draw() {
13+
// add one page at the end of the document and jump to it
14+
addPage();
15+
text("Example 1", width/2, height/2, 100, 100);
16+
}
17+
```
18+
19+
## Removing pages
20+
```
21+
// removes current page
22+
removePage();
23+
24+
// fill up again...
25+
addPage();
26+
27+
// removes page 1
28+
removePage(1);
29+
```
30+
31+
## Using references to pages
32+
```
33+
// @includepath "~/Documents/;%USERPROFILE%Documents";
34+
// @include "basiljs/basil.js";
35+
36+
function draw() {
37+
var myPage = addPage();
38+
var myTextFrame = text("hello world", 20, 20, 100, 20); // add a text frame on that page
39+
page(1); // leave that page
40+
page(myTextFrame); // go to the page where this PageItem sits
41+
42+
// removes myPage right away... you won't see it ever
43+
removePage(myPage);
44+
}
45+
```
46+
47+
- `addPage()` and `page()` return a reference to the new or determined page that you can store in a variable.
48+
- You can pass a PageItem such as a TextFrame to `page()` in order to jump to the page that contains the given PageItem
49+
50+
## Populating larger documents and adding between pages
51+
```
52+
// @includepath "~/Documents/;%USERPROFILE%Documents";
53+
// @include "basiljs/basil.js";
54+
55+
function draw() {
56+
// run this on an empty document with only one page!
57+
58+
// add pages until 20
59+
for (var i = pageCount(); i < 20; i++) {
60+
addPage();
61+
text("Example 2-" + i, width/2, height/2, 100, 100);
62+
}
63+
64+
// set location of insertion
65+
addPage(AT_END); // default
66+
text("Example AT_END", width/2, height/2, 100, 100);
67+
addPage(AT_BEGINNING);
68+
text("Example AT_BEGINNING", width/2, height/2, 100, 100);
69+
70+
// adds a page before page 15
71+
page(10); // set current page
72+
addPage(BEFORE); // this refers to the current page
73+
text("Example BEFORE 10 becomes the new 10", width/2, height/2, 100, 100);
74+
75+
// guess what!
76+
page(15);
77+
addPage(AFTER);
78+
text("Example AFTER 15 becomes 16", width/2, height/2, 100, 100);
79+
80+
println(pageCount());
81+
}
82+
```
83+
84+
- This example raises the page count to 20
85+
- You can use AT_END, AT_BEGINNING, BEFORE and AFTER to define where the new page should be inserted
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
---
2+
author: admin
3+
layout: tutorial
4+
title: "Selection and Navigation"
5+
---
6+
7+
## Get the mouse selection
8+
9+
```
10+
// @includepath "~/Documents/;%USERPROFILE%Documents";
11+
// @include "basiljs/basil.js";
12+
13+
function draw() {
14+
var selItems = selections();
15+
16+
// only use first item selected
17+
typo(selItems[0], "pointSize", 30);
18+
19+
// for-loop
20+
for (var i = 0; i < selItems.length; i++) {
21+
println(selItems);
22+
typo(selItems[i], "pointSize", 30);
23+
}
24+
25+
// experts: use a looping callback
26+
selections(function(item, i){
27+
println(item);
28+
typo(item, "pointSize", 30);
29+
});
30+
}
31+
```
32+
33+
- `selections()` returns all the selected PageItems or Text elements as an array of mixed items
34+
- Please note that you will always receive an array, also if just one element is selected
35+
- This a sensible strategy if you haven't created many things and they ended up being distributed all over the page
36+
- Also good for changing certain items only that you select by e.g. aesthetical criteria
37+
38+
## Add, get and set a layer
39+
```
40+
// @includepath "~/Documents/;%USERPROFILE%Documents";
41+
// @include "basiljs/basil.js";
42+
43+
function draw() {
44+
// add new layer
45+
var layer = layer("myLayer");
46+
ellipse(20,20,10,10);
47+
48+
// set active layer
49+
layer(layer);
50+
// also possible:
51+
layer("myLayer");
52+
53+
// delete the layer... remove() can be used with all PageItems
54+
layer.remove();
55+
}
56+
```
57+
58+
- You can add layers with `layer()`
59+
- You can also activate pre-existing layers
60+
- Putting your new elements on clearly labelled layers is a clean way to keep your project tidy
61+
- You can also use layers to select and alter the new items easily or set them to invisible
62+
63+
##Process all objects from a layer, page or document
64+
```
65+
// @includepath "~/Documents/;%USERPROFILE%Documents";
66+
// @include "basiljs/basil.js";
67+
68+
function draw() {
69+
// process all items on a layer
70+
var items = items(layer("fancy"));
71+
for (var i = 0; i < items.length; i++) {
72+
println(items[i]);
73+
}
74+
75+
// process all items on a page
76+
var items = items(page(1));
77+
for (var i = 0; i < items.length; i++) {
78+
println(items[i]);
79+
}
80+
81+
// process all items in document
82+
var items = items(doc());
83+
for (var i = 0; i < items.length; i++) {
84+
println(items[i]);
85+
}
86+
}
87+
```
88+
89+
- `items()` allows you to process everything on a Layer, in a Group, on a Page or in a Document
90+
91+
<!--
92+
## Changing strokeColor, strokeWeight and fillColor on existing items
93+
```
94+
// @includepath "~/Documents/;%USERPROFILE%Documents";
95+
// @include "basiljs/basil.js";
96+
97+
function draw() {
98+
99+
var items = items(layer("fancy"));
100+
101+
for (var i = 0; i < items.length; i++) {
102+
items[i].strokeWeight = 3;
103+
items[i].strokeColor = color(255,0,0,"myRed");
104+
items[i].fillColor = color(0,0,255,"myBlue");
105+
}
106+
107+
}
108+
```
109+
-->
110+
111+
## Attaching labels to created items
112+
```
113+
// @includepath "~/Documents/;%USERPROFILE%Documents";
114+
// @include "basiljs/basil.js";
115+
116+
function draw() {
117+
// the following methods return the PageItem they create
118+
// thus you can set their label directly after their method call
119+
ellipse(20,20,5,5).label = "dynamic";
120+
ellipse(20,20,5,5).label = "dynamic";
121+
text("hihi",20,20,20,20).label = "dynamic";
122+
rect(20,20,5,5).label = "dynamic";
123+
line(20,20,50,50).label = "dynamic";
124+
125+
// this way, you can access them by calling their name
126+
// please note that labels() always returns an array
127+
var items = labels("dynamic");
128+
129+
// you can use forEach() to do something with all of these items
130+
for (var i = 0; i < items.length; i++) {
131+
println(items[i]);
132+
}
133+
134+
// or you address them individually
135+
transform(items[0], "position", [100, 0]);
136+
}
137+
```
138+
139+
- Labels can be attached to PageItems by code or mouse using the Script Label panel in InDesign
140+
- Since labels are a bit hard to find in the GUI they should only be used if layers don't work for your endeavour
141+
142+
<!--
143+
## Set selection by code
144+
how to do this?
145+
select() is cancelling selection on previously selected things...
146+
-->
147+
148+
149+
<!-- ## How to use the Adobe Object Model and work with collections -->
150+
151+
## Cleaning up and removing stuff
152+
```
153+
// @includepath "~/Documents/;%USERPROFILE%Documents";
154+
// @include "basiljs/basil.js";
155+
156+
function draw() {
157+
// clears the given layer
158+
clear(layer("fancy"));
159+
// fully delete a layer
160+
layer("fancy").remove();
161+
// clears the given page
162+
clear(page());
163+
// clears the document
164+
clear(doc());
165+
}
166+
```
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
author: admin
3+
layout: tutorial
4+
title: "Transform PageItems"
5+
---
6+
7+
```
8+
// @includepath "~/Documents/;%USERPROFILE%Documents";
9+
// @include "basiljs/basil.js";
10+
11+
function draw() {
12+
doc();
13+
clear(doc());
14+
15+
units(MM); // use millimeter
16+
noStroke();
17+
fill(100); // black
18+
19+
var r = rect(50, 50, 30, 30);
20+
21+
delay(1000); // this is just to make the individual steps visible
22+
23+
transform(r, "position", [30, 0]);
24+
delay(1000);
25+
26+
transform(r, "position", [0, 30]);
27+
delay(1000);
28+
29+
transform(r, "position", [width/2, height/2]);
30+
delay(1000);
31+
32+
transform(r, "width", 50);
33+
delay(1000);
34+
35+
transform(r, "height", 50);
36+
delay(1000);
37+
38+
transform(r, "size", [30, 30]);
39+
delay(1000);
40+
41+
transform(r, "rotation", 45);
42+
delay(1000);
43+
44+
transform(r, "shearing", 15);
45+
delay(1000);
46+
47+
for (var i = 0; i < 50; i++) {
48+
var x = transform(r, "position").x;
49+
transform(r, "position", [x+2, 0]);
50+
delay(30);
51+
}
52+
53+
r.remove();
54+
55+
}
56+
```

0 commit comments

Comments
 (0)