-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
59 changed files
with
1,994 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
Oops, something went wrong.