From: Ben S. <be...@ni...> - 2000-04-05 04:45:16
|
Hello, My name is Ben Smith, I was attempting to write a SDL module for python as well. It was an uphill battle for me, I'm new to python, and I've still got a lot to learn about c, and trying to use the ExtensionClass for it. I found this module today and it rules! I added a small patch that allows you to manipulate the pixel buffer of an SDL surface in a 2d python array. here's a quick example: import sdl from whrandom import randint sdl.init(16) surface = sdl.video_set_mode(320,200,8,0) pixels = surface.get_pixels() print "generating random colors... this takes a while" for x in range (len(pixels)): for y in range (len(pixels[x])): pixels[x][y] = surface.map_rgb((randint(0,254), randint(0,254), randint(0,254))) surface.set_pixels(pixels) surface.update_rect((0,0,0,0)) import time time.sleep(20) It's not the fastest thing ever, but you get access to the pixel buffer pseudo-directly in python. The list of lists containing the pixel colors(pixels) is not destroyed in the call to set_pixels, because I thought it may be useful to keep around. I also didn't attach it to the surface object itself, because I thought it would move even more slowly if there were large arrays for every surface. It's also significantly faster without so many calls to randint and surface.map_rgb. =-=-=-=-=-=-=-= Linux - This will end your Windows session. be...@ni... |