File: PILNumeric.py

package info (click to toggle)
pyopengl 2.0.1.08-5.1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 19,484 kB
  • ctags: 9,036
  • sloc: pascal: 64,950; xml: 28,088; ansic: 20,696; python: 19,761; tcl: 668; makefile: 240; sh: 25
file content (44 lines) | stat: -rw-r--r-- 1,129 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# This is statement is required by the build system to query build info
if __name__ == '__build__':
	raise Exception

## This isn't really a PyOpenGL demo, but it's a nice
## example of how Numeric, Tkinter, and PIL can be used 
## together to create all sorts of images.
try:
    import Numeric
except:
    print "This demo requires the Numeric Extension, sorry."
    import sys
    sys.exit()
import FFT
import Tkinter
import Image
import ImageTk
import sys

w = 256
h = 256

    
def demo():
    data = Numeric.arrayrange(w*h)

##    fftdata = FFT.fft(data)
##    fftdata2 = FFT.fft(data2)
##    fftdata3 = (fftdata + fftdata2) / 2.
##    invfftdata = FFT.inverse_fft(fftdata3)
##    data = invfftdata.real
    data = data.astype('l')

    im = Image.new("RGBA", (w, h))
    print len(data.tostring("raw", "RGBX", 0, -1))
    print len(im.tostring("raw", "RGBX", 0, -1))
    im.fromstring(data.tostring("raw", "RGBX", 0, -1),"raw", "RGBX", 0, -1)

    root = Tkinter.Tk()
    image = ImageTk.PhotoImage(im)
    x = Tkinter.Label(root, image=image)
    x.pack()

    root.mainloop()