From ac703f1baaca3d2bdd7235d9c2847a2a6ea6ca2a Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Fri, 10 Jun 2011 00:07:25 +0200 Subject: [PATCH 01/10] Path: add example of pointToCurves(). --- src/path/Path.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/path/Path.js b/src/path/Path.js index 0c8daacb..2ec31702 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -693,6 +693,42 @@ var Path = this.Path = PathItem.extend({ this.setSegments(segments); }, + /** + * @param {Number} [tolerance=2.5] + * + * @example {@paperscript height=300} + * // Click and drag below to draw to draw a line, when you release the + * // mouse, the is made smooth using path.pointsToCurves(): + * + * var path; + * function onMouseDown(event) { + * // If we already made a path before, deselect it: + * if (path) { + * path.selected = false; + * } + * + * // Create a new path and add the position of the mouse + * // as its first segment. Select it, so we can see the + * // segment points: + * path = new Path(); + * path.strokeColor = 'black'; + * path.add(event.point); + * path.selected = true; + * } + * + * function onMouseDrag(event) { + * // On every drag event, add a segment to the path + * // at the position of the mouse: + * path.add(event.point); + * } + * + * function onMouseUp(event) { + * // When the mouse is released, simplify the path using + * // the pointsToCurves function: + * path.pointsToCurves(); + * path.selected = true; + * } + */ pointsToCurves: function(tolerance) { var fitter = new PathFitter(this, tolerance || 2.5); this.setSegments(fitter.fit()); From 87c1b564d292894c49256c9d12acb75f5d6aa9b8 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Fri, 10 Jun 2011 13:32:37 +0200 Subject: [PATCH 02/10] Document Path#lineBy(vector). --- src/path/Path.js | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/path/Path.js b/src/path/Path.js index 2ec31702..469ed58a 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -1825,9 +1825,52 @@ var Path = this.Path = PathItem.extend({ this._add(segments); }, - // DOCS: document Path#lineBy /** - * @param {Point} vector + * Adds a segment relative to the last segment point of the path. + * + * @param {Point} vector The vector which is added to the position + * of the last segment of the path, to become the new segment. + * + * @example {@paperscript} + * var path = new Path(); + * path.strokeColor = 'black'; + * + * // Add a segment at {x: 50, y: 50} + * path.add(25, 25); + * + * // Add a segment relative to the last segment of the path. + * // 50 in x direction and 0 in y direction, becomes {x: 75, y: 25} + * path.lineBy(50, 0); + * + * // 0 in x direction and 50 in y direction, becomes {x: 75, y: 75} + * path.lineBy(0, 50); + * + * @example {@paperscript height=300} + * // Drawing a spiral using lineBy: + * var path = new Path(); + * path.strokeColor = 'black'; + * + * // Add the first segment at {x: 50, y: 50} + * path.add(view.center); + * + * // Loop 500 times: + * for (var i = 0; i < 500; i++) { + * // Create a vector with an ever increasing length + * // and an angle in increments of 45 degrees + * var vector = new Point({ + * angle: i * 45, + * length: i / 2 + * }); + * // Add the vector relatively to the last segment point: + * path.lineBy(vector); + * } + * + * // Smooth the handles of the path: + * path.smooth(); + * + * // Uncomment the following line and click on 'run' to see + * // the construction of the path: + * // path.selected = true; */ lineBy: function(vector) { vector = Point.read(arguments); From 20fc389020584cc4b94908f3fbbdb369f1366072 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Fri, 10 Jun 2011 13:33:14 +0200 Subject: [PATCH 03/10] Documentation: add see tag to Path#closePath(). --- src/path/Path.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/path/Path.js b/src/path/Path.js index 469ed58a..cacc55ef 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -1907,6 +1907,8 @@ var Path = this.Path = PathItem.extend({ /** * Closes the path. When closed, Paper.js connects the first and last * segments. + * + * @see #closed */ closePath: function() { this.setClosed(true); From 344034cb62a2e3468a9472276b7387dca9b54b15 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Fri, 10 Jun 2011 13:34:20 +0200 Subject: [PATCH 04/10] Documentation: clean up Item#blendMode types. --- src/item/Item.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/item/Item.js b/src/item/Item.js index 26824787..4cae38fe 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -297,7 +297,10 @@ var Item = this.Item = Base.extend({ /** * The blend mode of the item. * - * @type String('normal', 'multiply', 'screen', 'overlay', 'soft-light', 'hard-light', 'color-dodge', 'color-burn', 'darken', 'lighten', 'difference', 'exclusion', 'hue', 'saturation', 'luminosity', 'color', 'add', 'subtract', 'average', 'pin-light', 'negation') + * @type String('normal', 'multiply', 'screen', 'overlay', 'soft-light', + * 'hard-light', 'color-dodge', 'color-burn', 'darken', 'lighten', + * 'difference', 'exclusion', 'hue', 'saturation', 'luminosity', 'color', + * 'add', 'subtract', 'average', 'pin-light', 'negation') * @default 'normal' * * @example {@paperscript} From 94fa73bf2f70093d539c980b1c427f0046813a3d Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Fri, 10 Jun 2011 13:34:58 +0200 Subject: [PATCH 05/10] Documentation: improve wording in Item#clone() example. --- src/item/Item.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/item/Item.js b/src/item/Item.js index 4cae38fe..c1f88ec8 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -594,7 +594,7 @@ var Item = this.Item = Base.extend({ * for (var i = 0; i < 20; i++) { * var copy = circle.clone(); * - * // Move the copies horizontally, so we can see them: + * // Distribute the copies horizontally, so we can see them: * copy.position.x += i * copy.bounds.width; * } */ From 7591ccf285ac42337e8d9fe7e90688fca2823492 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Fri, 10 Jun 2011 13:44:30 +0200 Subject: [PATCH 06/10] Improve Project#currentStyle documentation. --- src/project/Project.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/project/Project.js b/src/project/Project.js index 89e4bffd..c2b1256a 100644 --- a/src/project/Project.js +++ b/src/project/Project.js @@ -66,24 +66,24 @@ var Project = this.Project = Base.extend({ * @type PathStyle * @bean * - * @example + * @example {@paperscript} * project.currentStyle = { * fillColor: 'red', * strokeColor: 'black', * strokeWidth: 5 * } * - * // The following path will take over all style properties of + * // The following paths will take over all style properties of * // the current style: - * var path = new Path.Circle(new Point(50, 50), 30); - * console.log(path.strokeWidth); // 5 + * var path = new Path.Circle(new Point(75, 50), 30); + * var path2 = new Path.Circle(new Point(175, 50), 20); * - * @example + * @example {@paperscript} * project.currentStyle.fillColor = 'red'; * * // The following path will take over the fill color we just set: - * var path = new Path.Circle(new Point(50, 50), 30); - * console.log(path.fillColor); // RGBColor(1, 0, 0) + * var path = new Path.Circle(new Point(75, 50), 30); + * var path2 = new Path.Circle(new Point(175, 50), 20); */ getCurrentStyle: function() { return this._currentStyle; From a48a8d7a8d963406286c1a2b0f245de27a8e4b97 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Fri, 10 Jun 2011 14:05:58 +0200 Subject: [PATCH 07/10] Document TextItem#content. --- src/text/TextItem.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/text/TextItem.js b/src/text/TextItem.js index 7901fe6f..dabf0084 100644 --- a/src/text/TextItem.js +++ b/src/text/TextItem.js @@ -44,6 +44,31 @@ var TextItem = this.TextItem = Item.extend({ * * @name TextItem#content * @type String + * + * @example {@paperscript} + * // Setting the content of a PointText item: + * + * // Create a point-text item at {x: 30, y: 30}: + * var text = new PointText(new Point(30, 30)); + * text.fillColor = 'black'; + * + * // Set the content of the text item: + * text.content = 'Hello world'; + * + * @example {@paperscript} + * // Interactive example, move your mouse over the view below: + * + * // Create a point-text item at {x: 30, y: 30}: + * var text = new PointText(new Point(30, 30)); + * text.fillColor = 'black'; + * + * text.content = 'Move your mouse over the view, to see its position'; + * + * function onMouseMove(event) { + * // Each time the mouse is moved, set the content of + * // the point text to describe the position of the mouse: + * text.content = 'Your position is: ' + event.point.toString(); + * } */ _clone: function(copy) { From 68193d8a98f4ff9753ff1f05ff3b49cd40f5bdae Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Fri, 10 Jun 2011 14:12:33 +0200 Subject: [PATCH 08/10] Documentation: Add examples to RGBColor / GrayColor / HSBColor constructors. --- src/color/Color.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/color/Color.js b/src/color/Color.js index 36bfa3a1..2dbb6a2b 100644 --- a/src/color/Color.js +++ b/src/color/Color.js @@ -531,6 +531,16 @@ var GrayColor = this.GrayColor = Color.extend(/** @scope GrayColor */{ * * @class A GrayColor object is used to represent any gray color value. * @extends Color + * + * @example {@paperscript} + * // Creating a GrayColor: + * + * // Create a circle shaped path at {x: 80, y: 50} + * // with a radius of 30: + * var circle = new Path.Circle(new Point(80, 50), 30); + * + * // Create a GrayColor with 50% gray: + * circle.fillColor = new GrayColor(0.5); */ _colorType: 'gray' @@ -553,6 +563,16 @@ var RGBColor = this.RGBColor = Color.extend(/** @scope RGBColor */{ * * @class An RGBColor object is used to represent any RGB color value. * @extends Color + * + * @example {@paperscript} + * // Creating an RGBColor: + * + * // Create a circle shaped path at {x: 80, y: 50} + * // with a radius of 30: + * var circle = new Path.Circle(new Point(80, 50), 30); + * + * // 100% red, 0% blue, 50% blue: + * circle.fillColor = new RGBColor(1, 0, 0.5); */ _colorType: 'rgb' @@ -575,6 +595,17 @@ var HSBColor = this.HSBColor = Color.extend(/** @scope HSBColor */{ * * @class An HSBColor object is used to represent any HSB color value. * @extends Color + * + * @example {@paperscript} + * // Creating an HSBColor: + * + * // Create a circle shaped path at {x: 80, y: 50} + * // with a radius of 30: + * var circle = new Path.Circle(new Point(80, 50), 30); + * + * // Create an HSBColor with a hue of 90 degrees, a saturation + * // 100% and a brightness of 100%: + * circle.fillColor = new HSBColor(90, 1, 1); */ _colorType: 'hsb' From 9b1812f7d89c185541b6239bae4d32fd0fa9051e Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Fri, 10 Jun 2011 14:13:55 +0200 Subject: [PATCH 09/10] Documentation: fix type of View#bounds. --- src/ui/View.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ui/View.js b/src/ui/View.js index e8c4ad15..03db1b7a 100644 --- a/src/ui/View.js +++ b/src/ui/View.js @@ -146,7 +146,7 @@ var View = this.View = Base.extend({ }, /** - * @type Size + * @type Rectangle * @bean */ getBounds: function() { @@ -386,13 +386,13 @@ var View = this.View = Base.extend({ curPoint = point || curPoint; if (curPoint) tool.onHandleEvent('mousedrag', curPoint, event); - if (tool.onMouseDrag) + if (tool.onMouseDrag && !tool.onFrame) that.draw(); // PORT: If there is only an onMouseMove handler, also call it when // the user is dragging: } else if (!dragging || onlyMove) { tool.onHandleEvent('mousemove', point, event); - if (tool.onMouseMove) + if (tool.onMouseMove && !tool.onFrame) that.draw(); } } From d2c031aa4edb7b6aaa8d8fe1b41fc3d4c011886d Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Fri, 10 Jun 2011 14:21:27 +0200 Subject: [PATCH 10/10] Documentation: improve View#onFrame example. --- src/ui/View.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ui/View.js b/src/ui/View.js index 03db1b7a..d7793857 100644 --- a/src/ui/View.js +++ b/src/ui/View.js @@ -269,17 +269,17 @@ var View = this.View = Base.extend({ * {@code event.delta}: the time passed in seconds since the last frame * event. * - * @example + * @example {@paperscript} * // Creating an animation: * - * // Create a rectangle shaped path between {x: 20, y: 20} - * // and {x: 50, y: 50}: - * var path = new Path.Rectangle([20, 20], [50, 50]); + * // Create a rectangle shaped path with its top left point at: + * // {x: 50, y: 25} and a size of {width: 50, height: 50} + * var path = new Path.Rectangle(new Point(50, 25), new Size(50, 50)); * path.fillColor = 'black'; * * function onFrame(event) { - * // Every frame, rotate the path by 1 degree: - * path.rotate(1); + * // Every frame, rotate the path by 3 degrees: + * path.rotate(3); * } * * @type function