Skip to content

Commit f6116ed

Browse files
committed
added API docs, readme tweaks
1 parent ed098f6 commit f6116ed

File tree

4 files changed

+213
-21
lines changed

4 files changed

+213
-21
lines changed

README.md

Lines changed: 161 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,171 @@
1-
generative-design-library.js
2-
=============================
1+
# generative-design-library.js
32

43
[p5.js](https://p5js.org/) library for the book [Generative Design](http://www.generative-gestaltung.de/)
54

6-
Developer Setup
7-
---------------
8-
Download [node.js](https://nodejs.org/) or install it via [Homebrew](https://brew.sh/) (macOS only):
5+
## Install
96

10-
```
11-
$ brew install node
12-
```
7+
npm install generative-design-library.js
138

14-
Node monitor watching on file changes:
9+
## API
1510

16-
```
17-
$ npm run watch
18-
```
11+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
1912

20-
Create a new bundle:
13+
### timestamp
2114

22-
```
23-
$ npm run dist
24-
```
15+
Returns neatly formated timestamp e.g. "151025_172441_790"
2516

26-
Acknowledgements
27-
----------------
17+
Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** formated timestamp
2818

29-
* ASE (Adobe Swatch Exchange) exporting is based on [node-ase-utils](https://github.com/DominikGuzei/node-ase-utils) by Dominik Guzei
30-
* Wacom tablet support (only Firefox and Safari) based on Wacom Plugin Table Values [Demo](http://www.wacomeng.com/web/TestFBPluginTable.html)
31-
* Azimuth and Altitude calculation function copy and paste from [JPEN](http://jpen.sourceforge.net/api/current/src-html/jpen/PLevel.html)
19+
### RED
20+
21+
Color constant
22+
23+
### GREEN
24+
25+
Color constant
26+
27+
### BLUE
28+
29+
Color constant
30+
31+
### HUE
32+
33+
Color constant
34+
35+
### SATURATION
36+
37+
Color constant
38+
39+
### BRIGHTNESS
40+
41+
Color constant
42+
43+
### GRAYSCALE
44+
45+
Color constant
46+
47+
### ALPHA
48+
49+
Color constant
50+
51+
### sortColors
52+
53+
Sorts an array of colors according to the given method
54+
55+
**Parameters**
56+
57+
- `colors` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** An array of colors.
58+
- `method` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Either gd.RED, gd.GREEN, gd.BLUE, gd.HUE, gd.SATURATION, gd.BRIGHTNESS, gd.GRAYSCALE or gd.ALPHA.
59+
60+
Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** formated timestamp as string
61+
62+
### ase.encode
63+
64+
Returns an ase swatch definition from an array of p5 colors.
65+
66+
**Parameters**
67+
68+
- `p5colors` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** an array of p5 colors
69+
70+
Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** an ase swatch definition
71+
72+
### WacomTablet
73+
74+
- **See: <http://www.wacomeng.com/web/>**
75+
76+
Use a Wacom tablet in your browser. Currently works only in Safari. Support of the Wacom browser plugin seems to be fading out. You have to add this to your html:
77+
78+
<object id="wtPlugin" type="application/x-wacomtabletplugin"></object>
79+
80+
#### values
81+
82+
Get the current values a Wacom tablet
83+
84+
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** with properties: isWacom, isEraser, pressure, sysX, sysY, tabX, tabY, rotationDeg, rotationRad, tiltX, tiltY, tangPressure, version, pointerType, tabletModel, azimuth, altitude
85+
86+
### Treemap
87+
88+
Creates a new empty Treemap. Content may be added using addData() or addTreemap().
89+
90+
**Parameters**
91+
92+
- `x` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** x position
93+
- `y` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** y position
94+
- `w` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** width
95+
- `h` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** height
96+
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** drawing and sorting options {sort:true or false, direction:"horizontal", "vertical" or "both"}
97+
98+
Returns **[Treemap](#treemap)** the created empty Treemap
99+
100+
#### x
101+
102+
x position of the rectangle.
103+
104+
#### y
105+
106+
y position of the rectangle.
107+
108+
#### w
109+
110+
width of the rectangle.
111+
112+
#### h
113+
114+
height of the rectangle.
115+
116+
#### addData
117+
118+
Adds one data element to the items array.
119+
If there is already an item which has this as data, just increase the counter of that item.
120+
If not, create a new Treemap with that data and init the counter with 1
121+
122+
**Parameters**
123+
124+
- `data` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array))** the data element (e.g. a String)
125+
126+
Returns **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns true, if a new treemap was created
127+
128+
#### addTreemap
129+
130+
Adds an empty treemap to this treemap. If data is given, this could be used
131+
to show and hide a complete sub-treemap from the diagram. There is no check,
132+
if there is already another treemap with that data.
133+
134+
**Parameters**
135+
136+
- `data` **([String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array))** the data element (e.g. a String)
137+
- `count`
138+
139+
Returns **[Treemap](#treemap)** Returns the new Treemap
140+
141+
#### calculate
142+
143+
Calculates the rectangles of each item. While doing this, all counters
144+
and ignore flags are updated.
145+
146+
#### draw
147+
148+
A simple recursive drawing routine. Draws only the rectangles.
149+
150+
## Developer Setup
151+
152+
Download [node.js](https://nodejs.org/), then:
153+
154+
Watch for file changes and create new bundles:
155+
156+
$ npm run watch
157+
158+
Create new bundles for `dist` folder:
159+
160+
$ npm run dist
161+
162+
Update API documentation:
163+
164+
$ npm run documentation
165+
166+
## Acknowledgements
167+
168+
- ASE (Adobe Swatch Exchange) exporting is based on [node-ase-utils](https://github.com/DominikGuzei/node-ase-utils) by Dominik Guzei
169+
- Wacom tablet support (only Firefox and Safari) based on Wacom Plugin Table Values [Demo](http://www.wacomeng.com/web/TestFBPluginTable.html)
170+
- Azimuth and Altitude calculation function copy and paste from [JPEN](http://jpen.sourceforge.net/api/current/src-html/jpen/PLevel.html)
171+
- API documentation generated with [documentation.js](https://github.com/documentationjs/)

Treemap.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* Would be nice to have...
1818
* TODO: Alternative constructor
1919
* @class Treemap
20+
* @ignore
2021
* @constructor
2122
* @param {Array} data data to store. A plain or nested array of numbers or objects.
2223
If the elements are numbers they are the counters. If objects, countkey names the key to use as a counter
@@ -26,6 +27,7 @@
2627

2728
/**
2829
* @class Treemap
30+
* @ignore
2931
* @constructor (mainly for internal use)
3032
* @param {Treemap} parent the parent Treemap
3133
* @param {String|Number|Object|Array} data one data element to store. could be anything.
@@ -35,6 +37,7 @@
3537

3638
/**
3739
* @class Treemap
40+
* @ignore
3841
* @constructor (mainly for internal use)
3942
* @param {Treemap} parent the parent Treemap
4043
* @return {Treemap} the created empty Treemap
@@ -335,6 +338,8 @@ function Treemap() {
335338
/**
336339
* Randomize array element order in-place.
337340
* Using Durstenfeld shuffle algorithm.
341+
*
342+
* @ignore
338343
*/
339344
function shuffleArray(array) {
340345
for (var i = array.length - 1; i > 0; i--) {

WacomTablet.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
// http://www.wacomeng.com/web/
44
// http://www.wacomeng.com/web/TestFBPluginTable.html
55

6+
/**
7+
* Use a Wacom tablet in your browser. Currently works only in Safari. Support of the Wacom browser plugin seems to be fading out. You have to add this to your html:
8+
*
9+
* <object id="wtPlugin" type="application/x-wacomtabletplugin"></object>
10+
*
11+
* @see {@link http://www.wacomeng.com/web/}
12+
* @class
13+
* @constructor
14+
*/
615
function WacomTablet() {
716
this.penValues = {
817
// wacom
@@ -83,6 +92,11 @@ WacomTablet.prototype._update = function() {
8392
return this.penValues;
8493
};
8594

95+
/**
96+
* Get the current values a Wacom tablet
97+
*
98+
* @return {Object} with properties: isWacom, isEraser, pressure, sysX, sysY, tabX, tabY, rotationDeg, rotationRad, tiltX, tiltY, tangPressure, version, pointerType, tabletModel, azimuth, altitude
99+
*/
86100
WacomTablet.prototype.values = function() {
87101
return this._update();
88102
};

color.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,46 @@
22

33
var aseUtils = require('ase-utils');
44

5+
6+
/**
7+
* Color constant
8+
* @property {String}
9+
*/
510
var RED = "red";
11+
/**
12+
* Color constant
13+
* @property {String}
14+
*/
615
var GREEN = "green";
16+
/**
17+
* Color constant
18+
* @property {String}
19+
*/
720
var BLUE = "blue";
21+
/**
22+
* Color constant
23+
* @property {String}
24+
*/
825
var HUE = "hue";
26+
/**
27+
* Color constant
28+
* @property {String}
29+
*/
930
var SATURATION = "saturation";
31+
/**
32+
* Color constant
33+
* @property {String}
34+
*/
1035
var BRIGHTNESS = "brightness";
36+
/**
37+
* Color constant
38+
* @property {String}
39+
*/
1140
var GRAYSCALE = "grayscale";
41+
/**
42+
* Color constant
43+
* @property {String}
44+
*/
1245
var ALPHA = "alpha";
1346

1447

0 commit comments

Comments
 (0)