function animate(siteswap) { window.open('?site='+siteswap, 'anim', 'width=280,height=280,toolbar=no,location=no,directories=no,status=no,menubar=no'); } start; $end = $this->end; //permit siteswaps up to height 14 $throw='\dabcde'; //single synch or asynch throw, including multiplex and the 'x' operator $singlethrow = '(['.$throw.']|\[['.$throw.']{2,}\])'; $syncthrow = '(['.$throw.']x?|\[(['.$throw.']x?){2,}\])'; //asynch siteswap - 2 or more single throws $asynchSiteswap = '/'.$start.'('.$singlethrow.'{2,})'.$end.'/'; //asynch siteswap, one or more asynch pairs, with optional '*' operator $synchPair = '\('.$syncthrow.','.$syncthrow.'\)'; $synchSiteswap = '/'.$start.'(('.$synchPair.')+\*?)'.$end.'/'; preg_match_all($asynchSiteswap, $text, $asynchMatches, PREG_SET_ORDER); preg_match_all($synchSiteswap, $text, $synchMatches, PREG_SET_ORDER); $siteswaps = array(); for ($i=0;$ivalidate($siteswap)) $siteswaps[]= $siteswap; } for ($i=0;$ivalidate($siteswap)) $siteswaps[]= $siteswap; } return $siteswaps; } function linkify($text) { $siteswaps = $this->find($text); while(list(,$siteswap) = each ($siteswaps)) { $regex = '/'.$this->start.'('.preg_quote($siteswap).')'.$this->end.'/'; $text = preg_replace( $regex,'$1$2', $text); } return $text; } function validate($siteswap) { if (strpos($siteswap, "(")===false) return $this->validateAsynch($siteswap); else return true; } function validateAsynch($siteswap) { if ($this->asynchAverageRule($siteswap)==false) return false; if ($this->asynchPermutationTest($siteswap)==false) return false; return true; } function asynchPermutationTest($siteswap) { //classic permutation test, see: // http://www.jugglingdb.com/news/view_article.php?id=%3CgknSe.6293%24R5.919%40news.indigo.ie%3E $throwCount = strlen($siteswap); $throws = array(); for ($i=0;$i<$throwCount;$i++) { $throw = substr($siteswap, $i, 1); $throws[$i]=($this->throwHeight($throw)+$i)%$throwCount; } for ($i=0;$i<$throwCount;$i++) if (!in_array($i,$throws)) return false; return true; } function asynchAverageRule($siteswap) { //ensure that the sum of throw heights, divided by the number //of throws, is an integer $throwCount = strlen($siteswap); $heighTotal = 0; for ($i=0;$i<$throwCount;$i++) { $throw = substr($siteswap, $i, 1); $heightTotal+= $this->throwHeight($throw); } $numberOfBalls = $heightTotal/$throwCount; return is_int($numberOfBalls); } function throwHeight($throw) { $height = ord ($throw); //check if it is a digit if ($height<58) return $height-48; //otherwise it must be a letter return $height-87; } } ?>