Skip to content

Commit 311e7d8

Browse files
committed
Fix two coins animations
1 parent 6137e81 commit 311e7d8

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

client/app.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@
423423
place-items: center;
424424
font-family: var(--heading-family);
425425
/* Coin face font size for visual clarity */
426-
font-size: 56px;
426+
font-size: 40px;
427427
line-height: 1;
428428
letter-spacing: -0.02em;
429429
user-select: none;

client/src/probability-lab/ui/render-two.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,36 @@ export default function renderTwo(els, state) {
6161

6262
updateDeviceViewTwo(els.deviceView, defA, defB, state.two);
6363

64+
// Trigger coin flip animations for two-devices mode
65+
// TODO: make it work for auto mode too
66+
if (state.two.lastA !== null && state.two.lastB !== null && !state.running.auto) {
67+
const deviceWraps = els.deviceView.querySelectorAll('.pl-device-mini');
68+
const coinA = deviceWraps[0]?.querySelector('.pl-coin');
69+
const coinB = deviceWraps[1]?.querySelector('.pl-coin');
70+
71+
// Handle device A coin animation
72+
if (defA.device === 'coin' && coinA) {
73+
const isHeadsA = state.two.lastA === 0; // 0 = Heads, 1 = Tails
74+
coinA.style.animation = 'none';
75+
requestAnimationFrame(() => {
76+
coinA.style.animation = isHeadsA
77+
? 'pl-flip-heads 2s forwards'
78+
: 'pl-flip-tails 2s forwards';
79+
});
80+
}
81+
82+
// Handle device B coin animation
83+
if (defB.device === 'coin' && coinB) {
84+
const isHeadsB = state.two.lastB === 0; // 0 = Heads, 1 = Tails
85+
coinB.style.animation = 'none';
86+
requestAnimationFrame(() => {
87+
coinB.style.animation = isHeadsB
88+
? 'pl-flip-heads 2s forwards'
89+
: 'pl-flip-tails 2s forwards';
90+
});
91+
}
92+
}
93+
6494
const trials = state.two.trials;
6595
const matrix = state.two.joint.map((row) => row.map((count) => (trials > 0 ? count / trials : 0)));
6696

0 commit comments

Comments
 (0)