Skip to content

Instantly share code, notes, and snippets.

@lindemann09
Last active August 29, 2015 14:01
Show Gist options
  • Save lindemann09/f324e6cbf1287dacf117 to your computer and use it in GitHub Desktop.
Save lindemann09/f324e6cbf1287dacf117 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from expyriment import control, design, misc, io, stimuli
def scale_to_fullscreen(visual_stimulus, exp, keep_aspect_ratio=True):
"""Scale the stimulus to fullscreen.
This is a surface operation. After this, a surface will be present!
Scaling goes along with a quality loss. Thus, scaling an already
scaled stimulus is not a good idea.
Parameters
----------
keep_aspect_ratio : boolean, optional
if this boolean is False, stimulus will be stretched so that it
fills out the whole screen (default = False)
exp : design.Experiment
the currently running experiment
Returns
-------
visual_stimulus : the scaled stimulus
Notes
-----
Depending on the size of the stimulus, this method may take some time
to compute!
"""
surface_size = visual_stimulus.surface_size
screen_size = exp.screen.surface.get_size()
scale = (screen_size[0]/float(surface_size[0]),
screen_size[1]/float(surface_size[1]))
if keep_aspect_ratio:
scale = [min(scale)]*2
visual_stimulus.scale(factors=scale)
return visual_stimulus
exp = design.Experiment(name="My experiment")
control.initialize(exp)
control.start(exp)
p = stimuli.Picture( "my_stimulus.gif")
scale_to_fullscreen(p, exp, keep_aspect_ratio=False)
p.present()
exp.keyboard.wait()
control.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment