Psychopy- Python code error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Psychopy- Python code error (/thread-5159.html) |
Psychopy- Python code error - Iva09 - Sep-20-2017 Hi all, I am trying to create a visual stimuli in Psychopy which should contain two rectangles(red and green) flashing at different frequencies. These rectangle boxes should contain different set of alphabets (26 alphabets should be spread out to both rectangles). I am not able to attach alphabets to my rectangles. Somehow code is not working properly. The Psychopy Gui opens and it closes immediately, without showing anything. It cannot take input it seems. I am not able to figure out whether it is because of the way I defined classes or is it due to Psychopy syntax usage. Here is the code which I am working on. from psychopy import visual, core import numpy as np class TablesGenerator(object): def_text_table1 = [ ['A', 'B', 'C'], ['G', 'H', 'I'], ['M', 'N', 'O'], ['S', 'T', 'U'], ['Y', 'Z', '-'] ] def_text_table2 = [ ['D', 'E', 'F'], ['J', 'K', 'L'], ['P', 'Q', 'R'], ['V', 'W', 'X'], ['?', '_', '-'] ] def __init__(self, text_table1=def_text_table1, fullscr=False, pos=(0, 0), bg_color='red', fg_color='black'): self.text_table1 = text_table1 self.fullscr = fullscr self.pos = pos self.fg_color = fg_color self.bg_color = bg_color def __init__(self, text_table2=def_text_table2, fullscr=False, pos=(0, 0), bg_color='green', fg_color='black'): self.text_table2 = text_table2 self.fullscr = fullscr self.pos = pos self.fg_color = fg_color self.bg_color = bg_color # Create a window. # For configuring and debugging the code turn off full screen. fullscr = False win = visual.Window( [1200,1000], monitor="testMonitor", units="deg", fullscr=fullscr ) win.setMouseVisible(False) # Sinusoidal control version. freq_one = 0.5 freq_two = 1.5 # Colors of the rectangles. color_one = 'red' color_two = 'green' # Positions of the rectanges. pos_one = (-7, 0) pos_two = (7, 0) start = core.getTime() cnt = 0 while cnt<600: second = core.getTime() - start sin_val_one = 1.0+0.5*np.sin(2 * np.pi * second * float(freq_one)) sin_val_two = 1.0+0.5*np.sin(2 * np.pi * second * float(freq_two)) def _create_TextStim1(self, win, text1, font='Monospace', height=10, wrapWidth=600): text_stim1 = visual.TextStim(win=win, text1=''.join(text_table1), font=font, height=height, wrapWidth=wrapWidth, color=self.fg_color) return text_stim1 def _create_TextStim2(self, win, text2, font='Monospace', height=10, wrapWidth=600): text_stim2 = visual.TextStim(win=win, text2=''.join(text_table2), font=font, height=height, wrapWidth=wrapWidth, color=self.fg_color) return text_stim2 rect_one = visual.Rect( win=win,text1=''.join(text_stim1), fillColor=color_one, lineColor=color_one, size=20, pos=pos_one, opacity=sin_val_one ) rect_two = visual.Rect( win=win,text2=''.join(text_stim2), fillColor=color_two, lineColor=color_two, size=20, pos=pos_two, opacity=sin_val_two ) rect_one.draw() rect_two.draw() win.flip() cnt += 1 win.close() Can anyone please help me resolve this error? Thanks in Advance ! |