Please include the below as an example of how to use the rgb array
call.

Note that it uses the gdk_rgb_init() call I sent a patch for yesterday.

Thanks,
Jesper


#!/usr/bin/env python
# Simple test of GDK rgb array draw function
# Author: Jesper Skov <[EMAIL PROTECTED]>
# Date: 2000-03-19

from gtk import *
from Numeric import *
from whrandom import *

# Drw area size
width = 800
height = 800

# Number of blobs to paint
count = 100

# how often to update (msecs)
freq = 10


# Blob class. Describes movement behavior
class blob:
    x = 0
    x_direction = 1
    x_change = 10
    y = 0
    y_direction = 1
    y_change = 10
    
    def mutate(self, data):
        # Change x position, change direction if borders hit
        self.x = self.x + self.xd
        if (self.x <= 0):
            self.x = 0
            self.x_direction = 1
        elif (self.x >= self.limit_x-self.width):
            self.x = self.limit_x-self.width
            self.x_direction = -1

        # Change y position, change direction if borders hit
        self.y = self.y + self.yd
        if (self.y <= 0):
            self.y = 0
            self.y_direction = 1
        elif (self.y >= self.limit_y-self.height):
            self.y_direction = -1
            self.y = self.limit_y-self.height

        # Mutate movement deltas
        self.x_change = self.x_change - 1;
        if (self.x_change < 0):
            self.x_change = int(self.generator.random() * self.max_xd)
            self.xd = int(self.generator.random() * self.max_xd) * self.x_direction
        self.y_change = self.y_change - 1;
        if (self.y_change < 0):
            self.y_change = int(self.generator.random() * self.max_yd)
            self.yd = int(self.generator.random() * self.max_yd) * self.y_direction

        # Mutate color
        self.color_change = self.color_change - 1
        if (self.color_change < 0):
            self.color_change = int(self.generator.random() * self.color_step)
            self.array = (self.array + self.color_step).astype(UnsignedInt8)
            
        return TRUE

    # Draw this blob
    def draw(self, gdk_win):
        draw_array(gdk_win, self.gc, self.x, self.y, 0, self.array)
        
    def __init__(self, width, height, limit_x, limit_y, color_step, gc):
        self.width = width
        self.height = height
        self.limit_x = limit_x
        self.limit_y = limit_y
        self.color_step = color_step
        self.gc = gc
        
        self.array = zeros([width, height]).astype(UnsignedInt8)

        self.color_change = color_step
        self.xd = self.max_xd = width+1
        self.yd = self.max_yd = height+1

        self.generator = whrandom()
    
def destroy(*args):
    mainquit ()

# Draw all blobs on exposure
def expose_event(widget, event):
    win = event.window
    for i in range(len(blobs)):
        blobs[i].draw(win)
    return TRUE

# Init GDK rgb sub-system
gdk_rgb_init()

# Open window and create drawing aread
window = GtkWindow(WINDOW_TOPLEVEL)
window.set_usize(width,height)
window.connect("destroy", destroy)

drw = GtkDrawingArea()
drw.size(width,height)
drw.connect("expose_event", expose_event)
drw.set_events(GDK.EXPOSURE_MASK)
window.add(drw)
drw.show()

window.show ()

# Create the blobs
blobs = []
for i in range(count):
    blobs.append(blob((i%20)+1, (i%20)+1, width, height, ((i%10)+1)*10,
                      drw.get_style().white_gc))

# Set update event handler
def update(data):
    for i in range(len(blobs)):
        blobs[i].mutate(0)
    drw.queue_draw()
    return TRUE

timeout_add(freq, update, 0)

# Go
mainloop ()
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]

Reply via email to