Pages

Wednesday, 14 May 2014

Paper.js - The Swiss Army Knife of Vector Graphics Scripting

http://paperjs.org/


If you want to work with Paper.js, simply download the latest "stable" version from http://paperjs.org/download/

Installing Paper.js

You can download prebuilt packages from http://paperjs.org/download/.
As of July 2013, the recommended way to install and maintain Paper.js is through Bower for browsers, and through NPM for Node.js.
For OSX see http://madebyhoundstooth.com/blog/install-node-with-homebrew-on-os-x/ for a tutorial explaining how to install Node.js, NPM and Bower.
For Linux see http://nodejs.org/download/ to locate 32-bit and 64-bit nodejs binaries as well as sources. It is recommended that you download directly from the nodejs site; the version available via many OS-supplied package managers is out-of-date and doesn't work with many of the packages paper uses. NPM is now included with the nodejs distribution. Once nodejs (with npm) has been installed you can install bower using the following command:
npm install -g bower
With Bower installed, simply type this command in your project folder:
bower install paper
Upon execution, you will find a paper folder inside the project's bower_components folder. For more information on Bower and to learn about its features for dependence tracking, see http://bower.io/.

Which Version to Use?

The various distributions come with three different pre-build versions of Paper.js, in minified and normal variants:
  • paper-full.js – The full version for the browser, including PaperScript support and Acorn.js
  • paper-core.js – The core version for the browser, without PaperScript support nor Acorn.js. Use this to shave off some bytes when working with JavaScript directly.
  • paper-node.js – The version for Node.js. It is recommended to install this through NPM, see below.

Installing Paper.js for Node.js through NPM

You can also use NPM to install Paper.js for Node.js. But before doing so, you need the Cairo Graphics library installed, see http://cairographics.org/.
Installing Cairo on OSX:
The easiest way to install Cairo is install Homebrew http://mxcl.github.io/homebrew/ then issue the command:
brew install cairo
Note that currently there is an issue on OSX with Cairo. If the above causes errors, the following will most likely fix it:
PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ npm install paper
Also, whenever you would like to update the modules, you will need to execute:
PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ npm update
Installing Cairo on Debian/Ubuntu Linux:
sudo apt-get install libcairo2-dev
You might also need these additional packages if you don't usually build from c++ sources:
sudo apt-get install build-essential libssl-dev libjpeg8-dev libgif-dev
After Cairo has been installed:
You should now be able to install the Paper.js module from NPM:
npm install paper
 
from  https://github.com/paperjs/paper.js