Wednesday, February 15, 2012

Coding Siteswap

Jugglers have a notation called siteswap to explain different sequences of throws according to throw height. Thinking through the possible patterns for a given number of objects is an interesting math problem—a problem that I decided to attack in Ruby.

To determine the different throw patterns, I used Ruby's repeated_permutation method to find all of the possible throw sequences for throw heights 1-6. Then I added some filters:

def is_valid?  
 correct_number? && # number of objects thrown
 good_first_throw && # first throw must be high enough
 correct_timing == true && # you can only catch one thing at a time
 does_not_repeat # don't return 313131 when 31 will suffice
end


At the moment, I'm looking into this nifty JavaScript siteswap animator and seeing what it will take to make my Ruby code generate some sweet animations. I'm thinking that jQuery + an HTML5 canvas element would be pretty cool.

Here's the siteswap repo on GitHub.

No comments:

Post a Comment