easiest way to plot x,y graphically during run-time?
Peter Pearson
ppearson at nowhere.invalid
Thu Jun 4 19:24:46 EDT 2009
On Thu, 04 Jun 2009 03:29:42 -0500, Nick Craig-Wood wrote:
[snip]
> Here is a demo with pygame...
[snip]
And just for completeness, here is a demo with PyGUI, written
in similar style. (I'm a PyGUI newbie, so constructive criticism
would be appreciated.)
from GUI import Window, View, application, Color, Task
from random import randrange
class Brownian( View ):
def __init__( self, **kwargs ):
View.__init__( self, **kwargs )
width, height = self.size
self.dots = [ (randrange(width), randrange(height))
for _ in range( 100 ) ]
def step( self ):
self.dots = [ (dot[0]+randrange(-1,2), dot[1]+randrange(-1,2))
for dot in self.dots ]
self.invalidate()
def draw( self, canvas, rectangle ):
canvas.set_backcolor( Color( 0, 0, 0 ) )
canvas.set_forecolor( Color( 0.3, 0.85, 0.25 ) )
radius = 10
canvas.erase_rect( rectangle )
for dot in self.dots:
canvas.stroke_oval( ( dot[0]-radius, dot[1]-radius,
dot[0]+radius, dot[1]+radius ) )
def main():
size = 640, 480
win = Window( size = size, title = "A test of PyGUI" )
b = Brownian( size = size )
win.add( b )
win.show()
t = Task( b.step, interval = 0.02, repeat = True, start = True )
application().run()
if __name__ == "__main__":
main()
--
To email me, substitute nowhere->spamcop, invalid->net.
More information about the Python-list
mailing list