469,640 Members | 1,563 Online

# 2d graphics - what module to use?

What is the easiest way to draw to a window? I'd like to draw something
like sine waves from a mathematical equation.
Newbie to python.
Jul 25 '08 #1
8 8582
Use python's default GUI tkinter's drawing functions or you can use
wxPython GUI kit or you can use pyopengl.
If you are only interested to draw sin waves or math functions that
you should give try to matlab at www.mathworks.com

Jul 25 '08 #2
On 25 Lug, 08:13, Pierre Dagenais <pierre.dagen...@ncf.cawrote:
What is the easiest way to draw to a window? I'd like to draw something
* like sine waves from a mathematical equation.
Newbie to python.
What you are really asking for is what GUI library you should use;
every one allows you to draw freely. What do you need to do besides
drawing sine waves? You should look at your full range of options;
http://wiki.python.org/moin/GuiProgramming is a good starting point.

The "easiest" way to draw might be with those toolkits that offer
primarily a canvas to draw on rather than composable widgets. For
example, Pyglet (http://pyglet.org/) offers OpenGL contexts with
sensible defaults and unobtrusive automation:

from pyglet import *
from pyglet.gl import *
import math
win = window.Window(width=700, height=700, caption="sine wave demo",
resizable=True)
frequency,phase,amplitude=0.1,0.0,0.9
@win.event
def on_draw():
half_height=win.height*0.5
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(0.9, 1.0, 0.8)
glBegin(GL_LINE_STRIP)
for x in xrange(0,win.width):
y=half_height*(1.0+amplitude*math.sin(x*frequency+ phase))
glVertex2f(x,y)
glEnd()
app.run()

Regards,

Lorenzo Gatti
Jul 25 '08 #3
On Fri, Jul 25, 2008 at 2:13 AM, Pierre Dagenais <pi*************@ncf.cawrote:
What is the easiest way to draw to a window? I'd like to draw something
like sine waves from a mathematical equation.
Newbie to python.
--
http://mail.python.org/mailman/listinfo/python-list
I'd recommend matplotlib:

http://matplotlib.sourceforge.net/

http://wiki.python.org/moin/UsefulModules
Jul 25 '08 #4
Pierre Dagenais wrote:
What is the easiest way to draw to a window? I'd like to draw something
like sine waves from a mathematical equation.
Newbie to python.
--
http://mail.python.org/mailman/listinfo/python-list
For very simple things, the standard module turtle might be your best bet.

BB

Jul 25 '08 #5
On Jul 25, 8:13*am, Pierre Dagenais <pierre.dagen...@ncf.cawrote:
What is the easiest way to draw to a window? I'd like to draw something
* like sine waves from a mathematical equation.
Newbie to python.
For mathematica equations, NumPy and matplotlib is probably the best
option. I prefer to embed matplotlib in wxPython. wxAgg is an
excellent backend.

For more general 2D graphics, there are several options, including:

- pygame (uses SDL)
- aggdraw module
- pycairo
- pyopengl
- wxPython's device context (ditto for other GUI libraries)

Jul 25 '08 #6
sturlamolden wrote:
On Jul 25, 8:13 am, Pierre Dagenais <pierre.dagen...@ncf.cawrote:
>What is the easiest way to draw to a window? I'd like to draw something
like sine waves from a mathematical equation.
Newbie to python.

For mathematica equations, NumPy and matplotlib is probably the best
option. I prefer to embed matplotlib in wxPython. wxAgg is an
excellent backend.

For more general 2D graphics, there are several options, including:

- pygame (uses SDL)
- aggdraw module
- pycairo
- pyopengl
- wxPython's device context (ditto for other GUI libraries)

--
http://mail.python.org/mailman/listinfo/python-list
If you're using wx, there is also wx.lib.plot, which I found to be
_much_ faster than matplotlib in my application, especially when resizing.

-Matt
Jul 26 '08 #7
On Jul 25, 4:10*am, King <animator...@gmail.comwrote:
Use python's default GUI tkinter's drawing functions or you can use
wxPython GUI kit or you can use pyopengl.
If you are only interested to draw sin waves or math functions that
you should give try to matlab atwww.mathworks.com
If you're only interested in sine waves you most certainly should not
give Matlab a try; even with student pricing it's going to be way
expensive for something that simple.

For just popping up a window and drawing on it I recommend PyGame.
Carl Banks
Jul 26 '08 #8
On Jul 26, 6:47*am, Matthew Fitzgibbons <eles...@nienna.orgwrote:
If you're using wx, there is also wx.lib.plot, which I found to be
_much_ faster than matplotlib in my application, especially when resizing..
Yes. Matplotlib creates beautiful graphics, but are terribly slow on
large data sets.
Jul 26 '08 #9

### This discussion thread is closed

Replies have been disabled for this discussion.