I’m practicing with moving stimuli during a task. I have a countdown timer, a progress bar, and a circle that makes a loop around the countdown timer. My problem is that the circle does not make a complete loop before the timer is finished, and I don’t know how to speed this up. Is there a better way than what I have? Here is what I’ve been doing:
from __future__ import division
from psychopy import locale_setup, visual, core, event, data, gui
import os, platform, math, shlex
import subprocess as subp
#Set window and remove mouse during experiment:
win = visual.Window(fullscr=True, pos=(0,0), units="norm", color = "Black")
event.Mouse(visible=False)
#Determine Monitor Resolution:
if platform.system() == "Windows":
from win32api import GetSystemMetrics
width, height = GetSystemMetrics(0), GetSystemMetrics(1)
elif platform.system() == "Darwin":
p = subp.Popen(shlex.split("system_profiler SPDisplaysDataType"), stdout=subp.PIPE)
output = subp.check_output(('grep', 'Resolution'), stdin=p.stdout)
width, height = [int(x.strip(' ')) for x in output.split(':')[-1].split(' x ')]
#Create stimuli:
text = visual.TextStim(win, text=' ', pos=(0,0), height = 0.5, color="White")
circle = visual.Circle(win, radius=0.05, pos = (0,0.5), fillColor="Yellow")
prog_bar = visual.Rect(win, pos=(-1.0, -0.8), fillColor="White")
#Set varaibles
cdTime = 5.0
speed = 4/cdTime
pi = math.pi
radius = text.boundingBox[1]/height + 0.1
#Set timer:
timer = core.Clock()
timer.reset()
time_start = timer.getTime()
countdownTimer = core.CountdownTimer(cdTime)
while countdownTimer.getTime() > 0.0:
thesekeys = event.getKeys(keyList=["escape"])
if len(thesekeys):
break
text.text= int(round(math.ceil(countdownTimer.getTime()),0))
prog_bar.size = (((cdTime-countdownTimer.getTime())*2)*speed, 0.3) #Multiply by 2 to move progress bar in 1 direction, multiply by speed for progress to finish when timer finishes
circle.pos = (radius*math.cos(cdTime-countdownTimer.getTime()+0.1), radius*math.sin(cdTime-countdownTimer.getTime())+0.1)
text.draw()
circle.draw()
prog_bar.draw()
win.flip()
time_end = timer.getTime()
print "Length of countdown: %s" %(time_end - time_start)
#Finish
win.close()
core.quit()