## pyx-user

 [PyX-user] About the trafo.mirror and transparency From: kib2 - 2006-12-26 20:38:18 ```Hi, I've got two questions regarding PyX : In pyx.trafo.trafo, I don't understand how the mirror is implemented. As far as I know, to obtain a mirror at line passing through (0,0) with=20 the given angle "angle", the matrix should be like this:=20 ((math.cos(2*angle),math.sin(2*angle)),(math.sin(2*angle),-math.cos(2*ang= le))).=20 But it is given like this: ( (math.cos(phi)*math.cos(phi)-math.sin(phi)*math.sin(phi), -2*math.sin(phi)*math.cos(phi) ), (-2*math.sin(phi)*math.cos(phi), math.sin(phi)*math.sin(phi)-math.cos(phi)*math.cos(phi) ) ) There are problems with i.e a 135 degrees given angle. My other question is relative to the transparency in pdf output. The=20 documentation is rather limited on this, and I found no sample. How can I fill a given path with transparency and stroke it (without=20 transparency) at the same time ? Thanks, Kib=B2 ```
 Re: [PyX-user] About the trafo.mirror and transparency From: William Henney - 2006-12-27 03:32:52 ```Hi On 12/26/06, kib2 wrote: > In pyx.trafo.trafo, I don't understand how the mirror is implemented. > > As far as I know, to obtain a mirror at line passing through (0,0) with > the given angle "angle", the matrix should be like this: > ((math.cos(2*angle),math.sin(2*angle)),(math.sin(2*angle),-math.cos(2*ang= le))). > > > But it is given like this: > ( (math.cos(phi)*math.cos(phi)-math.sin(phi)*math.sin(phi), > -2*math.sin(phi)*math.cos(phi) ), > (-2*math.sin(phi)*math.cos(phi), > math.sin(phi)*math.sin(phi)-math.cos(phi)*math.cos(phi) ) ) > > There are problems with i.e a 135 degrees given angle. > But these are exactly the same, except for the sign of the angle (recall your high school trig identities!). Your matrix is correct for angles measured clockwise from the x-axis, but PyX is assuming that the angle is measured *anti*clockwise from the x-axis (which is the more common convention I think). On the other hand, I don't see why PyX has expanded out the double angle formulae - your version seems to have a lower operation count. > My other question is relative to the transparency in pdf output. The > documentation is rather limited on this, and I found no sample. > How can I fill a given path with transparency and stroke it (without > transparency) at the same time ? I don't think that you can do this with the built-in methods, but there is no reason why you can't roll your own. Something like this: ---------------------------------------------------------------- import pyx class mycanvas(pyx.canvas.canvas): "Just like pyx.canvas.canvas, but adds a strokefill method." def strokefill(self, path, strokeattrs=3D[], fillattrs=3D[], commonattr= s=3D[]): =09self.stroke(path, strokeattrs+commonattrs) =09self.fill(path, fillattrs+commonattrs) c =3D mycanvas() p =3D pyx.path.circle(0, 0, 1) translucent =3D pyx.color.transparency(0.7) blue =3D pyx.color.rgb(0.1, 0.2, 0.5) red =3D pyx.color.rgb(0.9, 0.4, 0.3) # blue solid stroke, red translucent fill c.strokefill(p, [blue], [red, translucent]) # red solid stroke, blue translucent fill, shifted c.strokefill(p, [red], [blue, translucent], [pyx.trafo.translate(0.5, 0.5)]= ) c.writePDFfile("strokefilltest") ---------------------------------------------------------------- Cheers Will --=20 Dr William Henney, Centro de Radioastronom=EDa y Astrof=EDsica, Universidad Nacional Aut=F3noma de M=E9xico, Campus Morelia ```
 Re: [PyX-user] About the trafo.mirror and transparency From: Andre Wobst - 2007-01-02 16:56:22 ```Hi, On 26.12.06, William Henney wrote: > > My other question is relative to the transparency in pdf output. The > > documentation is rather limited on this, and I found no sample. > > How can I fill a given path with transparency and stroke it (without > > transparency) at the same time ? > > I don't think that you can do this with the built-in methods, but > there is no reason why you can't roll your own. Something like this: > > ---------------------------------------------------------------- > import pyx > > class mycanvas(pyx.canvas.canvas): > "Just like pyx.canvas.canvas, but adds a strokefill method." > def strokefill(self, path, strokeattrs=[], fillattrs=[], commonattrs=[]): > self.stroke(path, strokeattrs+commonattrs) > self.fill(path, fillattrs+commonattrs) > > c = mycanvas() > p = pyx.path.circle(0, 0, 1) > translucent = pyx.color.transparency(0.7) > blue = pyx.color.rgb(0.1, 0.2, 0.5) > red = pyx.color.rgb(0.9, 0.4, 0.3) > > # blue solid stroke, red translucent fill > c.strokefill(p, [blue], [red, translucent]) > # red solid stroke, blue translucent fill, shifted > c.strokefill(p, [red], [blue, translucent], [pyx.trafo.translate(0.5, 0.5)]) > > c.writePDFfile("strokefilltest") > > ---------------------------------------------------------------- Well, usually you should use a combined stroke and fill operation. See http://pyx.sourceforge.net/examples/drawing/strokefill.html for some explanation. However, for transparency this does not work. It's due to the fact, that transparency needs to be set by an extended graphics state modification and this is done for stroke and fill operations at the same time (neglecting some strokeonly and fillonly settings in PyX's internal graphics stack). Clearly a bug. I'll fix it but I can't easily do that at the moment, since I have unreleased code in color.py and other area's and need to get into a clear state with my code base before addressing this issue. Anyway, thanks for reporting this bug ... André -- by _ _ _ Dr. André Wobst / \ \ / ) wobsta@..., http://www.wobsta.de/ / _ \ \/\/ / PyX - High quality PostScript and PDF figures (_/ \_)_/\_/ with Python & TeX: visit http://pyx.sourceforge.net/ ```