Ejemplo n.º 1
0
    def __init__(self, filename):

        texture = Texture(self.stimdir + filename)  # load the picture
        self.type = 'picture'

        TextureStimulus.__init__(self,
            texture = texture, size = (300, 400), **std_params)
Ejemplo n.º 2
0
    def __init__(self, picname):
        self.picname = picname
        self.motiv = picname[0]
        self.valen = picname[2]

        texture = Texture(STIM_DIRECTORY + picname)  # load the picture

        TextureStimulus.__init__(self, texture=texture, size=(500, 400), **std_params)
Ejemplo n.º 3
0
 def __init__(self,**kw):
     TextureStimulusBaseClass.__init__(self,**kw)
     size = self.constant_parameters.size
     bgcolor = self.constant_parameters.bgcolor
     img_color = (int(255*bgcolor[0]),int(255*bgcolor[1]),int(255*bgcolor[2]))
     texels = Image.new("RGBX",size,img_color)
     texels_draw = ImageDraw.Draw(texels)
     
     num_dots = self.constant_parameters.num_dots
     dot_size = self.constant_parameters.dot_size
     dot_color = self.constant_parameters.dot_color
     fill_color = (int(255*dot_color[0]),int(255*dot_color[1]),int(255*dot_color[2]))
     np.random.seed(self.constant_parameters.seed)
     xs = np.random.uniform(0, 1, num_dots) * size[0]
     np.random.seed(self.constant_parameters.seed+1)
     ys = np.random.uniform(0, 1, num_dots) * size[1]
     for i in xrange(num_dots):
         texels_draw.rectangle((xs[i], ys[i], 
                                xs[i]+dot_size, ys[i]+dot_size), 
                                fill=fill_color)
     self.texture = Texture(texels)
     nmasksamples = 256
     radius = self.constant_parameters.mask_diameter / 2
     samplesperpix = nmasksamples / self.texture.size[0]
     self.mask = DiscMask(function="circle",
                          texture = self.texture,
                          radius_parameter=radius*samplesperpix,
                          num_samples=(256,256))
     self.texture_stimulus = TextureStimulus( texture = self.texture,
                                              position = self.parameters.position,
                                              mask = self.mask,
                                              anchor = 'center',
                                              size = size,
                                              internal_format = gl.GL_RGBA,
                                              mipmaps_enabled = False,
                                              texture_min_filter = gl.GL_NEAREST,
                                              texture_mag_filter = gl.GL_NEAREST,
                                              )
Ejemplo n.º 4
0
class TextureDots(TextureStimulusBaseClass):
    """Random Dots drawn on Texture."""

    parameters_and_defaults = {
        'on':(True,
              ve_types.Boolean),
        'position':((320,240),
                    ve_types.Sequence2(ve_types.Real)),
        'mask_on':(False,
              ve_types.Boolean),
        'mask_position':((0,0),
                    ve_types.Sequence2(ve_types.Real)),
        }
    constant_parameters_and_defaults = {
        'size' : ((256,256),
                ve_types.Sequence2(ve_types.Real)),
        'mask_diameter' : (50,
                       ve_types.Real),
        'bgcolor' : ((0.5,0.5,0.5),
                   ve_types.Sequence3(ve_types.Real)),
        'seed' : ( 0,
                       ve_types.Integer ),
        'num_dots' : ( 500,
                       ve_types.UnsignedInteger ),
        'dot_size' : (4.0, # pixels
                      ve_types.Real),
        'dot_color' : ((1.0,1.0,1.0),
                   ve_types.Sequence3(ve_types.Real)),
        }

    __slots__ = (
        'texture_stimulus',
        )

    def __init__(self,**kw):
        TextureStimulusBaseClass.__init__(self,**kw)
        size = self.constant_parameters.size
        bgcolor = self.constant_parameters.bgcolor
        img_color = (int(255*bgcolor[0]),int(255*bgcolor[1]),int(255*bgcolor[2]))
        texels = Image.new("RGBX",size,img_color)
        texels_draw = ImageDraw.Draw(texels)
        
        num_dots = self.constant_parameters.num_dots
        dot_size = self.constant_parameters.dot_size
        dot_color = self.constant_parameters.dot_color
        fill_color = (int(255*dot_color[0]),int(255*dot_color[1]),int(255*dot_color[2]))
        np.random.seed(self.constant_parameters.seed)
        xs = np.random.uniform(0, 1, num_dots) * size[0]
        np.random.seed(self.constant_parameters.seed+1)
        ys = np.random.uniform(0, 1, num_dots) * size[1]
        for i in xrange(num_dots):
            texels_draw.rectangle((xs[i], ys[i], 
                                   xs[i]+dot_size, ys[i]+dot_size), 
                                   fill=fill_color)
        self.texture = Texture(texels)
        nmasksamples = 256
        radius = self.constant_parameters.mask_diameter / 2
        samplesperpix = nmasksamples / self.texture.size[0]
        self.mask = DiscMask(function="circle",
                             texture = self.texture,
                             radius_parameter=radius*samplesperpix,
                             num_samples=(256,256))
        self.texture_stimulus = TextureStimulus( texture = self.texture,
                                                 position = self.parameters.position,
                                                 mask = self.mask,
                                                 anchor = 'center',
                                                 size = size,
                                                 internal_format = gl.GL_RGBA,
                                                 mipmaps_enabled = False,
                                                 texture_min_filter = gl.GL_NEAREST,
                                                 texture_mag_filter = gl.GL_NEAREST,
                                                 )
    def draw(self):
        contained = self.texture_stimulus.parameters #shorthand
        my = self.parameters #shorthand
        contained.position = my.position
        contained.size = self.constant_parameters.size
        contained.on = my.on
        if my.mask_on:
            contained.mask = self.mask
        else:
            contained.mask = None
        self.mask.parameters.shift = my.mask_position
        self.texture_stimulus.draw()
        
Ejemplo n.º 5
0
    ))

#########################
#  Copy of framebuffer  #
#########################

# setup Texture instance for proper size and scaling, etc.
framebuffer_copy_texture = Texture(texels=screen.get_framebuffer_as_image(
    format=gl.GL_RGBA))

try:
    framebuffer_copy = TextureStimulus(
        texture=framebuffer_copy_texture,
        internal_format=gl.GL_RGBA,
        mipmaps_enabled=False,
        size=(width, height),
        texture_min_filter=gl.GL_LINEAR,
        position=(x3, y1),
        anchor='center',
        shrink_texture_ok=False,  # settting to True causes massive slowdowns
    )
    framebuffer_copy_works = True
except Exception, x:
    warning_stimuli.append(
        Text(
            text="Framebuffer copy",
            position=(x3, y1),
            anchor='center',
            color=warning_color,
            font_size=warning_font_size,
        ))
    framebuffer_copy_works = False
Ejemplo n.º 6
0
VisionEgg.start_default_logging()
VisionEgg.watch_exceptions()

from VisionEgg.Core import get_default_screen, Viewport, gl
from VisionEgg.FlowControl import Presentation
from VisionEgg.Text import Text
from VisionEgg.Textures import Texture, TextureStimulus

screen = get_default_screen()
screen.parameters.bgcolor = (0.0, 0.0, 1.0)  # background blue (RGB)

orig_text = Text(
    text="Hello world!",
    color=(1.0, 1.0, 1.0),
    font_size=50,
)

arr = orig_text.parameters.texture.get_texels_as_array()  # get numpy array
arr = arr[::-1]  # flip upside down
flipped_text = TextureStimulus(
    texture=Texture(arr),
    position=(screen.size[0] / 2, screen.size[1] / 2),
    anchor='center',
    internal_format=gl.GL_RGBA,
    mipmaps_enabled=False,
)

viewport = Viewport(screen=screen, size=screen.size, stimuli=[flipped_text])
p = Presentation(go_duration=(5.0, 'seconds'), viewports=[viewport])
p.go()