[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] gsoc: pygamedraw - status update



Hello,

I'd like to give you a short status report of the pygamedraw gsoc project.
I've implemented the main class structure and basic drawing methods, so its already usable:

# ...
red = pygame2.Color(200, 0, 0)
blue = pygame2.Color(0, 0, 200)
my_pen = SolidPen(color=red)
my_pen.width = 6
rect1 = pygame2.Rect(20, 60, 200, 150)
my_pen.width = 1
my_pen.ellipse(screen, rect1)
rect2 = pygame2.Rect(30, 20, 50, 80)
my_pen.ellipse(screen, rect2, start=30, stop=250)
my_pen.color = blue
my_pen.fill = True
my_pen.cirlce(screen, (150, 170), 60, stop=90)
my_pen.fill = False
points = [(20, 50),  (60, 10),  (70, 80)]
my_pen.line(screen, points, closed=True)
# ...

This should be mostly self-explanatory.
In comparison to the current draw module(s) you will notice
that it is object oriented!

Draw functions on module level are replaced by draw methods
on class level. This is the main change that brings along some
advantages and changes:

1.) possibility of inheritance
This is a great new feature that allows it to manipulate the way
of drawing without touching any shape algorithms. These are
implemented in the Pen base class and work on a mask as
intermediate. This mask is then passed to the Pen.render() method
that does some preparation and then calls the Pen.draw() method
that implements the actual drawing. So you just need to subclass
Pen and overwrite one method (namely Pen.draw()) and have a
completely new drawing behavior for all shapes.
Of course there will be some default Pens that already implement
the most common drawing methods. There are some screen shots
of already implemented Pens at my blog:
http://pygamedraw.wordpress.com/2010/06/02/from-mask-to-surface/
If you have any ideas for further Pen classes please tell me.

2.) shorter parameter lists
Having a Pen object allows it to store general parameters as class
attributes, so drawing methods take only a minimum of parameters.
However, I plan to add a way to set these class attributes on method
class, so if you don't like to write my_pen.width=1/2/... all the time,
you could set it directly on method call (like with the current pygame.draw
module): my_pen.rect(surf, rect, width=2).

 3.) cleaner code
I think this makes the code cleaner, more structured and more pythonic.

A more complex example is included with the sourcecode:
http://bitbucket.org/schlangen/pygamedraw/get/2c2c8b815137.zip
or
hg clone http://bitbucket.org/schlangen/pygamedraw


Regards,
Julian