|
1 | | -generative-design-library.js |
2 | | -============================= |
| 1 | +# generative-design-library.js |
3 | 2 |
|
4 | 3 | [p5.js](https://p5js.org/) library for the book [Generative Design](http://www.generative-gestaltung.de/) |
5 | 4 |
|
6 | | -Developer Setup |
7 | | ---------------- |
8 | | -Download [node.js](https://nodejs.org/) or install it via [Homebrew](https://brew.sh/) (macOS only): |
| 5 | +## Install |
9 | 6 |
|
10 | | -``` |
11 | | -$ brew install node |
12 | | -``` |
| 7 | + npm install generative-design-library.js |
13 | 8 |
|
14 | | -Node monitor watching on file changes: |
| 9 | +## API |
15 | 10 |
|
16 | | -``` |
17 | | -$ npm run watch |
18 | | -``` |
| 11 | +<!-- Generated by documentation.js. Update this documentation by updating the source code. --> |
19 | 12 |
|
20 | | -Create a new bundle: |
| 13 | +### timestamp |
21 | 14 |
|
22 | | -``` |
23 | | -$ npm run dist |
24 | | -``` |
| 15 | +Returns neatly formated timestamp e.g. "151025_172441_790" |
25 | 16 |
|
26 | | -Acknowledgements |
27 | | ----------------- |
| 17 | +Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** formated timestamp |
28 | 18 |
|
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/) |
0 commit comments