I've created a fun jQuery function that models dog behavior, including zoomies, tail wags, and belly rubs. It's all based on a core "excitement level" metric.
functionplayWithDog($dog){// Dog's initial excitement level affects everything!letexcitementLevel=$dog.data('excitement')||50;// Dogs get more excited when you show them a toyfunctionshowToy(toyType){consttoyMultiplier={'ball':2,'frisbee':1.8,'stick':1.3,'squeakyToy':2.5};excitementLevel*=toyMultiplier[toyType];// Tail wagging intensity correlates with excitement$dog.find('.tail').animate({transform:`rotate(${Math.min(excitementLevel,360)}deg)`},{duration:200,easing:'swing',complete:function(){// Dogs can't contain themselves after a certain excitement thresholdif(excitementLevel>100){zoomies();}}});}// The legendary zoomies - running in random patternsfunctionzoomies(){constpositions=generateRandomPositions(10);letzoomieInterval;zoomieInterval=setInterval(()=>{if(excitementLevel<70){clearInterval(zoomieInterval);needsBelly.rubs=true;return;}// Move rapidly between random positionspositions.forEach(pos=>{$dog.animate({left:pos.x,top:pos.y},{duration:300,easing:'linear'});});excitementLevel*=0.9;// Gradually tire out},500);}// Every dog needs belly rubsfunctiongiveBellyRubs(){$dog.addClass('happy-rolls').on('click',function(){constcontentment=Math.min(excitementLevel*0.5,100);$(this).find('.tongue').css({'transform':'translateY(20px)','opacity':contentment/100});// Sometimes the leg starts kickingif(contentment>80){$(this).find('.back-leg').addClass('scratching');}});}// Dogs remember who gives them treatsfunctiongiveTreat(treatType){consttreatValue={'basic':10,'bacon':25,'peanutButter':30,'cheese':35};$dog.data('loyalty',($dog.data('loyalty')||0)+treatValue[treatType]);// More treats = more tricks learnedif($dog.data('loyalty')>100){unlockNewTrick();}}// The more you play, the more tricks they learnfunctionunlockNewTrick(){constavailableTricks=['sit','stay','rollOver','shake','speak','playDead'];constknownTricks=$dog.data('tricks')||[];constnewTricks=availableTricks.filter(trick=>!knownTricks.includes(trick));if(newTricks.length){constlearnedTrick=newTricks[Math.floor(Math.random()*newTricks.length)];knownTricks.push(learnedTrick);$dog.data('tricks',knownTricks);// Dogs are extra happy when they learn something newexcitementLevel+=20;}}// Initial play session setup$dog.on('playtime',function(){showToy('ball');setTimeout(giveBellyRubs,5000);setInterval(()=>giveTreat('basic'),10000);});// Start the fun!$dog.trigger('playtime');}