13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>The</strong> Graphics Device Interfacehttp://www.zetcode.com/wxpython/gdi/angle = 0while (angle < 2*pi):x = radius*cos(angle)y = radius*sin(angle)dc.DrawLinePoint((0, 0), (x, y))angle = angle + 2*pi/360app = wx.App()Lines(None, -1, 'Lines')app.MainLoop()In this example we draw 260 lines from the middle of theclient area. <strong>The</strong> distance between two lines is 1 degree. Wecreate an interesting figure.import wxfrom math import hypot, sin, cos, piWe need three mathematical functions and one constant fromthe math module.dc.SetDeviceOrigin(size_x/2, size_y/2)<strong>The</strong> method SetDeviceOrigin() creates a new beginning of thecoordinate system. We place it into the middle of the clientarea. By repositioning the coordinate system, we make ourdrawing less complicated.radius = hypot(size_x/2, size_y/2)Here we get the Hypotenuse. It is the longest line, we candraw from the middle of the client area. It is the length of theline, that should be drawn from the beginning into the cornerof the window. This way most of the lines are not drawn fully.<strong>The</strong> overlapping parts are not visible. see Hypotenuse.x = radius*cos(angle)y = radius*sin(angle)<strong>The</strong>se are parametric functions. <strong>The</strong>y are used to find [x, y]points on the curve. All 360 lines are drawn from thebeginning of the coordinate system up to the points on thecircle.26 de 44 27/04/2008 1:08

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!