[Tutor] Creating functions with Ming (original) (raw)

Alex Newby alex at alexnewby.com
Tue Jul 6 21:21:18 CEST 2004


I've been toying with Ming with intent to make language skill-building exercises on the web. Currently, I've been translating the Astral Trespassers example in O'Reilly's "Perl Graphics Programming" Chapter 9 freebie for Ming.

All went well until I encountered the following function:

sub drawRect { my shape = shift; my ($w, h,h, h,dx, $dy) = @_; shape−>movePen(shape->movePen(shape>movePen(dx, $dy) shape−>drawLine(shape->drawLine(shape>drawLine(w, 0) shape−>drawLine(0,shape->drawLine(0, shape>drawLine(0,h) shape−>drawLine(−shape->drawLine(-shape>drawLine(w, 0) shape−>drawLine(0,−shape->drawLine(0, -shape>drawLine(0,h) }

I have little idea how to approximate this in Python. The Perl rendition is essentially procedural. Whereas, the Python version I've slapped together isn't so much.

This is the essential snippet:

from ming import *

def drawRect(self, w, h, x, y): movePenTo(x, y) drawLineTo(w, 0) drawLineTo(0, h) drawLineTo(-w, 0) drawLineTo(0, -h)

s = SWFShape() s.setLeftFill(s.addFill(255, 0, 0)) s.drawRect(10, 10, -5, 0) s.drawRect(40, 10, -20, 10)

I am aware that my function doesn't really do anything.

This is a snippet from ming.py:

class SWFShape(SWFBase):

def movePenTo(self, x, y):
    mingc.SWFShape_movePenTo(self.this, x, y)

def drawLineTo(self, x, y):
    mingc.SWFShape_drawLineTo(self.this, x, y)

#Coincidentally, there is also a function called drawRect.
#I thought to sub-class and received critical errors.

def drawRect(self, rect):
    mingc.SWFShape_drawRect(self.this, rect.this);

If I don't sub-class I hear about drawFoo not being an attribute of SWFShape. Any suggestions on what may be happening here.

Sincerely,

Alex Newby E-mail: alex at alexnewby.com Website: http://www.alexnewby.com



More information about the Tutor mailing list