Skip to content

Commit 9e77283

Browse files
committed
add different ebbinghaus day classes in single file
1 parent 3676132 commit 9e77283

File tree

2 files changed

+185
-72
lines changed

2 files changed

+185
-72
lines changed

src/visiomode/tasks/ebbinghaus.py

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
from visiomode.stimuli.ebbinghaus_circle import EbbinghausCircle
2+
from visiomode import tasks
3+
4+
import random
5+
6+
import pygame as pg
7+
8+
9+
class EbbinghausPsychometric(tasks.Task):
10+
form_path = "tasks/task.html"
11+
12+
def __init__(self, **kwargs):
13+
super().__init__(iti=2000, stimulus_duration=10000, **kwargs)
14+
15+
self.background = pg.Surface(self.screen.get_size())
16+
self.background = self.background.convert()
17+
self.background.fill((0, 0, 0))
18+
self.screen.blit(self.background, (0, 0))
19+
20+
self.corrections_enabled = False
21+
22+
self.separator_size = 50 # pixels
23+
self.separator = pg.Rect(((0, 0), (self.separator_size, self.screen.get_height())))
24+
self.separator.centerx = self.screen.get_rect().centerx
25+
26+
self.stimulus_width = (self.screen.get_size()[0] - self.separator_size) // 2
27+
28+
self.target = EbbinghausCircle(
29+
background=self.background,
30+
width=self.stimulus_width,
31+
center_size=[20, 25, 30],
32+
ratios=[0.5, 1, 2],
33+
)
34+
35+
self.distractor = EbbinghausCircle(
36+
background=self.background,
37+
width=self.stimulus_width,
38+
center_size=[10, 15, 20],
39+
ratios=[0.5, 1, 2],
40+
)
41+
42+
def show_stimulus(self):
43+
self.target.generate_new_trial()
44+
self.distractor.generate_new_trial()
45+
46+
# work out if it's an illusion trial
47+
self.is_illusion = True if self.target.center_radius == self.distractor.center_radius else False
48+
49+
target_x, distr_x = self.shuffle_centerx()
50+
51+
self.target.set_centerx(target_x)
52+
self.distractor.set_centerx(distr_x)
53+
54+
self.target.show()
55+
self.distractor.show()
56+
57+
def hide_stimulus(self):
58+
self.target.hide()
59+
self.distractor.hide()
60+
# self.screen.blit(self.background, (0, 0))
61+
62+
def update_stimulus(self):
63+
self.distractor.update()
64+
self.target.update()
65+
66+
def shuffle_centerx(self):
67+
# centers = [
68+
# 0 - (self.separator_size / 2),
69+
# self.screen.get_width() + (self.separator_size / 2),
70+
# ]
71+
centers = (
72+
((self.screen.get_width() / 2) - (self.separator_size / 2)) / 2,
73+
(self.screen.get_width() / 2) + (self.separator_size / 2) + (self.stimulus_width / 2),
74+
)
75+
return random.sample(centers, 2)
76+
77+
def on_correct(self):
78+
if self.is_illusion:
79+
# If it was an illusion trial, do nothing
80+
return
81+
return super().on_correct()
82+
83+
84+
class EbbinghausInterleaved(tasks.Task):
85+
"""Ebbinghaus illusion task where 10% of trials are illusion trials"""
86+
87+
form_path = "tasks/task.html"
88+
89+
def __init__(self, **kwargs):
90+
super().__init__(iti=2000, stimulus_duration=10000, **kwargs)
91+
92+
self.background = pg.Surface(self.screen.get_size())
93+
self.background = self.background.convert()
94+
self.background.fill((0, 0, 0))
95+
self.screen.blit(self.background, (0, 0))
96+
97+
self.corrections_enabled = False
98+
99+
self.separator_size = 50 # pixels
100+
self.separator = pg.Rect(((0, 0), (self.separator_size, self.screen.get_height())))
101+
self.separator.centerx = self.screen.get_rect().centerx
102+
103+
self.stimulus_width = (self.screen.get_size()[0] - self.separator_size) // 2
104+
105+
self.target = None
106+
self.distractor = None
107+
108+
self.is_illusion = False
109+
110+
def show_stimulus(self):
111+
# Determine stimulus parameters for the current trial
112+
if random.random() < 0.10: # 10% of trials
113+
# Illusion trial
114+
target_center_size = [20] # target: centre that looks smaller
115+
distractor_center_size = [20] # distractor: centre that looks bigger
116+
117+
# Set specific ratios
118+
target_ratios = [2] # Bigger context circles for target
119+
distractor_ratios = [0.5] # Smaller context circles for distractor
120+
121+
self.is_illusion = True
122+
123+
else: # 90% of trials (standard case)
124+
# Target center 40px, Distractor center 20px (as before)
125+
target_center_size = [40]
126+
distractor_center_size = [20]
127+
128+
# Default ratios for both (as before)
129+
target_ratios = [0.5, 1, 1.5, 2]
130+
distractor_ratios = [0.5, 1, 1.5, 2]
131+
132+
self.is_illusion = False
133+
134+
# Create new EbbinghausCircle instances with the determined parameters
135+
self.target = EbbinghausCircle(
136+
background=self.background,
137+
width=self.stimulus_width,
138+
center_size=target_center_size,
139+
ratios=target_ratios,
140+
)
141+
142+
self.distractor = EbbinghausCircle(
143+
background=self.background,
144+
width=self.stimulus_width,
145+
center_size=distractor_center_size,
146+
ratios=distractor_ratios,
147+
)
148+
149+
# Generate new trial for the newly created stimuli
150+
self.target.generate_new_trial()
151+
self.distractor.generate_new_trial()
152+
153+
# Shuffle positions and show
154+
target_x, distr_x = self.shuffle_centerx()
155+
156+
self.target.set_centerx(target_x)
157+
self.distractor.set_centerx(distr_x)
158+
159+
self.target.show()
160+
self.distractor.show()
161+
162+
def hide_stimulus(self):
163+
if self.target:
164+
self.target.hide()
165+
if self.distractor:
166+
self.distractor.hide()
167+
168+
def update_stimulus(self):
169+
if self.distractor:
170+
self.distractor.update()
171+
if self.target:
172+
self.target.update()
173+
174+
def shuffle_centerx(self):
175+
centers = (
176+
((self.screen.get_width() / 2) - (self.separator_size / 2)) / 2,
177+
(self.screen.get_width() / 2) + (self.separator_size / 2) + (self.stimulus_width / 2),
178+
)
179+
return random.sample(centers, 2)
180+
181+
def on_correct(self):
182+
if self.is_illusion:
183+
# If it was an illusion trial, do nothing
184+
return
185+
return super().on_correct()

src/visiomode/tasks/ebbinghaus_test.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)