[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-edu-sig
Subject:    [Edu-sig] Graphing using Zelle's graphics.py
From:       urnerk () qwest ! net (Kirby Urner)
Date:       2003-12-15 5:06:01
Message-ID: E1AVpby-0000kR-Tz () mail ! python ! org
[Download RAW message or body]



John Zelle's graphics.py makes it easy for students to do graphics using Tk
from within IDLE.  

Plus IDLE is making things somewhat easier these days, e.g. there's the
'restart shell' feature that clears out the memory without necessitating a
reboot of IDLE.

Suppose I wanted a quick sine and cosine graphs using graphics.py.  

Here's one way that might look:

 >>> from zelle.graphics import *
 >>> import math

 >>> def graph(f, domain, thewindow):
     """
     Take a function, domain and target window,
     Return a graph
     """
         for x1,x2 in zip(domain[:-1], domain[1:]):
		seg = Line(  Point(x1,f(x1)),  Point(x2,f(x2))  )
		seg.draw(thewindow)

 >>> win = GraphWin('Graph',600,600)
 >>> win.setBackground('Blue')
 >>> win.setCoords(-10,-2,10,2)
		
 >>> domain = [i/100. for i in range(-1000,1000)]

 >>> graph(math.cos ,domain, win)
 >>> graph(math.sin ,domain, win)

 >>> win.close()

The setCoords method is especially convenient, as it lets the user decide
what the coordinate system will be.

Kirby



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic