[Edu-sig] Re: Brainstorming about January

Lee Harr missive at hotmail.com
Mon Dec 13 02:53:44 CET 2004


>As far as I know there are a *lot* of graphics-Toolkits for Python out
>there. Which of them could be used for this task? What are your
>experiences? Do you have significantly faster solutions?
>


How about pygame, This takes about 2 seconds on my system,
while the tkinter version takes over a minute.


# feigen_pygame.py

import pygame
pygame.init()

WIDTH = 700
HEIGHT = 500
NUM = 2*HEIGHT//3

WHITE = (255, 255, 255)
RED = (255, 0, 0)
BLACK = (0, 0, 0)

def f(x):
    return LAMBDA * x * (1-x)

sfc = pygame.display.set_mode((WIDTH+1, HEIGHT))
sfc.fill(WHITE)

for i in range(8):
    for y in range(0,HEIGHT):
        x = (WIDTH/7.0)*i
        sfc.set_at((x, y), RED)

for frac in range(WIDTH):
    LAMBDA = 3.3 + frac*0.7/WIDTH
    x = 0.5   # initial value for iteration
    ys={}
    for i in range(150):
        x = f(x)
    for i in range(NUM):
        x = f(x)
        ys[int(HEIGHT*x)]=True
    for y in ys:
        sfc.set_at((frac, y), BLACK)
    if frac%10==0:
        pygame.display.update()

# wait for a mouse click before closing the window
ev = []
while not ev:
    ev = pygame.event.get([pygame.constants.MOUSEBUTTONDOWN])

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/



More information about the Edu-sig mailing list