Hi Joshua,

PyX does not do "proper PS/PDF gradients", i.e. shadings. (It's used
for mesh plotting, but not otherwise.)

PyX has its own flexible gradients in the color module - predefined
ones, and the possibility to define whatever you like. So far, they
can be only used as a decorator to a path. As a result the path is
split into N pieces (default: 20) which are colored with colors from
the gradient.

You can get gradients fills from that by stroking a "background path"
and clipping it to the shape you want. in fact, this is much more
flexible than the 7 predefined PDF shading types (linear, radial,
...). Just don't decorate a closed path with a gradient. I'll attach a
small example.

Cheers
Michael

Am Do., 13. Juni 2019 um 16:13 Uhr schrieb S Joshua Swamidass
<[email protected]>:
>
> Hello,
>
> I've been getting very good use out of PyX. I want to know how to do a 
> gradient fill and a gradient line, where the color along a path shifts from 
> one color to another, hopefully in a customizable way.
>
> S Joshua Swamidass
>
> _______________________________________________
> PyX-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pyx-user

Attachment: gradient.pdf
Description: Adobe PDF document

#!/usr/bin/python3
from pyx import *

c = canvas.canvas()

c.stroke(path.line(0, 0, 1, 1), [deco.colorgradient(color.gradient.RedGreen)])

#deco.colorgradient does not work with closed paths:
#c.stroke(path.rect(0, 0, 1, 1), [deco.colorgradient(color.gradient.RedGreen)])

c.stroke(path.path(path.moveto(1.5, 0), path.rlineto(1,0), path.rlineto(0,1), path.rlineto(-1, 0), path.rlineto(0, -1)), [deco.colorgradient(color.gradient.RedGreen)])


d = canvas.canvas([canvas.clip(path.rect(0, 0, 1, 1))])
d.stroke(path.line(0, 0, 1, 1), [deco.colorgradient(color.gradient.RedGreen, steps=100), style.linewidth(2)])

c.insert(d, [trafo.translate(0, -1.5)])

e = canvas.canvas([canvas.clip(path.circle(0.5, 0.5, 0.5))])
e.stroke(path.path(path.arc(0.5, 0, 1, 0, 180)), [deco.colorgradient(color.gradient.RedGreen, steps=100), style.linewidth(2)])

c.insert(e, [trafo.translate(1.5, -1.5)])

c.writePDFfile()
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user

Reply via email to