luni, 2 august 2010

Binary bitmate with pygame

Is a very simple example.
I use this code :

import pygame
from pygame.locals import *
import random
import Numeric
from math import *
import random
WIDTH = 640     #width of screen
HEIGHT = 480    #height of screen
def main():
    screen = pygame.display.set_mode((WIDTH,HEIGHT),DOUBLEBUF,32)
    pixels = pygame.surfarray.pixels3d(screen)
    width = len(pixels)-1
    height = len(pixels[0])-1
    for y in xrange(height):
        for x in xrange(width):
   if a==1 : b=(255,255,255)
   else : b=(0,0,0)
   pixels[x,y] = (b)
    done = False
    while not done:
        for e in pygame.event.get():
            if e.type == KEYDOWN:
                done = True
if __name__ == "__main__":
The most important is this line : 
pixels = pygame.surfarray.pixels3d(screen)
I use random function to select "0" or "1" and set the colors .
Next, I fill the screen by update the screen with new values of pixels : pygame.display.update()
See bellow the result :

Niciun comentariu:

Trimiteți un comentariu