# trigonometry to build rotating clock from math import radians, atan2, sin, cos, degrees from openexp.canvas import canvas from openexp.keyboard import keyboard import random import time import numpy as np var.response ='None' var.response_time= 0 var.press=0 clock_path = exp.pool[u'clock.png'] src = pool ['single_bip_700.wav'] #parameters arm_len = 170# distance from the center start_angle= var.angle n_rev = 1 # nr. of revolutions #speed =140.625 step_size =10 # displacement per frame delay =20 #delay in milliseconds (duration at each position) # Create a canvas my_canvas = canvas(self.experiment) #center coordinates xc=0 yc=-15 # distance from the center sx =var.sx sy =var.sy #sound my_sampler= sampler(src, volume = .5) #initialize the keyboard my_keyboard = keyboard (exp, keylist=['space', 'h'],timeout = 0) #random sound presentation var.play_time= random.randint(2,36) #rotating frame for time in range(0,n_rev*360, step_size): start_time = clock.time() var.start_time = start_time print ('this is start_time' + str(start_time)) #starting point of the loop # The end points of the arm, relative to the center dx =arm_len* cos(radians(time+ start_angle)) dy =arm_len* sin(radians(time+ start_angle)) # Draw! my_canvas.clear() my_canvas.image(clock_path, x=0, y=0, scale= 0.50) my_canvas.line(xc, yc,xc+dx, yc+dy, fill = True, color = 'red', penwidth = 3) my_canvas.show() #collecting responses key,end_time= my_keyboard.get_key() if key == "h": exp.set('response', key) exp.set('response_time', end_time - start_time)