-
Notifications
You must be signed in to change notification settings - Fork 1
/
pursuit_imp.py
97 lines (80 loc) · 3.51 KB
/
pursuit_imp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import numpy as np
import pandas as pd
from psychopy import core, event, visual, logging
from toon.input import MultiprocessInput
from toon.input.clock import mono_clock
from state_dec import StateMachine
from sham_mouse import Mouse
class Pursuit(StateMachine):
def __init__(self, settings=None):
super(Pursuit, self).__init__()
self.global_clock = mono_clock
# set up input
if settings['mouse']:
self.device = Mouse(clock=self.global_clock.getTime)
else:
core.quit()
#self.device = ForceHandle(clock=self.global_clock.getTime)
try:
#self.trial_table = pd.read_csv(settings['trial_table'])
pass
except FileNotFoundError:
core.quit()
# set up display
self.win = visual.Window(size=(800, 800),
pos=(0, 0),
fullscr=settings['fullscreen'],
screen=1,
units='height',
allowGUI=False,
colorSpace='rgb',
color=(-1, -1, -1),
waitBlanking=False)
self.win.recordFrameIntervals = True
self.setup_visuals()
# extras
self.data = None
self.total_frames = 0
self.frames_on_target = 0
def setup_visuals(self):
self.target = visual.Circle(self.win, size=0.05, fillColor=[0, 0, 0],
pos=(0, 0), autoDraw=True, autoLog=False,
name='target')
self.player = visual.Circle(self.win, size=0.025, fillColor=[1, 1, 1],
pos=(0, 0), autoDraw=True, autoLog=False,
name='player')
self.post_text = visual.TextStim(self.win, text='Spacebar to start.',
pos=(0, 0.4), units='height',
color=[1, 1, 1],
height=0.1,
alignHoriz='center', alignVert='center',
name='post_text', autoLog=False,
wrapWidth=2)
self.post_text.autoDraw = True
def check_for_space(self):
return any(event.getKeys(['space', 'spacebar']))
def remove_text(self):
self.post_text.autoDraw = False
def update_target_pos(self):
self.target.pos = [np.sin(self.total_frames/50.0)/3.5,
np.cos(self.total_frames/100.0)/4.0]
def update_target_color_and_count(self):
self.total_frames += 1
if self.target.contains(self.player.pos):
self.frames_on_target += 1
self.target.fillColor = [-0.27, 0.47, 0.05]
else:
self.target.fillColor = [0, 0, 0]
def samples_exhausted(self):
return self.total_frames > 500
def draw_time_on_target(self):
self.post_text.setText('Percentage: ' + str(round(100*(self.frames_on_target/self.total_frames), 0)))
self.post_text.autoDraw = True
def start_countdown(self):
self.countdown_timer = core.CountdownTimer(5)
def time_elapsed(self):
return self.countdown_timer.getTime() <= 0
def input(self):
timestamp, self.data = self.device.read()
def draw_input(self):
self.player.pos = self.data