Conway's Life
Matthew Dixon Cowles
matt at mondoinfo.com
Thu Jul 19 21:47:25 EDT 2001
On Fri, 20 Jul 2001 01:10:56 GMT, Doug Newhouse <n at .com> wrote:
>I'm a recreational programmer with some pretty basic experience in
>Python and I'm looking for a good way to implement the grid needed
>for Life (or other cellular automata) in Python.
It's great that you've come to Python. I'd use Python lists for the
grid you want. Here's one way to pre-allocate a table:
>>> x=20
>>> y=10
>>> table=[]
>>> for count in range(y):
... table.append([None]*x)
...
>>> print table[0][0]
None
>>> table[0][0]=1
You may save yourself some confusion later if read this FAQ entry
about multidimensional lists.
http://www.python.org/doc/FAQ.html#4.50
>This would be in win98. I should be able to figure out the
>algorithms and stuff, it's just that I have no idea how to do
>graphics. (Would this be TK? Perhaps someone could recommend a web
>site or book?)
Tkinter is the default GUI. If it's important for your code to work
cross-platform, it's probably the best choice.
The best Tkinter documentation I know of is Fredrik Lundh's excellent
An Introduction to Tkinter. It's at:
http://www.pythonware.com/library/tkinter/introduction/index.htm
I've long since downloaded a copy so as to save Fredrik bandwidth.
For the kind of graphics you want, I suspect that the Canvas widget
would be a good place to start.
I think that ActiveState's Win32all module has bindings for the Win32
GUI. It's at (wrapped for line length):
http://aspn.activestate.com/ASPN/Downloads/
ActivePython/Extensions/Win32all
wxPython is another alternative. It's at:
http://wxpython.org/
>(I did this once in Turbo Pascal using ascii symbols and EGA screen
>settings on a VGA monitor, that's not ideal ;)
<grin> I think you may like Python a little better.
Regards,
Matt
More information about the Python-list
mailing list