Speeding up Simple Canvas Loop

Michael P. Reilly arcege at shore.net
Mon May 10 10:41:46 EDT 1999


Randall Hopper <aa8vb at vislab.epa.gov> wrote:
: Michael P. Reilly:
:  |Randall Hopper <aa8vb at vislab.epa.gov> wrote:
:  |:     create_line = canvas.create_line
:  |:     for line in lines:
:  |:       create_line( line, width=0 )
:  |
:  |You can either use one call to create_line or use create_polygon.
:  |
:  |  # just get the first endpoint of each line
:  |  vertices = map(lambda a, b: a, lines)
:  |  # add the first vertex to the end to close the polygon
:  |  canvas.create_line( vertices + vertices[:1], width=0 )

: I don't understand this.  Correct me if I'm wrong, but this will simply
: draw one multi-segment line which connects all the first-points of the
: lines.

Correct.

: I believe it also assumes each line in "lines" is a 2-point line.  In fact,
: these lines each have a variable number of points (2 to hundreds) already.

No, each entry in the list is the starting vertex in the next segment of
the line.

:  |or
:  |  canvas.create_polygon( vertices, width=0 )

: These are distinct multi-point lines, so I can't just connect all the
: points together.

Sorry, I had misunderstood what you were trying to do.

  -Arcege





More information about the Python-list mailing list