Skip to content

Commit 4c775d9

Browse files
committed
Transferring all example scripts
1 parent 37e7929 commit 4c775d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1994
-0
lines changed

color/blendMode.jsx

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// @includepath "~/Documents/;%USERPROFILE%Documents";
2+
// @include "basiljs/basil.js";
3+
4+
function draw() {
5+
b.clear(b.doc());
6+
7+
var red = b.color(255, 0, 0);
8+
var lightBlue = b.color(0, 255, 255);
9+
10+
b.fill(red);
11+
b.ellipse(b.width / 3, b.height / 2, 333, 333);
12+
b.fill(lightBlue);
13+
var circle = b.ellipse(b.width / 3 * 2, b.height / 2, 333, 333);
14+
15+
/*
16+
BlendMode.NORMAL
17+
BlendMode.MULTIPLY
18+
BlendMode.SCREEN
19+
BlendMode.OVERLAY
20+
BlendMode.SOFT_LIGHT
21+
BlendMode.HARD_LIGHT
22+
BlendMode.COLOR_DODGE
23+
BlendMode.COLOR_BURN
24+
BlendMode.DARKEN
25+
BlendMode.LIGHTEN
26+
BlendMode.DIFFERENCE
27+
BlendMode.EXCLUSION
28+
BlendMode.HUE
29+
BlendMode.SATURATION
30+
BlendMode.COLOR
31+
BlendMode.LUMINOSITY
32+
*/
33+
34+
b.blendMode(circle, BlendMode.HARD_LIGHT);
35+
}
36+
37+
b.go();

color/color.jsx

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// @includepath "~/Documents/;%USERPROFILE%Documents";
2+
// @include "basiljs/basil.js";
3+
4+
function draw() {
5+
// get the number of swatches, to see later how many new ones have been created
6+
var swatchCount = b.doc().swatches.length;
7+
b.println("Document has " + swatchCount + " swatches");
8+
9+
b.println("Default colormode is: " + b.colorMode());
10+
11+
// create RGB colors
12+
b.colorMode(b.RGB);
13+
var red = b.color(255, 2, 3);
14+
var green = b.color(0, 255, 0, "my green"); // set the name of the RBG color, see colour window
15+
var rgbGrey = b.color(128);
16+
17+
b.stroke(rgbGrey);
18+
b.fill(red);
19+
b.rect(0, 0, b.width, 50);
20+
b.fill(green);
21+
b.rect(0, 50, b.width, 50);
22+
23+
24+
// create CMYK colors
25+
b.colorMode(b.CMYK);
26+
var magenta = b.color(1, 100, 3, 4);
27+
var yellow = b.color(0, 0, 100, 0, "my yellow"); // set the name of the CMYK color, see colour window
28+
var cmykGrey = b.color(80, "my light grey");
29+
30+
b.stroke(cmykGrey);
31+
b.fill(magenta);
32+
b.rect(0, 200, b.width, 50);
33+
b.fill(yellow);
34+
b.rect(0, 250, b.width, 50);
35+
36+
// get a color from the document via the name
37+
b.fill(b.color("my green"));
38+
b.rect(0, 500, b.width, 50);
39+
// a few colors like "Black" are predefined in every indesign document
40+
var black = b.color("Black");
41+
b.fill(black);
42+
b.rect(0, 550, b.width, 50);
43+
44+
b.println(b.doc().swatches.length - swatchCount + " colors added to the swatches of the document");
45+
}
46+
47+
b.go();

color/fill.jsx

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @includepath "~/Documents/;%USERPROFILE%Documents";
2+
// @include "basiljs/basil.js";
3+
4+
function draw() {
5+
// create new random RGB color
6+
var newRandomColor = b.color(b.random(0, 255),
7+
b.random(0, 255),
8+
b.random(0, 255));
9+
10+
// fill rect with it
11+
b.fill(newRandomColor);
12+
b.rect(0, 0, b.width, b.height);
13+
}
14+
15+
b.go();

color/fillTint.jsx

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// @includepath "~/Documents/;%USERPROFILE%Documents";
2+
// @include "basiljs/basil.js";
3+
4+
function draw() {
5+
var counter = 50;
6+
b.noStroke();
7+
var rectHeight = b.height / counter;
8+
9+
for (var i = 0; i < counter; i++) {
10+
var y = b.map(i, 0, counter - 1, 0, b.height - rectHeight);
11+
var fillTint = b.map(i, 0, counter - 1, 100, 0);
12+
13+
b.fillTint(fillTint);
14+
b.rect(0, y, b.width, rectHeight);
15+
}
16+
}
17+
18+
b.go();

color/gradient.jsx

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// @includepath "~/Documents/;%USERPROFILE%Documents";
2+
// @include "basiljs/basil.js";
3+
4+
function draw() {
5+
b.clear(b.doc());
6+
b.noStroke();
7+
8+
var dist = b.height / 4;
9+
10+
// create two colors
11+
var red = b.color(255, 0, 0);
12+
var blue = b.color(0, 0, 255);
13+
14+
// create array with 10 random colors
15+
var randomColors = [];
16+
for (var i = 0; i < 10; i++) {
17+
randomColors.push(b.color(b.random(0, 255), b.random(0, 255), b.random(0, 255)));
18+
}
19+
20+
// create array with 10 random numbers (0-100)
21+
var randomNumbers = [];
22+
for (var j = 0; j < 10; j++) {
23+
randomNumbers.push(b.random(0, 100));
24+
}
25+
26+
// draw rectangles and fill them with different types of gradients
27+
28+
// grandient from color1 to color2
29+
b.fill(b.gradient(red, blue, "RedBlueLinear"));
30+
b.rect(0, dist * 0, b.width, dist);
31+
32+
// gradient from array of colors
33+
b.fill(b.gradient(randomColors, "RandomCol"));
34+
b.rect(0, dist * 1, b.width, dist);
35+
36+
// gradient from same array of colors with random gradient stop positions
37+
b.fill(b.gradient(randomColors, randomNumbers, "RandomCol/Pos"));
38+
b.rect(0, dist * 2, b.width, dist);
39+
40+
// radial gradient from color1 to color2
41+
b.gradientMode(b.RADIAL);
42+
b.fill(b.gradient(red, blue, "RedBlueRadial"));
43+
b.rect(0, dist * 3, b.width, dist);
44+
45+
// stroke gradient
46+
b.noFill();
47+
b.strokeWeight(4);
48+
b.gradientMode(b.LINEAR);
49+
b.stroke(b.gradient(blue, red, "BlueRedLinear"));
50+
b.ellipse(b.width / 2, b.height / 2, dist * 2, dist * 2);
51+
}
52+
53+
b.go();

color/lerpColor.jsx

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @includepath "~/Documents/;%USERPROFILE%Documents";
2+
// @include "basiljs/basil.js";
3+
4+
function draw() {
5+
var c1 = b.color(0, 255, 0);
6+
var c2 = b.color(255, 128, 0);
7+
8+
var counter = 10;
9+
b.noStroke();
10+
var rectHeight = b.height / counter;
11+
12+
for (var i = 0; i < counter; i++) {
13+
var y = b.map(i, 0, counter - 1, 0, b.height - rectHeight);
14+
var amt = b.map(i, 0, counter - 1, 0, 1);
15+
16+
b.fill(b.lerpColor(c1, c2, amt));
17+
b.rect(0, y, b.width, rectHeight);
18+
}
19+
}
20+
21+
b.go();

color/opacity.jsx

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @includepath "~/Documents/;%USERPROFILE%Documents";
2+
// @include "basiljs/basil.js";
3+
4+
function draw() {
5+
b.clear(b.doc());
6+
7+
var red = b.color(255, 0, 0);
8+
var black = b.color("Black");
9+
10+
b.fill(red);
11+
b.ellipse(b.width / 2, b.height / 2, 333, 333);
12+
13+
b.fill(black);
14+
var rect = b.rect(b.width / 2, 0, b.width / 2, b.height);
15+
16+
// set the opacity
17+
b.opacity(rect, 37);
18+
}
19+
20+
b.go();

color/stroke.jsx

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// @includepath "~/Documents/;%USERPROFILE%Documents";
2+
// @include "basiljs/basil.js";
3+
4+
function draw() {
5+
// create new random RGB color
6+
var newRandomColor = b.color(b.random(0, 255),
7+
b.random(0, 255),
8+
b.random(0, 255));
9+
10+
b.stroke(newRandomColor);
11+
b.strokeWeight(10);
12+
// draw a cross with random color
13+
b.line(0, 0, b.width, b.height);
14+
b.line(0, b.height, b.width, 0);
15+
}
16+
17+
b.go();

color/strokeTint.jsx

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// @includepath "~/Documents/;%USERPROFILE%Documents";
2+
// @include "basiljs/basil.js";
3+
4+
function draw() {
5+
var counter = 50;
6+
b.strokeWeight(7);
7+
8+
for (var i = 0; i < counter; i++) {
9+
var y = b.map(i, 0, counter - 1, 0, b.height);
10+
var newStrokeTint = b.map(i, 0, counter - 1, 100, 0);
11+
12+
// set stroke tint of current color
13+
b.strokeTint(newStrokeTint);
14+
b.line(0, y, b.width, y);
15+
}
16+
}
17+
18+
b.go();

data/HashList.jsx

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// @includepath "~/Documents/;%USERPROFILE%Documents";
2+
// @include "basiljs/basil.js";
3+
4+
// example shows how to use a HashList to count the occurrence of words in a text
5+
6+
function draw() {
7+
8+
b.canvasMode(b.MARGIN);
9+
10+
var hash = new HashList();
11+
12+
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.";
13+
var tf1 = b.text(longString, 0, 0, b.width, 200);
14+
var tf2 = b.text(longString, 0, 220, b.width, 200);
15+
var tf3 = b.text("", 0, 440, b.width, 200);
16+
var words = longString.split(" ");
17+
18+
var str;
19+
for(var i = 0; i < words.length; i++) {
20+
str = words[i];
21+
str = b.trimWord(str);
22+
if (str === "") {
23+
continue;
24+
} // special case: nothing left after trimWord
25+
// count the number of occurances
26+
if(hash.hasKey(str)) {
27+
b.println(str);
28+
hash.set(str, hash.get(str) + 1);
29+
} else {
30+
hash.set(str, 1);
31+
}
32+
}
33+
34+
var keys = (hash.getKeysByValues()); // sorts it by the number of its occurences.
35+
var result1 = "";
36+
var result2 = "";
37+
for (var j = 0; j < keys.length; j++) {
38+
var word = keys[j];
39+
for (var n = 0; n < hash.get(word); n++) {
40+
result1 += word + " ";
41+
}
42+
result2 += (word + " : " + hash.get(word) + ", ");
43+
}
44+
tf2.contents = result1;
45+
tf3.contents = result2;
46+
47+
}
48+
49+
b.go();

data/csv.jsx

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* example shows how to parse a raw CSV string to a javascript object.
3+
* no idea what CSV is? then have a read here: http://en.wikipedia.org/wiki/Comma-separated_values
4+
*/
5+
6+
// @includepath "~/Documents/;%USERPROFILE%Documents";
7+
// @include "basiljs/basil.js";
8+
9+
// to load an external csv file use
10+
// var jsonString = b.loadString("path/to/file.csv")
11+
12+
var csvString = "";
13+
csvString += "firstName,lastName,middleInitial,firstNameFirst,lastNameFirst\n";
14+
csvString += "Kristina,Chung,H,Kristina H. Chung,\"Chung, Kristina H.\"\n";
15+
csvString += "Paige,Chen,H,Paige H. Chen,\"Chen, Paige H.\"\n";
16+
csvString += "Sherri,Melton,E,Sherri E. Melton,\"Melton, Sherri E.\"\n";
17+
csvString += "Gretchen,Hill,I,Gretchen I. Hill,\"Hill, Gretchen I.\"\n";
18+
csvString += "Karen,Puckett,U,Karen U. Puckett,\"Puckett, Karen U.\"\n";
19+
csvString += "Patrick,Song,O,Patrick O. Song,\"Song, Patrick O.\"\n";
20+
csvString += "Elsie,Hamilton,A,Elsie A. Hamilton,\"Hamilton, Elsie A.\"\n";
21+
csvString += "Hazel,Bender,E,Hazel E. Bender,\"Bender, Hazel E.\"\n";
22+
csvString += "Malcolm,Wagner,A,Malcolm A. Wagner,\"Wagner, Malcolm A.\"\n";
23+
csvString += "Dolores,McLaughlin,C,Dolores C. McLaughlin,\"McLaughlin, Dolores C.\"\n";
24+
csvString += "Francis,McNamara,C,Francis C. McNamara,\"McNamara, Francis C.\"\n";
25+
csvString += "Sandy,Raynor,A,Sandy A. Raynor,\"Raynor, Sandy A.\"\n";
26+
csvString += "Marion,Moon,O,Marion O. Moon,\"Moon, Marion O.\"\n";
27+
csvString += "Beth,Woodard,O,Beth O. Woodard,\"Woodard, Beth O.\"\n";
28+
csvString += "Julia,Desai,E,Julia E. Desai,\"Desai, Julia E.\"\n";
29+
// ... an excerpt of randomNames.csv
30+
// from http://www.opensourcecf.com/1/2009/05/10000-Random-Names-Database.cfm
31+
32+
function setup() {
33+
b.clear(b.doc());
34+
35+
// set the delimiter
36+
// very common for .csv files is ',' (=default) or ';' and for .tsv files '\t'
37+
// b.CSV.delimiter(',')
38+
39+
// parse CSV
40+
var csvData = b.CSV.decode(csvString);
41+
42+
// create textframes for "firstNameFirst" column
43+
for (var i = 0; i < csvData.length; i++) {
44+
b.text(csvData[i].firstNameFirst, 0, i * 20, b.width, 19);
45+
}
46+
47+
// convert an array of key value objects to a CSV-string
48+
b.println(b.CSV.encode(csvData));
49+
}
50+
51+
b.go();

0 commit comments

Comments
 (0)