## [PyX-checkins] SF.net SVN: pyx: [2727] trunk/pyx/examples/drawing2

 [PyX-checkins] SF.net SVN: pyx: [2727] trunk/pyx/examples/drawing2 From: - 2006-05-19 10:35:56 ```Revision: 2727 Author: m-schindler Date: 2006-05-19 03:35:42 -0700 (Fri, 19 May 2006) ViewCVS: http://svn.sourceforge.net/pyx/?rev=2727&view=rev Log Message: ----------- added a canvas insertion example Modified Paths: -------------- trunk/pyx/examples/drawing2/INDEX Added Paths: ----------- trunk/pyx/examples/drawing2/insert.py trunk/pyx/examples/drawing2/insert.txt Modified: trunk/pyx/examples/drawing2/INDEX =================================================================== --- trunk/pyx/examples/drawing2/INDEX 2006-05-19 09:27:41 UTC (rev 2726) +++ trunk/pyx/examples/drawing2/INDEX 2006-05-19 10:35:42 UTC (rev 2727) @@ -1,4 +1,5 @@ ellipse +insert smoothed parallel clipping Added: trunk/pyx/examples/drawing2/insert.py =================================================================== --- trunk/pyx/examples/drawing2/insert.py (rev 0) +++ trunk/pyx/examples/drawing2/insert.py 2006-05-19 10:35:42 UTC (rev 2727) @@ -0,0 +1,14 @@ +from math import sin, cos, radians +from pyx import * + +angle = 10 +factor = 1.0 / (cos(radians(angle)) + sin(radians(angle))) + +cc = canvas.canvas() +cc.stroke(path.rect(-2, -2, 4, 4)) + +c = canvas.canvas() +for i in range(10): + c.insert(cc, [trafo.rotate(i*angle), trafo.scale(factor**i)]) +c.writeEPSfile("insert") +c.writePDFfile("insert") Added: trunk/pyx/examples/drawing2/insert.txt =================================================================== --- trunk/pyx/examples/drawing2/insert.txt (rev 0) +++ trunk/pyx/examples/drawing2/insert.txt 2006-05-19 10:35:42 UTC (rev 2727) @@ -0,0 +1,16 @@ +Inserting transformed canvases into canvases + +Similar to the drawing of paths onto canvases, it is also possible to insert +one canvas into another. You may specify additional transformations which are +applied to the canvas which is inserted. ... + +The example code shows how a canvas `cc` containing a square can be inserted +several times into another canvas `c`. The applied transformation first rotates +the square around the origin and then performs a scaling. Note that not only +the size of the square gets scaled, but everything that is drawn on the canvas, +also the linewidth of the square. + +In geometrical operations, it is often necessary to perform calculations. This +is conveniently done by importing the mathematics capability of Python. In the +example, we calculate the scaling factor from the rotation angle such that the +corners of the rotated smaller square reside on the sides of the larger square. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```

 [PyX-checkins] SF.net SVN: pyx: [2713] trunk/pyx/examples/drawing2 From: - 2006-05-18 10:16:42 ```Revision: 2713 Author: m-schindler Date: 2006-05-18 03:16:30 -0700 (Thu, 18 May 2006) ViewCVS: http://svn.sourceforge.net/pyx/?rev=2713&view=rev Log Message: ----------- added a clipping example Modified Paths: -------------- trunk/pyx/examples/drawing2/INDEX Added Paths: ----------- trunk/pyx/examples/drawing2/clipping.py trunk/pyx/examples/drawing2/clipping.txt Modified: trunk/pyx/examples/drawing2/INDEX =================================================================== --- trunk/pyx/examples/drawing2/INDEX 2006-05-18 09:23:35 UTC (rev 2712) +++ trunk/pyx/examples/drawing2/INDEX 2006-05-18 10:16:30 UTC (rev 2713) @@ -1,2 +1,3 @@ smoothed parallel +clipping Added: trunk/pyx/examples/drawing2/clipping.py =================================================================== --- trunk/pyx/examples/drawing2/clipping.py (rev 0) +++ trunk/pyx/examples/drawing2/clipping.py 2006-05-18 10:16:30 UTC (rev 2713) @@ -0,0 +1,15 @@ +from pyx import * + +clippath = path.circle(0, 0, 1) +drawpath = path.line(-2, -2, 1.2, 2) + +cl = canvas.canvas([canvas.clip(clippath), color.rgb.red]) +cl.stroke(drawpath, [style.linewidth(1.0)]) + +c = canvas.canvas() +c.stroke(drawpath, [style.linewidth(1.0)]) +c.insert(cl) +c.stroke(clippath) + +c.writeEPSfile("clipping") +c.writePDFfile("clipping") Added: trunk/pyx/examples/drawing2/clipping.txt =================================================================== --- trunk/pyx/examples/drawing2/clipping.txt (rev 0) +++ trunk/pyx/examples/drawing2/clipping.txt 2006-05-18 10:16:30 UTC (rev 2713) @@ -0,0 +1,13 @@ +Clipping a canvas + +This example shows how drawing on a canvas can be clipped to a predefined +region. The thick line is drawn two times, first in black onto an ordinary +canvas, the second time in red onto a canvas which is clipped to the indicated +circle. ... + +The clipping property of a canvas must be specified on creation with an +instance of `canvas.clip`, which takes a path as an argument. + +! The clipped canvas `cl` is additionally equipped with the argument +`color.rgb.red`, which is then the default color of the canvas. If no other +color ist specified while drawing, all drawing is performed with this color. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [PyX-checkins] SF.net SVN: pyx: [2723] trunk/pyx/examples/drawing2 From: - 2006-05-18 20:42:57 ```Revision: 2723 Author: joergl Date: 2006-05-18 13:42:52 -0700 (Thu, 18 May 2006) ViewCVS: http://svn.sourceforge.net/pyx/?rev=2723&view=rev Log Message: ----------- remove deprecated passing of styles to canvas constructor Modified Paths: -------------- trunk/pyx/examples/drawing2/clipping.py trunk/pyx/examples/drawing2/clipping.txt Modified: trunk/pyx/examples/drawing2/clipping.py =================================================================== --- trunk/pyx/examples/drawing2/clipping.py 2006-05-18 20:40:07 UTC (rev 2722) +++ trunk/pyx/examples/drawing2/clipping.py 2006-05-18 20:42:52 UTC (rev 2723) @@ -3,8 +3,8 @@ clippath = path.circle(0, 0, 1) drawpath = path.line(-2, -2, 1.2, 2) -cl = canvas.canvas([canvas.clip(clippath), color.rgb.red]) -cl.stroke(drawpath, [style.linewidth(1.0)]) +cl = canvas.canvas([canvas.clip(clippath)]) +cl.stroke(drawpath, [color.rgb.red, style.linewidth(1.0)]) c = canvas.canvas() c.stroke(drawpath, [style.linewidth(1.0)]) Modified: trunk/pyx/examples/drawing2/clipping.txt =================================================================== --- trunk/pyx/examples/drawing2/clipping.txt 2006-05-18 20:40:07 UTC (rev 2722) +++ trunk/pyx/examples/drawing2/clipping.txt 2006-05-18 20:42:52 UTC (rev 2723) @@ -7,7 +7,3 @@ The clipping property of a canvas must be specified on creation with an instance of `canvas.clip`, which takes a path as an argument. - -! The clipped canvas `cl` is additionally equipped with the argument -`color.rgb.red`, which is then the default color of the canvas. If no other -color ist specified while drawing, all drawing is performed with this color. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [PyX-checkins] SF.net SVN: pyx: [2726] trunk/pyx/examples/drawing2 From: - 2006-05-19 09:27:48 ```Revision: 2726 Author: m-schindler Date: 2006-05-19 02:27:41 -0700 (Fri, 19 May 2006) ViewCVS: http://svn.sourceforge.net/pyx/?rev=2726&view=rev Log Message: ----------- added more detailed descriptions Modified Paths: -------------- trunk/pyx/examples/drawing2/parallel.txt trunk/pyx/examples/drawing2/smoothed.txt Modified: trunk/pyx/examples/drawing2/parallel.txt =================================================================== --- trunk/pyx/examples/drawing2/parallel.txt 2006-05-19 08:39:02 UTC (rev 2725) +++ trunk/pyx/examples/drawing2/parallel.txt 2006-05-19 09:27:41 UTC (rev 2726) @@ -3,11 +3,27 @@ This example shows how to use the `deformer.parallel` class. It provides the path which has always constant (signed) distance to an original path. ... +The correct geometrical solution to the "constant distance" problem is that a +corner of the original curve gets surrounded by an arc. As an alternative, you +can make the deformer deviate from the strict geometrical interpretation with +the argument + + `sharpoutercorners=1` + +The resulting parallel path will then exhibit corners with the same angle as +the original path does. + +!! The parallel deformer tries to find the parallel path which consists of as +few path elements as possible. This is a striking feature of the parallel +deformer, resulting in small EPS and PDF files, as well as in paths which can +be processed further in PyX. In the example, the parallel curves for the curved +right part of the original path consists of a single B\xE9zier curve only. + ! Note that the order of the deformer attributes is not arbitrary, since the deforming operations do not commute. If you want first to smooth and then get the parallel curve to the smoothed curve, you have to say - [deformer.smoothed(radius), deformer.parallel(dist)] + [deformer.smoothed(radius), deformer.parallel(dist)] since the stroke attributes are evaluated from left to right. Modified: trunk/pyx/examples/drawing2/smoothed.txt =================================================================== --- trunk/pyx/examples/drawing2/smoothed.txt 2006-05-19 08:39:02 UTC (rev 2725) +++ trunk/pyx/examples/drawing2/smoothed.txt 2006-05-19 09:27:41 UTC (rev 2726) @@ -3,11 +3,17 @@ This example shows how to use the `deformer` class. A deformer takes an original path and return a modified one, which is here a smoothed variant. The deformer can be used like any other attribute when stroking or filling a path. -... -In the example code, the original curve comprises a straight line and a curve, -exhibiting a sharp corner in between. This sharp corner is smoothed away. +Here, we show the use of `deformer.smoothed`, which smoothes away corners in +the original path. ... It operates on the pathelements of the original path and +cuts out pieces of a given length (`1.0` in the example) surrounding a corner +and replaces them by a smooth curve. This new curve is determined to be +''geometrical smooth'', exhibiting the same tangents and curvatures as the +original path at the connection points. Alltogether, the smoothing is performed +not in a strictly ''geometrical'' sense but also depends on the +parameterization of the path. If you try to smooth a path consisting of many +short path elements, nothing will really change. -! The deformed path can be accessed directly from the deformer by +! In all deformers, the deformed path can be accessed directly by - ps = deformer.smoothed(1.0).deform(p) + ps = deformer.smoothed(1.0).deform(p) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [PyX-checkins] SF.net SVN: pyx: [2727] trunk/pyx/examples/drawing2 From: - 2006-05-19 10:35:56 ```Revision: 2727 Author: m-schindler Date: 2006-05-19 03:35:42 -0700 (Fri, 19 May 2006) ViewCVS: http://svn.sourceforge.net/pyx/?rev=2727&view=rev Log Message: ----------- added a canvas insertion example Modified Paths: -------------- trunk/pyx/examples/drawing2/INDEX Added Paths: ----------- trunk/pyx/examples/drawing2/insert.py trunk/pyx/examples/drawing2/insert.txt Modified: trunk/pyx/examples/drawing2/INDEX =================================================================== --- trunk/pyx/examples/drawing2/INDEX 2006-05-19 09:27:41 UTC (rev 2726) +++ trunk/pyx/examples/drawing2/INDEX 2006-05-19 10:35:42 UTC (rev 2727) @@ -1,4 +1,5 @@ ellipse +insert smoothed parallel clipping Added: trunk/pyx/examples/drawing2/insert.py =================================================================== --- trunk/pyx/examples/drawing2/insert.py (rev 0) +++ trunk/pyx/examples/drawing2/insert.py 2006-05-19 10:35:42 UTC (rev 2727) @@ -0,0 +1,14 @@ +from math import sin, cos, radians +from pyx import * + +angle = 10 +factor = 1.0 / (cos(radians(angle)) + sin(radians(angle))) + +cc = canvas.canvas() +cc.stroke(path.rect(-2, -2, 4, 4)) + +c = canvas.canvas() +for i in range(10): + c.insert(cc, [trafo.rotate(i*angle), trafo.scale(factor**i)]) +c.writeEPSfile("insert") +c.writePDFfile("insert") Added: trunk/pyx/examples/drawing2/insert.txt =================================================================== --- trunk/pyx/examples/drawing2/insert.txt (rev 0) +++ trunk/pyx/examples/drawing2/insert.txt 2006-05-19 10:35:42 UTC (rev 2727) @@ -0,0 +1,16 @@ +Inserting transformed canvases into canvases + +Similar to the drawing of paths onto canvases, it is also possible to insert +one canvas into another. You may specify additional transformations which are +applied to the canvas which is inserted. ... + +The example code shows how a canvas `cc` containing a square can be inserted +several times into another canvas `c`. The applied transformation first rotates +the square around the origin and then performs a scaling. Note that not only +the size of the square gets scaled, but everything that is drawn on the canvas, +also the linewidth of the square. + +In geometrical operations, it is often necessary to perform calculations. This +is conveniently done by importing the mathematics capability of Python. In the +example, we calculate the scaling factor from the rotation angle such that the +corners of the rotated smaller square reside on the sides of the larger square. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [PyX-checkins] SF.net SVN: pyx: [2728] trunk/pyx/examples/drawing2 From: - 2006-05-19 11:10:52 ```Revision: 2728 Author: joergl Date: 2006-05-19 04:10:41 -0700 (Fri, 19 May 2006) ViewCVS: http://svn.sourceforge.net/pyx/?rev=2728&view=rev Log Message: ----------- show difference between trafo as deformer and as canvas trafo Modified Paths: -------------- trunk/pyx/examples/drawing2/ellipse.py trunk/pyx/examples/drawing2/ellipse.txt Modified: trunk/pyx/examples/drawing2/ellipse.py =================================================================== --- trunk/pyx/examples/drawing2/ellipse.py 2006-05-19 10:35:42 UTC (rev 2727) +++ trunk/pyx/examples/drawing2/ellipse.py 2006-05-19 11:10:41 UTC (rev 2728) @@ -1,8 +1,16 @@ from pyx import * c = canvas.canvas() -c.stroke(path.circle(0, 0, 1), [trafo.scale(sx=2, sy=1.5), - trafo.rotate(45), - trafo.translate(1, 0)]) +circ = path.circle(0, 0, 1) + +# variant 1: use trafo as a deformer +c.stroke(circ, [style.linewidth.THIck, + trafo.scale(sx=2, sy=0.9), trafo.rotate(45), trafo.translate(1, 0)]) + +# variant 2: transform a subcanvas +sc = canvas.canvas() +sc.stroke(circ, [style.linewidth.THIck]) +c.insert(sc, [trafo.scale(sx=2, sy=0.9), trafo.rotate(45), trafo.translate(5, 0)]) + c.writeEPSfile("ellipse") c.writePDFfile("ellipse") Modified: trunk/pyx/examples/drawing2/ellipse.txt =================================================================== --- trunk/pyx/examples/drawing2/ellipse.txt 2006-05-19 10:35:42 UTC (rev 2727) +++ trunk/pyx/examples/drawing2/ellipse.txt 2006-05-19 11:10:41 UTC (rev 2728) @@ -1,35 +1,52 @@ -Applying transformations when drawing a path: Creating an ellipse +Applying transformations on a path or canvas: Drawing an ellipse PyX does not directly provide a path corresponding to an ellipse. This example -shows how to draw an ellipse using affine transformations. ... +shows two ways how to draw an ellipse using affine transformations. ... In order to create an ellipse, we best start from a unit circle centered around -the point of origin of the coordinate system. When stroking this circle on the -canvas, we tell PyX to apply a couple of affine transformations first. These -affine transformations are contained in the `trafo` module. We first use -`trafo.scale` to apply a non-uniform scaling, namely by a factor of 2 in -x-direction and a factor of 1.5 in y-direction. Doing so, we define the two -principle axes of the ellipse. In a next step, we rotate with `trafo.rotate` -the ellipse by an angle of 45 degrees in the mathematical positive direction, -i.e. counter-clockwise. Last, we shift the origin of the ellipse to the desired -point by applying a `trafo.translate` operation. +the point of origin of the coordinate system (here: `circ`). In variant 1, we +tell PyX to apply a couple of affine transformations before stroking this +circle on the canvas `c`. These affine transformations are contained in the +`trafo` module. We first use `trafo.scale` to apply a non-uniform scaling, +namely by a factor of 2 in x-direction and a factor of 0.9 in y-direction. +Doing so, we define the two principle axes of the ellipse. In a next step, we +rotate with `trafo.rotate` the ellipse by an angle of 45 degrees in the +mathematical positive direction, i.e. counter-clockwise. Last, we shift the +origin of the ellipse to the desired point by applying a `trafo.translate` +operation. ! Note that the order of the transformations matters. If you, for instance, would first translate the ellipse, the later scaling would also affect the distance by which you have shifted the ellipse. PyX applies the transformations one after the other, from left to right, so the example shown above does the correct thing. -! You can also treat transformations as mathematical objects (they -are represented by two-dimensional matrices together with an offset vector) and -multiply them using the `*` operator. Note, however, that mathematically, transformations -are applied from right to left, such that the above example would need to be written as +! You can also treat transformations as mathematical objects (they are +represented by two-dimensional matrices together with an offset vector) and +multiply them using the `*` operator. Note, however, that mathematically, +transformations are applied from right to left, such that variant 1 +would need to be written as - c.stroke(path.circle(0, 0, 1), [trafo.translate(1,0) * trafo.rotate(45) * trafo.scale(sx=2, sy=1.5)]) + c.stroke(circ, [trafo.translate(1,0) * trafo.rotate(45) * trafo.scale(sx=2, sy=1.5)]) ! PyX also provides some convenience methods for applying certain -transformations with a given point as the origin. These allow one to write the -example in yet another form +transformations with a given point as the origin. These allow one to write variant 1 +in yet another form - c.stroke(path.circle(1, 0, 1), [trafo.scale(sx=2, sy=1.5, x=1, y=0), trafo.rotate(45, x=1, y=0)]) + c.stroke(circ, [trafo.scale(sx=2, sy=1.5, x=1, y=0), trafo.rotate(45, x=1, y=0)]) where we have started already from a circle centered around the desired point 1,0. + +When telling the stroke method to apply a number of transformations, we use +that a transformation is a so-called deformer. Deformers take an original path, +do some operation on it and return the modified version. PyX thus internally +converts the circle into a path representing the ellipse. Alternatively, we can +also let the PostScript or PDF interpreter do the same transformation. This is what +is shown in variant 2. There, we first stroke the circle on a new canvas `sc`. +When inserting this canvas in the original canvas `c`, we again pass a set of +transformations as arguments. Since PyX cannot deform an entire canvas, it just +writes these transformations into the output file. If you compare the resulting +output (the right ellipse) with the one of variant 1, you will notice a +difference, though: when transforming a whole canvas, the lineshape is +transformed as well. Often, this is not the intended result, so you better +transform individual objects when stroking or filling them. + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [PyX-checkins] SF.net SVN: pyx: [2764] trunk/pyx/examples/drawing2 From: - 2006-05-22 08:38:31 ```Revision: 2764 Author: joergl Date: 2006-05-22 01:38:26 -0700 (Mon, 22 May 2006) ViewCVS: http://svn.sourceforge.net/pyx/?rev=2764&view=rev Log Message: ----------- mark parameters as Python code Modified Paths: -------------- trunk/pyx/examples/bargraphs/compare.txt trunk/pyx/examples/drawing2/ellipse.py Modified: trunk/pyx/examples/bargraphs/compare.txt =================================================================== --- trunk/pyx/examples/bargraphs/compare.txt 2006-05-22 08:36:58 UTC (rev 2763) +++ trunk/pyx/examples/bargraphs/compare.txt 2006-05-22 08:38:26 UTC (rev 2764) @@ -29,8 +29,8 @@ will be shown on another subaxis. !! A nested bar axis is totally equivalent to a regular bar axis except for its -default value for the defaultsubaxis parameter in the constructor. While this -defaultsubaxis parameter is a special instance of a linear axis for the bar +default value for the `defaultsubaxis` parameter in the constructor. While this +`defaultsubaxis` parameter is a special instance of a linear axis for the bar axis, for a nestedbar axis its a special instance of another bar axis. The nesting of bar axes is not limited to a single level: You can nest bar axes into each other to any level you want. Providing explicit subaxes for certain Modified: trunk/pyx/examples/drawing2/ellipse.py =================================================================== --- trunk/pyx/examples/drawing2/ellipse.py 2006-05-22 08:36:58 UTC (rev 2763) +++ trunk/pyx/examples/drawing2/ellipse.py 2006-05-22 08:38:26 UTC (rev 2764) @@ -4,13 +4,14 @@ circ = path.circle(0, 0, 1) # variant 1: use trafo as a deformer -c.stroke(circ, [style.linewidth.THIck, - trafo.scale(sx=2, sy=0.9), trafo.rotate(45), trafo.translate(1, 0)]) +#c.stroke(circ, [style.linewidth.THIck, +# trafo.scale(sx=2, sy=0.9), trafo.rotate(45), trafo.translate(1, 0)]) # variant 2: transform a subcanvas sc = canvas.canvas() sc.stroke(circ, [style.linewidth.THIck]) -c.insert(sc, [trafo.scale(sx=2, sy=0.9), trafo.rotate(45), trafo.translate(5, 0)]) +# c.insert(sc, [trafo.scale(sx=2, sy=0.9), trafo.rotate(45), trafo.translate(5, 0)]) +c.insert(sc, [trafo.translate(5, 0), trafo.rotate(90)]) c.writeEPSfile("ellipse") c.writePDFfile("ellipse") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```