[open] Libet's rotating spot clock - Intentional Binding Paradigm
Hi. I'm trying to make a rotaing spot clock like the one used in Libet's volition expermient, to use it to measure the Intentional binding effect. I got lots of help on this forum, reading other entrie on the subject. here.
I was able to make an inline code that displays the clock with a rotating red ball, marking the revolutions every 2560 ms and then to mark the time which a key is pressed ("z"). 1500 ms after the keypress, a synth sound plays, and the sound time is recorded. Then the clock is stopped a random range of time after. I'm missing the method to introduce the percieved time of the two events.
Although my code does the job, i think it's rather rough. I would appreciate if someone could look in to my code and maybe help me find a more elegant solution. thanks!
from openexp.canvas import canvas from openexp.keyboard import keyboard from openexp.synth import synth from math import radians, atan2, sin, cos, degrees # Trigonometry to build rotating spot import random, time #initialize synth, sine wave my_synth = synth(self.experiment, osc = "sine", freq = "b1", attack = 1, length = 200) #initialice canvas and path of clock image my_canvas = canvas(self.experiment) my_canvas.show() path = self.experiment.get_file("clock2.png") #initialize keyboard my_keyboard = keyboard(self.experiment, keylist = ["z"],timeout= 0) clock_radius = 75 #radius of the clock spot. speed = 140.625 # speed to make 1 turn of the clock in 2560 ms start_t = time.time() - random.randint(0, 2560) # needed to make the startinf position of the clock random. half_screen = 250.5 #had to do this to draw the circle relative to the center of the screen. I dont now if canvas can manage "center" relative coordinates. press_time = 100000000000 #set this variables high enough, to avoid entering the conditions. finish_time = 100000000000 delay = random.randint(2, 5) while True: #start the clock t = time.time() - start_t dy = clock_radius * sin(radians(t * speed)) dx = clock_radius * cos(radians(t * speed)) my_canvas.clear() my_canvas.circle(dx + half_screen,dy + half_screen,5, fill=True); my_canvas.image(path) my_canvas.show() mark = atan2(dy,dx)*10 + 15 # fix the result of the atan2 function to give clock marks if mark < 0: mark = (60 + mark) key, f_time = my_keyboard.get_key() if key==122: #mark the time of the key press key_mark=mark press_time=time.time() if time.time() - press_time > 1.5: #set a 1.5s interval before synth play my_synth.play() sound_mark=mark press_time = 100000000000000 finish_time=time.time() if time.time() - finish_time > delay: #set a random (delay) interval before breaking print key_mark, sound_mark break