Commit Β·
734d133
1
Parent(s): 732f6ed
Split C (part 2): coin-float animation (option D) using float_order
Browse files- client-side animation over the outcome image: gain coin flies chosen-chest -> pocket
(+sparkle, ka-ching); loss flies pocket -> chest (thunk); 0 pops; a coin stays at each
pocket as the persistent feedback
- sequential you-first/partner-first driven by the block's float_order (~900ms apart)
- static coins removed from the render (the float draws them); cleared when leaving the
outcome; sounds now fire per coin from the animation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Files changed (2)
- experiment_structure.py+13-10
- web_app.py+51
522 unmodified lines523524525526527528529530531184 unmodified lines716717718719720721722723724725726727728729730731522 unmodified linessprites.draw_character(d, par_x, H - 12, 1, 0, **sprites.PARTNER_PAL)T(d, you_x, H - 118, "YOU", size=15, bold=True, fill=(255, 255, 255), center=True, outline=True)T(d, par_x, H - 118, "PARTNER", size=15, bold=True, fill=(255, 255, 255), center=True, outline=True)if mode == M_OUTCOME:sprites.draw_coin(d, you_x, H - 74, s_out)sprites.draw_coin(d, par_x, H - 74, o_out)return img184 unmodified liness = ts.statemode = int(s.mode)_arm_outcome_autoclose(mode)# synthesised sound cues (no-op unless the player turned sound on)if mode == M_OUTCOME:so = int(s.last_self_outcome)ui.run_javascript("if(window.sfx){window.sfx.chest(); setTimeout(function(){"f" if({so}>0) window.sfx.kaching();"f" else if({so}<0) window.sfx.thunk();"" else window.sfx.zero();}, 200);}")elif mode == M_OVERWORLD:ui.run_javascript("if(window.sfx) window.sfx.step();")except Exception as e:logger.warning(f"outcome auto-close hook failed: {e}")522 unmodified lines523524525526527528529530184 unmodified lines715716717718719720721722723724725726727728729730731732733734522 unmodified linessprites.draw_character(d, par_x, H - 12, 1, 0, **sprites.PARTNER_PAL)T(d, you_x, H - 118, "YOU", size=15, bold=True, fill=(255, 255, 255), center=True, outline=True)T(d, par_x, H - 118, "PARTNER", size=15, bold=True, fill=(255, 255, 255), center=True, outline=True)# the coins themselves are drawn by the client-side float animation (window.playCoinFloat),# which lands one at each pocket (you_x/par_x, H-74) as the persistent feedback.return img184 unmodified liness = ts.statemode = int(s.mode)_arm_outcome_autoclose(mode)if mode == M_OUTCOME:so = int(s.last_self_outcome)oo = int(s.last_other_outcome)cb = int(np.clip(int(s.current_block), 0, N_PLACES - 1))fo = int(np.asarray(s.float_order)[cb])cs = int(s.chosen_side)# chest-open clink, then the coins float to the pockets (sounds fire per coin)ui.run_javascript("if(window.sfx) window.sfx.chest();"f"if(window.playCoinFloat) window.playCoinFloat({so},{oo},{fo},{cs});")else:ui.run_javascript("if(window.clearCoinFloat) window.clearCoinFloat();")if mode == M_OVERWORLD:ui.run_javascript("if(window.sfx) window.sfx.step();")except Exception as e:logger.warning(f"outcome auto-close hook failed: {e}")
150 unmodified lines151152153154155156696 unmodified lines853854855856857858150 unmodified lines"</script>")def setup_sound():"""All sound is SYNTHESISED in the browser (Web Audio) β no asset files. Off by default;a π/π toggle controls a gentle background loop + event blips. Audio can only start after696 unmodified lineswith meta_container.style("align-items: center;"):await footer(footer_container)install_outcome_timer() # auto-close the outcome chest after a fixed timesetup_sound() # synthesised SFX + music, with a π/π toggle (off by default)setup_break_ui() # floating 'Take a break' button (shown only in main task)setup_telemetry() # log device/browser/version + every click + framerate150 unmodified lines151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206696 unmodified lines903904905906907908909150 unmodified lines"</script>")# image coords (in the 720x560 render) of the chests and the two avatar 'pockets' β kept in# sync with _render_place so the flying coins land on the right spots. Easy to tweak.def install_coin_float():"""Coins float between the chosen chest and the avatars' pockets (option D): a gain flieschest -> pocket (+sparkle, ka-ching); a loss flies pocket -> chest (thunk); a 0 just pops.You-first vs partner-first comes from the block's float_order. All client-side over thestatic outcome image."""ui.add_body_html("<style>"".thcoin{position:fixed;width:34px;height:34px;border-radius:50%;display:flex;""align-items:center;justify-content:center;font-weight:bold;font-size:15px;z-index:46;""pointer-events:none;transition:left .6s ease-out, top .6s ease-out, opacity .45s, transform .25s;}"".thspark{position:fixed;font-size:22px;z-index:47;pointer-events:none;""transition:opacity .5s, transform .5s;}""</style>""<script>""window.__coins=[];""window.clearCoinFloat=function(){window.__coins.forEach(function(e){e.remove();});window.__coins=[];};""window.__imgXY=function(ix,iy){var img=document.getElementById('stateImage');"" if(!img)return null;var r=img.getBoundingClientRect();"" return [r.left+ix*r.width/720, r.top+iy*r.height/560];};""window.__mkcoin=function(val){var c=document.createElement('div');c.className='thcoin';"" if(val>0){c.style.background='#f1c40f';c.style.border='2px solid #bf960a';c.style.color='#5a4a0a';c.textContent='+'+val;}"" else if(val<0){c.style.background='#e74c3c';c.style.border='2px solid #962818';c.style.color='#ffecec';c.textContent=val;}"" else{c.style.background='#e4e4e8';c.style.border='2px solid #14141a';c.style.color='#14141a';c.textContent='0';}"" document.body.appendChild(c);window.__coins.push(c);return c;};""window.__animOne=function(val,chestXY,avXY){"" var ch=window.__imgXY(chestXY[0],chestXY[1]),av=window.__imgXY(avXY[0],avXY[1]);"" if(!ch||!av)return;var c=window.__mkcoin(val);"" if(val>0){c.style.left=(ch[0]-17)+'px';c.style.top=(ch[1]-17)+'px';"" requestAnimationFrame(function(){c.style.left=(av[0]-17)+'px';c.style.top=(av[1]-17)+'px';});"" setTimeout(function(){if(window.sfx)window.sfx.kaching();"" var s=document.createElement('div');s.className='thspark';s.textContent='\\u2728';"" s.style.left=(av[0]-8)+'px';s.style.top=(av[1]-22)+'px';document.body.appendChild(s);window.__coins.push(s);"" requestAnimationFrame(function(){s.style.opacity='0';s.style.transform='translateY(-16px)';});},620);}"" else if(val<0){c.style.left=(av[0]-17)+'px';c.style.top=(av[1]-17)+'px';"" var fly=window.__mkcoin(val);fly.style.left=(av[0]-17)+'px';fly.style.top=(av[1]-17)+'px';"" requestAnimationFrame(function(){fly.style.left=(ch[0]-17)+'px';fly.style.top=(ch[1]-17)+'px';fly.style.opacity='0';});"" setTimeout(function(){if(window.sfx)window.sfx.thunk();},180);}"" else{c.style.left=(av[0]-17)+'px';c.style.top=(av[1]-17)+'px';c.style.transform='scale(0.3)';"" requestAnimationFrame(function(){c.style.transform='scale(1)';});"" setTimeout(function(){if(window.sfx)window.sfx.zero();},80);}};""window.playCoinFloat=function(self,other,floatOrder,chosenSide){window.clearCoinFloat();"" var leftChest=[215,285],rightChest=[505,285],youC=[282,486],parC=[438,486];"" var chest=chosenSide==0?leftChest:rightChest;"" var seq=floatOrder==0?[[self,youC],[other,parC]]:[[other,parC],[self,youC]];"" seq.forEach(function(it,i){setTimeout(function(){window.__animOne(it[0],chest,it[1]);},i*900);});};""</script>")def setup_sound():"""All sound is SYNTHESISED in the browser (Web Audio) β no asset files. Off by default;a π/π toggle controls a gentle background loop + event blips. Audio can only start after696 unmodified lineswith meta_container.style("align-items: center;"):await footer(footer_container)install_outcome_timer() # auto-close the outcome chest after a fixed timeinstall_coin_float() # coins float between the chest and the avatars' pocketssetup_sound() # synthesised SFX + music, with a π/π toggle (off by default)setup_break_ui() # floating 'Take a break' button (shown only in main task)setup_telemetry() # log device/browser/version + every click + framerate
experiment_structure.py+13-10
web_app.py+51