neurotools.graphics.pygame module

Collected utilities for pygame

It is difficult to write pixels directly in python.

There’s some way to get a framebuffer back from Tk, but it is cumberosme.

The module pygame supports sending pixel buffers, which is wrapped for convneinece in this module.

example usage

import neurotools.graphics.pygame as npg import time import numpy as np import pygame K = 128 screen = npg.start(K,K,’Image data’) dt = 1/20 wait_til = time.time() + dt print(‘Animating..’) for i in neurotools.tools.progress_bar(range(100)):

t = time.time() if t<wait_til: time.sleep(wait_til-t) wait_til = t + dt npg.draw_array(screen, np.random.rand(K,K,3))

pygame.quit()

neurotools.graphics.pygame.enable_vsync()[source]
neurotools.graphics.pygame.start(W, H, name='untitled')[source]
neurotools.graphics.pygame.draw_array(screen, rgbdata, doshow=True)[source]

Send array data to a PyGame window. PyGame is BRG order which is unusual – reorder it.

Parameters:
  • screen (object) – Object returned by neurotools.graphics.pygame.start

  • rgbdata – RGB image data with color values in [0,1]