Merge branch 'refs/heads/master' into v8-optimizations

Conflicts:
	src/core/Base.js
	src/style/Color.js
This commit is contained in:
Jürg Lehni 2014-01-05 05:01:13 +01:00
commit ea63d4c288
118 changed files with 498 additions and 462 deletions

View file

@ -1,6 +1,6 @@
## Authors
- Juerg Lehni <juerg@lehni.org>
- Juerg Lehni <juerg@scratchdisk.com>
- Jonathan Puckey <jonathan@studiomoniker.com>
## Contributors

View file

@ -1,5 +1,5 @@
Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
http://lehni.org/ & http://jonathanpuckey.com/
Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
http://scratchdisk.com/ & http://jonathanpuckey.com/
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy

View file

@ -14,7 +14,11 @@ 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.
See <http://madebyhoundstooth.com/blog/install-node-with-homebrew-on-os-x/> for a tutorial explaining how to install Node.js, NPM and Bower on OSX.
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:
@ -22,26 +26,38 @@ With Bower installed, simply type this command in your project folder:
Upon execution, you will find a `paper` folder inside the project's `component` folder. For more information on Bower and to learn about its features for dependence tracking, see <http://bower.io/>.
## Installing for Node.js
## Installing Paper.js for Node.js through NPM
Similarly you can use NPM to install Paper.js for Node.js. But before doing so, you need the Cairo Graphics library installed, see <http://cairographics.org/>.
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/>.
The easiest way to install Cairo on OSX is through Homebrew <http://mxcl.github.io/homebrew/>.
**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
Once Homebrew has installed this for you, you can then install the Paper.js module:
npm install paper
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
PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ npm insetall 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
**Ater Cairo has been installed:**
You should now be able to install the Paper.js module from NPM:
npm install paper
## Development
**Get the source (for building):**
@ -53,11 +69,12 @@ Also, whenever you would like to update the modules, you will need to execute:
If you want to contribute to the project you will have to [make a fork](http://help.github.com/forking/). Then do this:
git clone --recursive git@github.com:yourusername/paper.js.git
cd paper.js
git remote add upstream git://github.com/paperjs/paper.js.git
### Refreshing Your Clone
To fetch changes from origin, run
To fetch changes from origin (your fork), run
git fetch origin
@ -73,11 +90,15 @@ To update the `jsdoc-toolkit` submodule inside the `build` folder, used to gener
Paper.js has a couple of dependencies as Bower and NPM modules. See <http://madebyhoundstooth.com/blog/install-node-with-homebrew-on-os-x/> for a tutorial explaining how to install Node.js, NPM and Bower on OSX.
In order to be able to build Paper.js, these dependencies need to be installed first after checking out the repository:
In order to be able to build Paper.js, after checking out the repository, paper has dependencies that need to be installed. Install them by issuing the following commands from the paper.js directory:
npm install
bower install
You might find that the npm command fails attempting to fetch packages needed for dependencies due to using https (the default protocol to access the npm registry). If that is the case you can switch to using http for registry access with the following command:
npm config set registry http://registry.npmjs.org/
Next you need to create minified versions of some of these dependencies. This is handled by the `minify-components.sh` script inside the `build` folder:
cd build
@ -145,7 +166,8 @@ As mentioned earlier in this article, we prefer that you send a [*pull request*]
3. This is important: Create a so-called *topic branch*: `git checkout -tb name-of-my-patch` where "name-of-my-patch" is a short but descriptive name of the patch you're about to create. Don't worry about the perfect name though -- you can change this name at any time later on.
4. Hack! Make your changes, additions, etc and commit them.
4. Hack! Make your changes, additions, etc., commit them then push them to your github fork: `git push origin name-of-my-patch`
5. Send a pull request to the upstream repository's owner by visiting your repository's site at github (i.e. https://github.com/yourusername/paper.js) and press the "Pull Request" button. Here's a good guide on pull requests: <http://help.github.com/pull-requests/>

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/
#
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://scratchdisk.com/ & http://jonathanpuckey.com/
#
# Distributed under the MIT license. See LICENSE file for details.
#

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/
#
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://scratchdisk.com/ & http://jonathanpuckey.com/
#
# Distributed under the MIT license. See LICENSE file for details.
#

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/
#
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://scratchdisk.com/ & http://jonathanpuckey.com/
#
# Distributed under the MIT license. See LICENSE file for details.
#

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/
#
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://scratchdisk.com/ & http://jonathanpuckey.com/
#
# Distributed under the MIT license. See LICENSE file for details.
#

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/
#
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://scratchdisk.com/ & http://jonathanpuckey.com/
#
# Distributed under the MIT license. See LICENSE file for details.
#

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/
#
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://scratchdisk.com/ & http://jonathanpuckey.com/
#
# Distributed under the MIT license. See LICENSE file for details.
#

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/
#
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://scratchdisk.com/ & http://jonathanpuckey.com/
#
# Distributed under the MIT license. See LICENSE file for details.
#

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/
#
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://scratchdisk.com/ & http://jonathanpuckey.com/
#
# Distributed under the MIT license. See LICENSE file for details.
#

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/
#
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://scratchdisk.com/ & http://jonathanpuckey.com/
#
# Distributed under the MIT license. See LICENSE file for details.
#

View file

@ -3,8 +3,8 @@
# Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
# http://paperjs.org/
#
# Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
# http://lehni.org/ & http://jonathanpuckey.com/
# Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
# http://scratchdisk.com/ & http://jonathanpuckey.com/
#
# Distributed under the MIT license. See LICENSE file for details.
#

View file

@ -1,7 +1,7 @@
require('paper');
var paper = require('./Tadpoles.pjs');
var paper = require('paper');
var scope = require('./Tadpoles.pjs')(new paper.Size(1024, 768));
paper.view.exportFrames({
scope.view.exportFrames({
amount: 400,
directory: __dirname,
onComplete: function() {

View file

@ -1,5 +1,3 @@
paper.setup(new Canvas(1024, 768));
// Adapted from Flocking Processing example by Daniel Schiffman:
// http://processing.org/learning/topics/flocking.html

View file

@ -89,12 +89,11 @@
function onMouseDrag(event) {
if (segment) {
segment.point = event.point;
segment.point += event.delta;
path.smooth();
}
if (movePath)
} else if (path) {
path.position += event.delta;
}
}
</script>
</head>

5
node_modules/.gitignore generated vendored
View file

@ -1,7 +1,8 @@
.bin
canvas
grunt*
jsdoc
jsdom
prepro
request
uglify-js
prepro
grunt*

View file

@ -5,7 +5,7 @@
"homepage": "http://paperjs.org",
"repository": "git://github.com/paperjs/paper.js",
"contributors": [
"Jürg Lehni <juerg@lehni.org> (http://lehni.org)",
"Jürg Lehni <juerg@scratchdisk.com> (http://scratchdisk.com)",
"Jonathan Puckey <jonathan@studiomoniker.com> (http://studiomoniker.com)"
],
"main": "./dist/paper-node.js",
@ -26,7 +26,7 @@
},
"devDependencies": {
"uglify-js": "~2.3.6",
"prepro": "~0.8.0",
"prepro": "~0.8.1",
"grunt": "~0.4.1",
"grunt-contrib-uglify": "~0.2.2"
},

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
@ -15,8 +15,7 @@
* @class
* @private
*/
// Extend Base with utility functions used across the library. Also set
// this.Base on the injection scope, since straps.js ommits that.
// Extend Base with utility functions used across the library.
Base.inject(/** @lends Base# */{
/**
* Renders base objects to strings in object literal notation.
@ -40,7 +39,7 @@ Base.inject(/** @lends Base# */{
/**
* Serializes this object to a JSON string.
*
* @param {Object} [options={ precision: 5 }]
* @param {Object} [options={ asString: true, precision: 5 }]
*/
exportJSON: function(options) {
return Base.exportJSON(this, options);
@ -180,9 +179,6 @@ Base.inject(/** @lends Base# */{
obj = Base.create(this.prototype);
if (readIndex)
obj.__read = true;
// If options were provided, pass them on to the constructed object
if (options)
obj.__options = options;
obj = obj.initialize.apply(obj, index > 0 || length < list.length
? Array.prototype.slice.call(list, index, index + length)
: list) || obj;
@ -192,8 +188,6 @@ Base.inject(/** @lends Base# */{
// last read() call
list.__read = obj.__read;
obj.__read = undefined;
if (options)
obj.__options = undefined;
}
return obj;
},
@ -211,7 +205,7 @@ Base.inject(/** @lends Base# */{
/**
* Reads all readable arguments from the list, handling nested arrays
* seperately.
* separately.
* @param {Array} list the list to read from, either an arguments object
* or a normal array.
* @param {Number} start the index at which to start reading in the list
@ -433,7 +427,10 @@ Base.inject(/** @lends Base# */{
},
exportJSON: function(obj, options) {
return JSON.stringify(Base.serialize(obj, options));
var json = Base.serialize(obj, options);
return options && options.asString === false
? json
: JSON.stringify(json);
},
importJSON: function(json, target) {

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
@ -77,32 +77,16 @@ var Callback = {
if (!handlers)
return false;
var args = [].slice.call(arguments, 1),
PaperScript = paper.PaperScript,
handleException = PaperScript && PaperScript.handleException,
that = this;
function callHandlers() {
for (var i in handlers) {
// When the handler function returns false, prevent the default
// behaviour and stop propagation of the event by calling stop()
if (handlers[i].apply(that, args) === false
&& event && event.stop) {
event.stop();
break;
}
for (var i in handlers) {
// When the handler function returns false, prevent the default
// behaviour and stop propagation of the event by calling stop()
if (handlers[i].apply(that, args) === false
&& event && event.stop) {
event.stop();
break;
}
}
// See PaperScript.handleException for an explanation of the following.
// Firefox is to blame for the necessity of this...
if (handleException) {
try {
callHandlers();
} catch (e) {
handleException(e);
}
} else {
callHandlers();
}
return true;
},

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
@ -14,17 +14,12 @@
* @name PaperScript
* @namespace
*/
var PaperScript = Base.exports.PaperScript = (function(root) {
var PaperScript = Base.exports.PaperScript = (function() {
// Locally turn of exports and define for inlined acorn / esprima.
// Just declaring the local vars is enough, as they will be undefined.
var exports, define,
// The scope into which the library is loaded.
scope = this;
/*#*/ if (__options.version == 'dev') {
// As the above inclusion loads code into the root scope during dev,
// set scope to root, so we can find the library.
scope = root;
/*#*/ } // __options.version == 'dev'
/*#*/ if (__options.parser == 'acorn') {
/*#*/ include('../../bower_components/acorn/acorn.min.js', { exports: false });
/*#*/ } else if (__options.parser == 'esprima') {
@ -34,7 +29,7 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
// Operators to overload
var binaryOperators = {
// The hidden math functions are to be injected specifically, see below.
// The hidden math methods are to be injected specifically, see below.
'+': '__add',
'-': '__subtract',
'*': '__multiply',
@ -50,11 +45,11 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
'+': null
};
// Inject underscored math functions as aliases to Point, Size and Color.
// Inject underscored math methods as aliases to Point, Size and Color.
var fields = Base.each(
['add', 'subtract', 'multiply', 'divide', 'modulo', 'negate'],
function(name) {
// Create an alias for ach math function to be injected into the
// Create an alias for each math method to be injected into the
// classes using Straps.js' #inject()
this['__' + name] = '#' + name;
},
@ -109,13 +104,12 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
*/
function compile(code) {
// Use Acorn or Esprima to translate the code into an AST structure
// which is then walked and parsed for operators to overload.
// Instead of modifying the AST and converting back to code, we directly
// change the source code based on the parser's range information, so we
// can preserve line-numbers in syntax errors and remove the need for
// Escodegen.
// which is then walked and parsed for operators to overload. Instead of
// modifying the AST and translating it back to code, we directly change
// the source code based on the parser's range information, to preserve
// line-numbers in syntax errors and remove the need for Escodegen.
// Tracks code insertions so we can add their differences to the
// Track code insertions so their differences can be added to the
// original offsets.
var insertions = [];
@ -143,8 +137,8 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
// information up-to-date.
function replaceCode(node, str) {
var start = getOffset(node.range[0]),
end = getOffset(node.range[1]);
var insert = 0;
end = getOffset(node.range[1]),
insert = 0;
// Sort insertions by their offset, so getOffest() can do its thing
for (var i = insertions.length - 1; i >= 0; i--) {
if (start > insertions[i][0]) {
@ -245,7 +239,7 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
var view = scope.getView(),
// Only create a tool object if something resembling a tool handler
// definition is contained in the code.
tool = /\s+on(?:Key|Mouse)(?:Up|Down|Move|Drag)/.test(code)
tool = /\s+on(?:Key|Mouse)(?:Up|Down|Move|Drag)\b/.test(code)
? new Tool()
: null,
toolHandlers = tool ? tool._events : [],
@ -255,71 +249,69 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
// injecting a code line that defines them as variables.
// They are exported again at the end of the function.
handlers = ['onFrame', 'onResize'].concat(toolHandlers),
res;
// compile a list of paramter names for all variables that need to
// appear as globals inside the script. At the same time, also
// collect their values, so we can pass them on as arguments in the
// function call.
params = [],
args = [],
func;
code = compile(code);
// compile a list of paramter names for all variables that need to
// appear as globals inside the script. At the same time, also collect
// their values, so we can pass them on as arguments in the function
// call.
var params = ['_$_', '$_', 'view', 'tool'],
args = [_$_, $_ , view, tool];
// Look through all enumerable properties on the scope and expose these
// too as pseudo-globals.
for (var key in scope) {
if (!/^_/.test(key)) {
params.push(key);
args.push(scope[key]);
function expose(scope, hidden) {
// Look through all enumerable properties on the scope and expose
// these too as pseudo-globals, but only if they seem to be in use.
for (var key in scope) {
if ((hidden || !/^_/.test(key)) && new RegExp(
'\\b' + key.replace(/\$/g, '\\$') + '\\b').test(code)) {
params.push(key);
args.push(scope[key]);
}
}
}
expose({ _$_: _$_, $_: $_, view: view, tool: tool }, true);
expose(scope);
// Finally define the handler variable names as parameters and compose
// the string describing the properties for the returned object at the
// end of the code execution, so we can retrieve their values from the
// function call.
handlers = Base.each(handlers, function(key) {
params.push(key);
this.push(key + ': ' + key);
// Check for each handler explicitely and only return them if they
// seem to exist.
if (new RegExp('\\s+' + key + '\\b').test(code)) {
params.push(key);
this.push(key + ': ' + key);
}
}, []).join(', ');
// We need an additional line that returns the handlers in one object.
code += '\nreturn { ' + handlers + ' };';
if (handlers)
code += '\nreturn { ' + handlers + ' };';
/*#*/ if (__options.environment == 'browser') {
if (root.InstallTrigger) { // Firefox
// Add a semi-colon at the start so Firefox doesn't swallow empty
// lines and shift error messages.
code = ';' + code;
// On Firefox, all error numbers inside evaled code are relative to
// the line where the eval happened. Totally silly, but that's how
// it is. So we're calculating the base of lineNumbers, to remove it
// again from reported errors. Luckily, Firefox is the only browser
// where we can define the lineNumber for exceptions.
var handle = PaperScript.handleException;
if (!handle) {
handle = PaperScript.handleException = function(e) {
throw e.lineNumber >= lineNumber
? new Error(e.message, e.fileName,
e.lineNumber - lineNumber)
: e;
};
// We're using a crazy hack to detect wether the library is
// minified or not: By generating a second error on the 2nd line
// and using the difference in line numbers to calculate the
// offset to the eval, it works in both casees.
var lineNumber = new Error().lineNumber;
lineNumber += (new Error().lineNumber - lineNumber) * 3;
}
try {
res = new Function(params, code).apply(scope, args);
// NOTE: in order for the calculation of the above lineNumber
// offset to work, we cannot add any statements before the above
// line of code, nor can we put it into a separate function.
} catch (e) {
handle(e);
}
if (window.InstallTrigger || window.chrome) { // Firefox and Chrome
// On Firefox, all error numbers inside dynamically compiled code
// are relative to the line where the eval / compilation happened.
// To fix this issue, we're temporarily inserting a new script
// tag. We also use this on Chrome to fix an issue with compiled
// functions:
// https://code.google.com/p/chromium/issues/detail?id=331655
var script = document.createElement('script'),
head = document.head;
// Do not add a new-line before the code on Chrome since the error
// messages are shifted by one line there...
if (!window.chrome)
code = '\n' + code;
script.appendChild(document.createTextNode(
'paper._execute = function(' + params + ') {' + code + '\n}'
));
head.appendChild(script);
func = paper._execute;
head.removeChild(script);
} else {
res = new Function(params, code).apply(scope, args);
func = Function(params, code);
}
/*#*/ } else { // !__options.environment == 'browser'
res = new Function(params, code).apply(scope, args);
func = Function(params, code);
/*#*/ } // !__options.environment == 'browser'
var res = func.apply(scope, args) || {};
// Now install the 'global' tool and view handlers, and we're done!
Base.each(toolHandlers, function(key) {
var value = res[key];
@ -404,15 +396,21 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
path = require('path');
require.extensions['.pjs'] = function(module, uri) {
var source = compile(fs.readFileSync(uri, 'utf8')),
scope = new PaperScope();
scope.__filename = uri;
scope.__dirname = path.dirname(uri);
// Expose core methods and values
scope.require = require;
scope.console = console;
execute(source, scope);
module.exports = scope;
// Requiring a PaperScript on Node.js returns an initialize method which
// needs to receive a Canvas object when called and returns the
// PaperScope.
module.exports = function(canvas) {
var source = compile(fs.readFileSync(uri, 'utf8')),
scope = new PaperScope();
scope.setup(canvas);
scope.__filename = uri;
scope.__dirname = path.dirname(uri);
// Expose core methods and values
scope.require = require;
scope.console = console;
execute(source, scope);
return scope;
};
};
/*#*/ } // __options.environment == 'node'
@ -423,4 +421,6 @@ var PaperScript = Base.exports.PaperScript = (function(root) {
};
/*#*/ } // !__options.environment == 'browser'
})(this);
// Pass on `this` as the binding object, so we can reference Acorn both in
// development and in the built library.
}).call(this);

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
@ -46,7 +46,7 @@ var DomElement = new function() {
return res;
}
return {
return /** @lends DomElement */{
create: function(nodes, parent) {
var isArray = Array.isArray(nodes),
res = create(isArray ? nodes : arguments, isArray ? parent : null);

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
@ -15,7 +15,7 @@
* @namespace
* @private
*/
var DomEvent = {
var DomEvent = /** @lends DomEvent */{
add: function(el, events) {
for (var type in events)
el.addEventListener(type, events[type], false);

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
@ -1804,12 +1804,15 @@ var Item = Base.extend(Callback, /** @lends Item# */{
* data string.
*
* The options object offers control over some aspects of the SVG export:
* <b>options.asString:</b> {@code Boolean} wether the JSON is returned as
* a {@code Object} or a {@code String}.
* <b>options.precision:</b> {@code Number} the amount of fractional
* digits in numbers used in JSON data.
*
* @name Item#exportJSON
* @function
* @param {Object} [options={ precision: 5 }] the serialization options
* @param {Object} [options={ asString: true, precision: 5 }] the
* serialization options
* @return {String} the exported JSON data
*/
@ -1836,8 +1839,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{
* Exports the item with its content and child items as an SVG DOM.
*
* The options object offers control over some aspects of the SVG export:
* <b>options.asString:</b> {@code Boolean} wether a SVG node or a String
* is to be returned.
* <b>options.asString:</b> {@code Boolean} wether a SVG node or a
* {@code String} is to be returned.
* <b>options.precision:</b> {@code Number} the amount of fractional
* digits in numbers used in SVG data.
* <b>options.matchShapes:</b> {@code Boolean} wether imported path
@ -2718,6 +2721,9 @@ var Item = Base.extend(Callback, /** @lends Item# */{
// 'children', 'fill-gradients', 'fill-patterns', 'stroke-patterns',
// 'lines'. Default: ['objects', 'children']
transform: function(matrix /*, applyMatrix */) {
// Bail out immediatelly if there is nothing to do
if (matrix.isIdentity())
return this;
// Calling _changed will clear _bounds and _position, but depending
// on matrix we can calculate and set them again.
var bounds = this._bounds,

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js v*#=* __options.version - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
@ -13,16 +13,16 @@
*
***
*
* straps.js - Class inheritance library with support for bean-style accessors
* Straps.js - Class inheritance library with support for bean-style accessors
*
* Copyright (c) 2006 - 2013 Juerg Lehni
* http://lehni.org/
* http://scratchdisk.com/
*
* Distributed under the MIT license.
*
***
*
* acorn.js
* Acorn.js
* http://marijnhaverbeke.nl/acorn/
*
* Acorn is a tiny, fast JavaScript parser written in JavaScript,

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
@ -555,7 +555,7 @@ statics: {
},
getParameterOf: function(v, x, y) {
// Handle beginnings and end seperately, as they are not detected
// Handle beginnings and end separately, as they are not detected
// sometimes.
var tolerance = /*#=*/ Numerical.TOLERANCE;
if (Math.abs(v[0] - x) < tolerance && Math.abs(v[1] - y) < tolerance)
@ -674,7 +674,7 @@ statics: {
c = v1 - v0,
count = Numerical.solveQuadratic(a, b, c, roots),
// Add some tolerance for good roots, as t = 0 / 1 are added
// seperately anyhow, and we don't want joins to be added with
// separately anyhow, and we don't want joins to be added with
// radiuses in getStrokeBounds()
tMin = /*#=*/ Numerical.TOLERANCE,
tMax = 1 - tMin;
@ -1090,12 +1090,13 @@ new function() { // Scope for methods that require numerical integration
b = 1;
var isZero = Numerical.isZero;
// See if the curve is linear by checking p1 == c1 and p2 == c2
if (isZero(v[0] - v[2]) && isZero(v[1] - v[3])
if (a === 0 && b === 1
&& isZero(v[0] - v[2]) && isZero(v[1] - v[3])
&& isZero(v[6] - v[4]) && isZero(v[7] - v[5])) {
// Straight line
var dx = v[6] - v[0], // p2x - p1x
dy = v[7] - v[1]; // p2y - p1y
return (b - a) * Math.sqrt(dx * dx + dy * dy);
return Math.sqrt(dx * dx + dy * dy);
}
var ds = getLengthIntegrand(v);
return Numerical.integrate(ds, a, b, getIterations(a, b));

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
@ -15,6 +15,11 @@
// from "Graphics Gems", Academic Press, 1990
// Modifications and optimisations of original algorithm by Juerg Lehni.
/**
* @name PathFitter
* @class
* @private
*/
var PathFitter = Base.extend({
initialize: function(path, error) {
this.points = [];

View file

@ -2,14 +2,19 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
/**
* @name PathFlattener
* @class
* @private
*/
var PathFlattener = Base.extend({
initialize: function(path) {
this.curves = []; // The curve values as returned by getValues()

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
@ -335,12 +335,15 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
* a JSON data string.
*
* The options object offers control over some aspects of the SVG export:
* <b>options.asString:</b> {@code Boolean} wether the JSON is returned as
* a {@code Object} or a {@code String}.
* <b>options.precision:</b> {@code Number} the amount of fractional
* digits in numbers used in JSON data.
*
* @name Project#exportJSON
* @function
* @param {Object} [options={ precision: 5 }] the serialization options
* @param {Object} [options={ asString: true, precision: 5 }] the
* serialization options
* @return {String} the exported JSON data
*/
@ -364,8 +367,8 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{
* all contained in one top level SVG group node.
*
* The options object offers control over some aspects of the SVG export:
* <b>options.asString:</b> {@code Boolean} wether a SVG node or a String
* is to be returned.
* <b>options.asString:</b> {@code Boolean} wether a SVG node or a
* {@code String} is to be returned.
* <b>options.precision:</b> {@code Number} the amount of fractional
* digits in numbers used in SVG data.
* <b>options.matchShapes:</b> {@code Boolean} wether imported path

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
@ -247,23 +247,20 @@ var Color = Base.extend(new function() {
}
return value;
}
: name === 'hue'
? function(value) {
// Keep negative values within modulo 360 too:
return isNaN(value) ? 0
: ((value % 360) + 360) % 360;
: type === 'gradient'
? function(/* value */) {
return Point.read(arguments, 0, 0, {
readNull: name === 'highlight',
clone: true
});
}
: type === 'gradient'
? function(/* value */) {
return Point.read(arguments, 0, 0, {
readNull: name === 'highlight',
clone: true
});
}
: function(value) {
return isNaN(value) ? 0
: Math.min(Math.max(value, 0), 1);
};
: function(value) {
// NOTE: We don't clamp values here, they're only
// clamped once the actual CSS values are produced.
// Gotta love the fact that isNaN(null) is false,
// while isNaN(undefined) is true.
return value == null || isNaN(value) ? 0 : value;
};
this['get' + part] = function() {
return this._type === type
@ -401,7 +398,7 @@ var Color = Base.extend(new function() {
* // the path and to position the gradient color:
* var topLeft = view.center - [80, 80];
* var bottomRight = view.center + [80, 80];
*
*
* var path = new Path.Rectangle({
* topLeft: topLeft,
* bottomRight: bottomRight,
@ -489,7 +486,6 @@ var Color = Base.extend(new function() {
var slice = Array.prototype.slice,
args = arguments,
read = 0,
parse = true,
type,
components,
alpha,
@ -520,8 +516,6 @@ var Color = Base.extend(new function() {
}
}
if (!components) {
// Only parse values if we're not told to not do so
parse = !(this.__options && this.__options.dontParse);
// Determine if there is a values array
values = argType === 'number'
? args
@ -586,7 +580,7 @@ var Color = Base.extend(new function() {
: 'rgb';
// Convert to array and parse in one loop, for efficiency
var properties = types[type];
parsers = parse && componentParsers[type];
parsers = componentParsers[type];
this._components = components = [];
for (var i = 0, l = properties.length; i < l; i++) {
var value = arg[properties[i]];
@ -600,8 +594,7 @@ var Color = Base.extend(new function() {
radial: arg.radial
};
}
if (parse)
value = parsers[i].call(this, value);
value = parsers[i].call(this, value);
if (value != null)
components[i] = value;
}
@ -623,9 +616,7 @@ var Color = Base.extend(new function() {
this._components = components = [];
var parsers = componentParsers[this._type];
for (var i = 0, l = parsers.length; i < l; i++) {
var value = values && values[i];
if (parse)
value = parsers[i].call(this, value);
var value = parsers[i].call(this, values && values[i]);
if (value != null)
components[i] = value;
}
@ -656,6 +647,24 @@ var Color = Base.extend(new function() {
this._owner._changed(/*#=*/ Change.STYLE);
},
/**
* Returns a copy of the components array with all values clamped to
* valid numbers, based on the type of property they represent.
*/
_clamp: function() {
var components = this._components.slice(),
properties = this._properties;
if (this._type !== 'gradient') {
for (var i = 0, l = properties.length; i < l; i++) {
var value = components[i];
components[i] = properties[i] === 'hue'
? ((value % 360) + 360) % 360
: value < 0 ? 0 : value > 1 ? 1 : value;
}
}
return components;
},
/**
* @return {Number[]} the converted components as an array
*/
@ -664,11 +673,11 @@ var Color = Base.extend(new function() {
return this._type === type
? this._components.slice()
: (converter = converters[this._type + '-' + type])
? converter.apply(this, this._components)
? converter.apply(this, this._clamp())
// Convert to and from rgb if no direct converter exists
: converters['rgb-' + type].apply(this,
converters[this._type + '-rgb'].apply(this,
this._components));
this._clamp()));
},
/**
@ -776,6 +785,7 @@ var Color = Base.extend(new function() {
/**
* @name Color#clone
* @function
*
* Returns a copy of the color object.
*
@ -815,13 +825,16 @@ var Color = Base.extend(new function() {
// TODO: Support HSL / HSLA CSS3 colors directly, without conversion
var components = this._convert('rgb'),
alpha = hex || this._alpha == null ? 1 : this._alpha;
function convert(val) {
return Math.round((val < 0 ? 0 : val > 1 ? 1 : val) * 255);
}
components = [
Math.round(components[0] * 255),
Math.round(components[1] * 255),
Math.round(components[2] * 255)
convert(components[0]),
convert(components[1]),
convert(components[2])
];
if (alpha < 1)
components.push(alpha);
components.push(val < 0 ? 0 : val);
return hex
? '#' + ((1 << 24) + (components[0] << 16)
+ (components[1] << 8)
@ -1119,48 +1132,33 @@ var Color = Base.extend(new function() {
}
});
}, new function() {
function clamp(value, hue) {
return value < 0
? 0
: hue && value > 360
? 360
: !hue && value > 1
? 1
: value;
}
var operators = {
add: function(a, b, hue) {
return clamp(a + b, hue);
add: function(a, b) {
return a + b;
},
subtract: function(a, b, hue) {
return clamp(a - b, hue);
subtract: function(a, b) {
return a - b;
},
multiply: function(a, b, hue) {
return clamp(a * b, hue);
multiply: function(a, b) {
return a * b;
},
divide: function(a, b, hue) {
return clamp(a / b, hue);
divide: function(a, b) {
return a / b;
}
};
return Base.each(operators, function(operator, name) {
// Tell the argument reader not to parse values for multiply and divide,
// so the are not clamped yet.
var options = { dontParse: /^(multiply|divide)$/.test(name) };
this[name] = function(/* color */) {
var color = Color.read(arguments, 0, 0, options);
this[name] = function(color) {
color = Color.read(arguments, 0, 0);
var type = this._type,
properties = this._properties,
components1 = this._components,
components2 = color._convert(type);
for (var i = 0, l = components1.length; i < l; i++)
components2[i] = operator(components1[i], components2[i],
properties[i] === 'hue');
components2[i] = operator(components1[i], components2[i]);
return new Color(type, components2,
this._alpha != null
? operator(this._alpha, color.getAlpha())

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
@ -55,24 +55,25 @@ new function() {
attrs[center ? 'cy' : 'y'] = point.y;
trans = null;
}
if (matrix.isIdentity())
return attrs;
// See if we can decompose the matrix and can formulate it as a simple
// translate/scale/rotate command sequence.
var decomposed = matrix.decompose();
if (decomposed && !decomposed.shearing) {
var parts = [],
angle = decomposed.rotation,
scale = decomposed.scaling;
if (trans && !trans.isZero())
parts.push('translate(' + formatter.point(trans) + ')');
if (angle)
parts.push('rotate(' + formatter.number(angle) + ')');
if (!Numerical.isZero(scale.x - 1) || !Numerical.isZero(scale.y - 1))
parts.push('scale(' + formatter.point(scale) +')');
attrs.transform = parts.join(' ');
} else {
attrs.transform = 'matrix(' + matrix.getValues().join(',') + ')';
if (!matrix.isIdentity()) {
// See if we can decompose the matrix and can formulate it as a
// simple translate/scale/rotate command sequence.
var decomposed = matrix.decompose();
if (decomposed && !decomposed.shearing) {
var parts = [],
angle = decomposed.rotation,
scale = decomposed.scaling;
if (trans && !trans.isZero())
parts.push('translate(' + formatter.point(trans) + ')');
if (angle)
parts.push('rotate(' + formatter.number(angle) + ')');
if (!Numerical.isZero(scale.x - 1)
|| !Numerical.isZero(scale.y - 1))
parts.push('scale(' + formatter.point(scale) +')');
attrs.transform = parts.join(' ');
} else {
attrs.transform = 'matrix(' + matrix.getValues().join(',') + ')';
}
}
return attrs;
}

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
@ -143,7 +143,7 @@ var CanvasView = View.extend(/** @lends CanvasView# */{
return false;
}
return {
return /** @lends CanvasView# */{
/**
* Returns true if event was stopped, false otherwise, whether handler
* was called or not!

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
@ -706,8 +706,7 @@ var View = Base.extend(Callback, /** @lends View# */{
}
if (view) {
var point = viewToProject(view, event);
if (dragging || new Rectangle(new Point(),
view.getViewSize()).contains(point))
if (dragging || view.getBounds().contains(point))
tool = handleMouseMove(view, point, event);
}
}

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
@ -12,9 +12,10 @@
/**
* @name Formatter
* @class
* @private
*/
var Formatter = Base.extend({
var Formatter = Base.extend(/** @lends Formatter# */{
/**
* @param {Number} [precision=5] the amount of fractional digits.
*/

View file

@ -2,14 +2,19 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
/**
* @name Numerical
* @namespace
* @private
*/
var Numerical = new function() {
// Lookup tables for abscissas and weights with values for n = 2 .. 16.
@ -75,7 +80,7 @@ var Numerical = new function() {
};
}
return {
return /** @lends Numerical */{
TOLERANCE: TOLERANCE,
// Precision when comparing against 0
EPSILON: EPSILON,
@ -114,13 +119,13 @@ var Numerical = new function() {
findRoot: function(f, df, x, a, b, n, tolerance) {
for (var i = 0; i < n; i++) {
var fx = f(x),
dx = fx / df(x);
// Calculate a new candidate with the Newton-Raphson method.
dx = fx / df(x),
nx = x - dx;
// See if we can trust the Newton-Raphson result. If not we use
// bisection to find another candiate for Newton's method.
if (abs(dx) < tolerance)
return x;
// Generate a candidate for Newton's method.
var nx = x - dx;
return nx;
// Update the root-bounding interval and test for containment of
// the candidate. If candidate is outside the root-bounding
// interval, use bisection instead.
@ -135,6 +140,9 @@ var Numerical = new function() {
x = nx >= b ? 0.5 * (a + b) : nx;
}
}
// Return the best result even though we haven't gotten close
// enough to the root... (In paper.js this never seems to happen).
return x;
},
/**

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
@ -51,6 +51,14 @@ test('Set color to array', function() {
});
test('Creating Colors', function() {
compareColors(new Color(), new Color(0, 0, 0),
'Color with no arguments should be black');
compareColors(new Color('black'), new Color(0, 0, 0),
'Color from name (black)');
compareColors(new Color('red'), new Color(1, 0, 0),
'Color from name (red)');
compareColors(new Color('#ff0000'), new Color(1, 0, 0),
'Color from hex code');
@ -203,7 +211,7 @@ test('Saturation from black rgb', function() {
test('Color#add', function() {
var color = new Color(0, 1, 1);
compareColors(color.add([1, 0, 0]), [1, 1, 1]);
compareColors(color.add([1, 0.5, 0]), [1, 1, 1]);
compareColors(color.add([1, 0.5, 0]), [1, 1.5, 1]);
var color = new Color(0, 0.5, 0);
compareColors(color.add(0.5), [0.5, 1, 0.5]);
});
@ -229,7 +237,7 @@ test('Color#divide', function() {
var color = new Color(1, 1, 1);
compareColors(color.divide([1, 2, 4]), [1, 0.5, 0.25]);
var color = new Color(1, 0.5, 0.25);
compareColors(color.divide(0.25), [1, 1, 1]);
compareColors(color.divide(0.25), [4, 2, 1]);
var color = new Color(1, 1, 1);
compareColors(color.divide(4), [0.25, 0.25, 0.25]);
});

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

View file

@ -2,8 +2,8 @@
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
* Copyright (c) 2011 - 2014, Juerg Lehni & Jonathan Puckey
* http://scratchdisk.com/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*

Some files were not shown because too many files have changed in this diff Show more