Andrea,

On 9/21/06, andrea valle <[EMAIL PROTECTED]> wrote:
> So, I try to make an example.
> I'm developing graphical musical notation.
> I need a finite set of symbols, each one having  its properties. eg. a
> red circle in a white rect represents something, a red circle alone
> represents something other, a blue cross a third thing, a little blue
> cross a fourth one and so on.

Sorry to butt in here, but I think that what you want is quite easy.
You don't really have to worry about the design of PyX - just wrap it
up so it has the design you want! Is the example below anything like
what you are after? Note that in my example a symbol has "fixed
properties", such as shape and fill color, that are set when the
symbol is first defined. These could be extended to include stroke
color, linewidth, etc. Then there are "temporary properties" - size,
position, angle, that can be different each time the symbol is
"painted"

Cheers

Will

##########################################################################
import pyx

class Shape:
    "Paths for simple shapes of unit size"
    circle = pyx.path.circle(0, 0, 0.5)
    square = pyx.path.rect(-0.5, -0.5, 1, 1)

class Color:
    black = pyx.color.rgb.black
    blue = pyx.color.rgb(0.1,0.2,0.8)
    pink = pyx.color.rgb(0.9,0.5,0.5)

class Symbol(pyx.canvas.canvas):
    "A symbol with properties"
    def __init__(self, fillcolor=Color.black, alpha=0.5,
                 path=Shape.circle):
        pyx.canvas.canvas.__init__(self)
        self.fill(path, [fillcolor, pyx.color.transparency(1.-alpha)])

    def paint(self, c, pos=(0, 0), size=1, angle=0):
        c.insert(self, [pyx.trafo.translate(*pos),
                        pyx.trafo.scale(size),
                        pyx.trafo.rotate(angle)])

picture = pyx.canvas.canvas()

bluecircle = Symbol(fillcolor=Color.blue)
pinksquare = Symbol(fillcolor=Color.pink, path=Shape.square)

bluecircle.paint(picture)
bluecircle.paint(picture, pos=(1, 1), size=2.5)
pinksquare.paint(picture, pos=(0, 1), size=1.5, angle=30)

picture.writePDFfile("paint")
##########################################################################


-- 

  Dr William Henney, Centro de Radioastronomía y Astrofísica,
  Universidad Nacional Autónoma de México, Campus Morelia

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
PyX-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-user

Reply via email to