472,334 Members | 1,567 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 8714
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 thread has been closed and replies have been disabled. Please start a new discussion.

### Similar topics

 4 by: Brent W. Hughes | last post by: If the Turtle gets himself into a large (or infinite) loop, is there any way to stop him other than Ctrl-Alt-Del? Brent 4 by: Steven Feil | last post by: I am wondering if there is a light weight Python library for producing web graphics on-the-fly. There is a C-language library called gd that can be... 5 by: Markus Elfring | last post by: Hello, A lot of clipart libraries offer free raster images. I am looking for a similar collection for vector graphics. Do you know a gallery... 2 by: Matt Silberstein | last post by: I wanted to make a script to build a thumbnail library. So I went to cpan.org and find the various GD modules. So I run ppm3 (I am running on XP)... 3 by: Anton81 | last post by: Hi, I want to use globals that are immediately visible in all modules. My attempts to use "global" haven't worked. Suggestions? Anton 3 by: Harley | last post by: I am trying to build graphic charts in a vb.net module callable from another form. I have translated this code from VB6 where it worked well. I... 7 by: Dick Moores | last post by: I accidentally stumbled across the Turtle Graphics module (turtle.py) the other day and have been having some fun with it. Now I'm wondering if... 1 by: thatos | last post by: Which website can I go to get grahics.py module 1 by: evilcraft_mj | last post by: when i type from graphics import * error shown that there is no such module called graphics. help me find this...... 2 by: Gabriel | last post by: Hi all ! I'm developing a math program that shows graphics of functions. I would hear suggestions about the way of drawing 2D . Thanks a lot... 0 by: better678 | last post by: Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented... 0 by: teenabhardwaj | last post by: How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of... 0 by: CD Tom | last post by: This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins... 0 by: jalbright99669 | last post by: Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made... 0 by: Matthew3360 | last post by: Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ... 2 by: Matthew3360 | last post by: Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it... 0 by: AndyPSV | last post by: HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable... 0 by: Arjunsri | last post by: I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and... 0 by: WisdomUfot | last post by: It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...