Hello,
I’m designing an experiment where an image is initially hidden behind 7 vertical rectangles (visual.Rect) before gradually being revealed due to the erosion of the rectangles. My code for implementing this is as follows:
from __future__ import division
from psychopy import locale_setup, visual, core, event, data, gui
#Window
win = visual.Window(size = (2560,1440), fullscr = True, pos = (0,0), units = "height", color = [-1,-1,-1])
#Turn off Mouse
event.Mouse(visible = False)
#Timer
trialTimer = core.Clock()
#Escape function
def escape_option():
if 'escape' in event.getKeys(keyList=['escape']):
core.quit()
#Variables
image_width = 0.593333333333
image_height = 0.5
num_shades = 7
avg_shade_width = image_width/num_shades
unmaskLength = 60
mask1_center = 0
mask2_center = -avg_shade_width
mask3_center = avg_shade_width
mask4_center = -avg_shade_width*2
mask5_center = avg_shade_width*2
mask6_center = -avg_shade_width*3
mask7_center = avg_shade_width*3
#Psychopy Stimuli
image = visual.ImageStim(win=win, pos=(0,0), size=(1.78/3, 1/2), image='/Users/dlevitas/Desktop/First_year_project/Pictures/F_02_neu.jpg')
mask1 = visual.Rect(win=win, pos=(mask1_center,0), lineColor='Black', fillColor='Black')
mask2 = visual.Rect(win=win, pos=(mask2_center,0), lineColor='Black', fillColor='Black')
mask3 = visual.Rect(win=win, pos=(mask3_center,0), lineColor='Black', fillColor='Black')
mask4 = visual.Rect(win=win, pos=(mask4_center,0), lineColor='Black', fillColor='Black')
mask5 = visual.Rect(win=win, pos=(mask5_center,0), lineColor='Black', fillColor='Black')
mask6 = visual.Rect(win=win, pos=(mask6_center,0), lineColor='Black', fillColor='Black')
mask7 = visual.Rect(win=win, pos=(mask7_center,0), lineColor='Black', fillColor='Black')
#Start
trialTimer.reset()
while trialTimer.getTime() < unmaskLength:
current_time = trialTimer.getTime()
escape_option()
mask1.size = ((unmaskLength - current_time)*(avg_shade_width/unmaskLength)*2,2)
mask2.size = ((unmaskLength - current_time)*(avg_shade_width/unmaskLength)*2,2)
mask3.size = ((unmaskLength - current_time)*(avg_shade_width/unmaskLength)*2,2)
mask4.size = ((unmaskLength - current_time)*(avg_shade_width/unmaskLength)*2,2)
mask5.size = ((unmaskLength - current_time)*(avg_shade_width/unmaskLength)*2,2)
mask6.size = ((unmaskLength - current_time)*(avg_shade_width/unmaskLength)*2,2)
mask7.size = ((unmaskLength - current_time)*(avg_shade_width/unmaskLength)*2,2)
image.draw()
mask1.draw()
mask2.draw()
mask3.draw()
mask4.draw()
mask5.draw()
mask6.draw()
mask7.draw()
win.flip()
My issue is that the masks do not erode at the same time (mask1 has already begun to erode before mask7). I assume this is occurring because I’m drawing each mask individually; however, I was wondering if there was a way to resolve this issue?
Thank you for the assistance.
Dan