@@ -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