[visionegg] simple RSVP scripts

Hi, Andrew,

I'm writing a simple RSVP script to pre-load several bitmaps and display them at the appropriate time, while getting user RT.

As this program will need to be modified by undergrads with no programming experience, I want to modify the demo you posted some time ago (in response to another post... http://www.freelists.org/archives/visionegg/11-2002/msg00001.html ) to do away with the Presentation object and controllers until they feel more comfortable with them.

I've included the code at the end of this email.

As I've done most of my coding in c, I'm accustomed to generating all bitmaps ahead of time, then during each trial, drawing each bitmap to a back-buffer, synchronizing to the vertical blank, then page-flipping. In the example you suggested, the closest analogue in python/visionegg is the following code snippet

     # Load the texture to OpenGL, prepare for display
     stimulus = TextureStimulus(texture = texture,
                                size    = texture.size,
                                texture_min_filter=gl.GL_LINEAR,

position=(screen.size[0]/2.0,screen.size[1]/2.0),
                                shrink_texture_ok=1)

     # Add to list of stimuli
     preloaded_stimulus_list.append( stimulus )

whereupon you append the textures to a texture list preloaded into video memory (right?).

Then, the controller cycles through this texture list. However, I would like to be able to reference each texture explicitly and in random-access fashion, such as:

draw texture_1 to back buffer;
flip;
wait n msecs (and get RT)
draw texture_2 to back buffer;
.. and so on...

What would you suggest the quickest way to do this... I assume it's fairly simple, but remember, I come from the world of c (and as such, python's still something of a stretch for me!)

cheers,

-=gabe

************************************
#!usr/bin/pythonw
# based on Andrew Straw's demo code
# http://www.freelists.org/archives/visionegg/11-2002/msg00001.html

from VisionEgg import *
start_default_logging(); watch_exceptions()

from VisionEgg.Core import *
from VisionEgg.FlowControl import Presentation, FunctionController
from VisionEgg.Textures import *
from pygame.time import *
import OpenGL.GL as gl

#make sure bitmaps are in source directory
photoX = ("crate.bmp", "glass.bmp", "mud.bmp", "nehe.bmp", "star.bmp")

duration_per_image = 0.1 # seconds
num_images = len(photoX)

screen = get_default_screen()

# Create list of stimuli
preloaded_stimulus_list = [] # empty at first

for i in range(num_images):
     # Read the texture file
     texture = TextureFromFile(photoX[i])

     # Load the texture to OpenGL, prepare for display
     stimulus = TextureStimulus(texture = texture,
                                size    = texture.size,
                                texture_min_filter=gl.GL_LINEAR,

position=(screen.size[0]/2.0,screen.size[1]/2.0),
                                shrink_texture_ok=1)

     # Add to list of stimuli
     preloaded_stimulus_list.append( stimulus )

#<debug>
# make sure textures are actually loaded
print "preloaded_stimulus_list = "
print preloaded_stimulus_list
#</debug>


def image_selector( t ): i = int(t/duration_per_image) return [ preloaded_stimulus_list[i] ]

###############################################
#
# <controller_version>
    #uncomment this section this section for original, working version
"""

p = Presentation(go_duration=(duration_per_image *
                              num_images,'seconds'),viewports=[viewport])
p.add_controller(viewport,'stimuli',
                 FunctionController(during_go_func=image_selector) )

p.go()

"""
# </controller_version>

###############################################
# comment this section for "controller" version
#
# <procedural_version>

frame_timer = FrameTimer()
msec_timer = get_ticks()


done = False

# show image 1

# code to modify for loading file as appropriate
image_counter = 0
viewport = Viewport(screen=screen,
stimuli = preloaded_stimulus_list[image_counter]) # doesn't work


viewport.draw()
swap_buffers()
frame_timer.tick()

image_counter = image_counter + 1

# wait and poll
while get_ticks() <= (msec_timer + 4000):
event = pygame.event.poll()
#event = pygame.event.get([KEYDOWN,KEYUP])
if event.type == pygame.locals.KEYDOWN and event.key == pygame.locals.K_ESCAPE:
break


    # put code for polling user RT here



# show image 2


# show image 3



# </procedural_version>
#
########################################

frame_timer.print_histogram()

*************


====================================== The Vision Egg mailing list Archives: http://www.freelists.org/archives/visionegg Website: http://www.visionegg.org/mailinglist.html

Other related posts: