Solution for presenting multiple stimuli
Hello,
I have a question regarding the presentation of multiple stimuli simultaneously.
I'm using Expyriment 0.8.0 with Python 2.10.12 on OSX 10.12.1 (I can also test on Windows 7 on a VM).
In my task, there is a big red circle, and participants move a cursor controlled by the mouse to reach the red circle.
So the red circle is static, whereas the cursor circle is updated at every screen flip.
How do I keep all other stimuli static, and update only the cursor?
What I have tried (mousecircle = cursor):
Option 1 : Works best with the cursor, smooth movement, but bad because everything else is cleared.
# Option 1
mousecircle.present()
Option 2: works but now both circles are flickering strangely
# Option 2
mousecircle.present()
targetcircle.present(clear=False)
Option 3: Using a canvas: cursor is leaving a trace behind (not cleared)
# Option 3
mousecircle.plot(canvas)
targetcircle.plot(canvas)
canvas.present()
Option 4: Here I try to restore the canvas to the default, where no cursor is drawn, but still it is leaving a trace.
# Option 4
newcanvas = canvas # Restore canvas to default, where there is just the target, to "delete" the old cursor
mousecircle.plot(newcanvas)
targetcircle.plot(newcanvas)
newcanvas.present()
My goal is to update only the cursor (mousecircle), but not the target (targetcircle).
The solution might be easy, but I'm unable to solve it... Perhaps you can guide me in solving the problem and/or tell me how to handle multiple stimuli intelligently
Thank you!
My full code (I removed most irrelevant parts):
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 29 15:18:47 2016 using the 'expyriment' Python library:
Krause, F. & Lindemann, O. (2013). Expyriment: A Python library for cognitive
and neuroscientific experiments. Behavior Research Methods.
doi:10.3758/s13428-013-0390-6
"""
from __future__ import division # so 1/3 does not give 0 in python 2.7
from expyriment import design, control, stimuli, misc, io
from expyriment.misc import constants
import numpy as np # for tuple arithmetic
control.set_develop_mode(True)
control.defaults.window_size = (800, 600)
# EXP SETTINGS
NR_TRIALS_PER_BLOCK = 50
t_fixcross = 500
min_max_ITI = [2000, 3000]
max_trialtime = 4000
TJI = 1000 # interval
# EXP INFO
exp = design.Experiment(name="Mouse task'")
# INITIALIZE
control.initialize(exp)
# DESIGN
for deviation_type in ["no_deviation", "deviation_1", "deviation_2", "deviation_3"]:
block = design.Block()
block.set_factor("deviation_type", deviation_type)
#add trials to block
trial = design.Trial()
block.add_trial(trial, copies=NR_TRIALS_PER_BLOCK)
block.shuffle_trials()
exp.add_block(block)
# STIMULI
blankscreen = stimuli.BlankScreen()
canvas = stimuli.BlankScreen()
fixcross = stimuli.FixCross()
# Mouse task
init_pos = [(-250, 0), (0, 0), (250, 0)]
col = (constants.C_BLUE, constants.C_RED, constants.C_WHITE)
startcircle = stimuli.Circle(radius=15, colour=col[0], line_width=0,
position=init_pos[0],anti_aliasing=None)
mousecircle = stimuli.Circle(radius=5, colour=col[2], line_width=0,
position=init_pos[1], anti_aliasing=None)
targetcircle = stimuli.Circle(radius=30, colour=col[1], line_width=0,
position=init_pos[2], anti_aliasing=None)
# preload
blankscreen.preload()
fixcross.preload()
startcircle.preload()
mousecircle.preload()
targetcircle.preload()
# TRIAL FUNCTION
def mouse_trial(cnt,trial):
# Prepare trial
fixcross.present()
exp.clock.wait(t_fixcross)
# Present screen
exp.clock.reset_stopwatch()
targetcircle.plot(canvas)
canvas.present()
while not exp.mouse.check_button_pressed(0):
old_pos = exp.mouse.position
# Update cursor position
new_pos = exp.mouse.position
mousecircle.replace(new_pos)
# Option 1
# mousecircle.present()
# Option 2
# mousecircle.present()
# targetcircle.present(clear=False)
# Option 3
# mousecircle.plot(canvas)
# targetcircle.plot(canvas)
# canvas.present()
# Option 4
newcanvas = canvas
mousecircle.plot(newcanvas)
targetcircle.plot(newcanvas)
newcanvas.present()
######### START ##############
control.start(exp)
for block in exp.blocks:
for cnt, trial in enumerate(block.trials):
mouse_trial(cnt, trial)
####### END EXPERIMENT ########
control.end(goodbye_text="Thank you very much for participating in our experiment",
goodbye_delay=5000)
Comments
Dear Santiago,
I think option 2 is indeed the most suitable one. However, the flickering might be due to double buffering. The solution is to just present it twice, so it gets written to both, the front and the back buffer.
Hope this helps,
Florian