Monday, November 10, 2014

v5.0

Version 5:

- Added support for siteswaps up to "z" (for passing use a capital "P")
- Changed dwell duration to dwell ratio
- Animation automatically starts on page load. If you pass in a siteswap in the URL query string then it'll use that siteswap. For example: ydgunz.github.io/gunswap?siteswap=531. Make sure to encode the URI component (just use encodeURIComponent), so to animate 24[54] you would put in ydgunz.github.io/gunswap?siteswap=%5B33%5D.
- Cubic bezier dwell paths! This is one of the ideas that I've been excited about for a while and it's finally coming together. This will need it's own post to explain everything, but the general idea is that using cubic bezier interpolation to define dwell paths will allow patterns like mills mess, factory, etc. I've added a bezier version of the cascade and the 1-count factory (I think some people call this "waterfall"?) to the hand movement select list. More to come on this.
- I spent some time trying to make more of an app out of this so that folks can save patterns. But I'm not really sure where that's going so I stopped. I think I'm going to spend some time documenting the existing code and figuring out how to clean it up some more. Oh the luxuries of a project with no deadline.

Monday, August 25, 2014

v4.0

Haven't posted in a while. Here's what we've got in v4.0:
  • Separated siteswap parsing/validation from animation and created a Siteswap.js library that can be used both in the browser and on the server with nodejs. I'm hoping to work on some fancier documentation for the Siteswap.js library so that other folks can use it if they are interested.
  • Started using Grunt, Mocha and Travis CI for testing purposes. Grunt is a great Javascript task runner that I really only have set up to watch for changes in the source files and kick off tests, but there's a lot of opportunity there for streamlining some of the development processes. Mocha is the testing framework, pretty simple. Travis CI is an awesome, free, CI platform that runs all my tests on every push to GitHub. 
    • I'm really only testing some of the basic siteswap parsing functionality, but I'm pretty happy with the tests so far. I'm not sure how to go about testing the functionality that generates the prop positions/rotations, will have to give that some more thought. Also need to consider how to test the UI. I've played with Watir in the past, but that's all ruby...
  • Spent a bunch of time playing with a Mongo/NodeJS/Express/EmbeddedJS stack. Considering adding a DB backend so that people can save their patterns. There's a lot to this though and right now I'm still more interested in just the raw animator.
  • Fixed that synchronous halving issue by adding (0,0) to each beat.
  • Introduced a new modifier "S" to change the number of prop rotations in the air and the orientation of the throw and spins (only really applicable to clubs and rings). 
    • The syntax is <toss>S<# of spins><toss orientation><spin orientation>
    • The # of spins represents full 360 degree rotations. This is optional and if it is not present the # of spins will default to floor(<toss>/2). So a toss of 5 would be 2 spins, a toss of 3 would be 1 spin, a toss of 1 would be 0 spins, etc.
    • The toss and spin orientation are defined according to Varkor's notation. http://juggle.wikia.com/wiki/Rotation_notation
    • Examples:
      • 4S04S01S0 - 441 with all flats
      • 5S1XY - 5 cascade with 1 helicopter spin thrown with the club facing in the direction of the positive x axis
  • Number of bounces is now set the same way as the number of spins, ie. 5B1
  • Bounce type now defaults to lift bouncing if you don't specify the bounce type. Thus 5B1 and 5B1L are the same.
  • Changed the pass modifier to be a capital "P".
  • Added a grass texture map to the floor. Easy and fun. 
  • Removed the siteswap explorer and local storage saving option. I think the siteswap explorer deserves to be a separate project and I'll address the saving option when I put a DB backend on this thing.
I know some folks have had trouble with the animator, mostly in Opera and older browser versions. I think I'm going to add a 2-D HTML5 canvas option that doesn't rely on Three.js or WebGL. I've also got a handful of bugs that I should make an effort to log since I haven't actually addressed them yet.

I'm not sure what's next. I know the prop orientation stuff could be way better - more natural angles for club tosses, smoother rotations while the prop is in the dwell path (right now it just jumps), documentation of the syntax. But I'm itching to work on the dwell paths, specifically because I want to try my hand at cubic bezier interpolation. I'd also like to consider more realistic animation of the juggler, but there are a lot of things to consider there. That's a bit more intense on the animation side of things than I think I'm capable of right now.

Sunday, April 6, 2014

v3.0 Released

Just published version 3.0. First thought - what's the difference between 3.1 and 4.0? We have this same debate at work and it seems like there's no real solid answer. I think if my next stopping point only includes some bug fixes and refactoring, then it's 3.1. If it's got a bunch of big new features and (yet another) UI change, then I'll call it 4.0.

Anyways, version 3.0 has the following new features:

  • Improved UI layout
  • Added ring and club prop types
  • Added reverse cascade and shower hand movements
  • Added a "siteswap explorer" that generates vanilla siteswap patterns based on some user inputs
  • Added a save feature using the browser's local storage, so the data wont' persist across browsers and/or machines
I think the next stopping point is going to be a version 3.1 with a bunch of refactoring and bug fixes. There's still that synchronous siteswap "halving" issue and the siteswap explorer doesn't support non-numeric characters. It also kind of gives the user a smoking gun to choke their browser if they generate siteswaps for 8+ beats and max throw height. The help functionality is really lacking, and I think that's because I'm still not sure who the target audience is for this software. If you know your siteswaps and have used something like juggling lab before, then I think this all should be fairly intuitive. If you don't know siteswaps then chances are you're really not interested in this app anyway, so perhaps I don't even try to help that kind of user?

The code is really starting to look like spaghetti. I guess that's the downside to constantly experimenting with different ideas, and not thinking of how the whole thing fits together. I think before I start working on big features for v4.0 (things like customized dwell paths, number of prop rotations in flight, defining where each juggler is in passing patterns) I need to take a step back and re-assess the whole design.

And testing...that didn't last long... I do like the Qunit tests for the siteswap validation component. I think there's some real value to be had there, and I should make sure I spend some time getting that back up to speed. I don't think there's really any sense in automated testing for any of the animation stuff, I'm not even sure how that would work.

Lots of cool stuff here, I'm really pleased with how far this has come since I decided to take the release process more serious. Each release has had its flaws, but actually drawing a line in the sand and saying "this is version 3" feels good.

Monday, March 24, 2014

v2.0 Notes

Reached a good stopping point for v2.0 faster than I expected. I added the following:

  • User inputs for beat duration, dwell duration, prop radius and prop coefficient of restitution (ie. bounciness)
  • Support for bounce juggling
    • Add any number of "B" characters to a single toss to make it a bounce (the number of bounces is the number of B's). Must follow each B with an L (lift), F (force), HL (hyperlift) or HF (hyperforce). So 5 ball lift bounce pattern would be "5BL"
    • http://jugglinglab.sourceforge.net/html/ssnotation.html explains the bounce notation I used
  • Animated jugglers
  • First person camera option
  • User input for animation speed

Priorities for the next version:

  • Synchronous siteswap "halving" issue
  • Alternative dwell paths like reverse cascade, windmill and mills mess
  • Alternative props like clubs and rings
Soon I'd like to write a post about my dwell path and flight path interpolation algorithms. Definitely needs explaining because the code is starting to look a little messy.

Tuesday, March 11, 2014

gunswap v1.0 released!

I am happy to announce that after way too much tinkering and half-complete little scripts, gunswap v1.0 is complete!

All you can do right now is enter a standard siteswap pattern and see it animated in the browser (I've done all my development in Chrome). There is support for vanilla, multiplex, synchronous and passing siteswaps. That lays the groundwork for a lot of cool improvements - what's next?

Version 2 will probably focus mostly on more inputs for configurable parameters. The trick is going to be determining which are the most important. Here are some general categories of input parameters and/or new features:

  • Synchronous siteswap "halving" issue. Consider adding (0,0) in between each beat to make throws match up with async siteswap better.
  • Environment
    • Gravity
    • Beat duration
    • Dwell ratio
  • Props
    • Cosmetic properties like size, shape and color
      • Consider options for different types of props like clubs and rings
    • Coefficient of restitution (if we implement bounce juggling)
  • Toss modifiers
    • Force/lift bounce
    • Rotation of prop (more useful for things like clubs and rings - not really noticeable with balls)
  • Dwell path
    • Current dwell path is just a circle which has options for center, radius and points of catch/release
    • Totally custom dwell paths could be made using some kind of bezier curve algorithm. http://bseth99.github.io/projects/animate/2-bezier-curves.html looks like it has some potential and I think this is how Juggling Lab does it
  • Passing
    • Define juggler positions
    • Allow jugglers to move
  • Animation
    • 2D option
    • Lighting and shading
    • Animation speed
  • Database backend
    • Not sure how interested in this I am, it would be nice to be able to save patterns, but this seems like it would shift the focus of the project

Siteswap validation

In the previous post we discussed validating the format of a siteswap string using regular expressions. However, this is not sufficient for completely validating a siteswap pattern. We need to ensure that all the throws defined by the pattern can be repeated indefinitely without props ever colliding. This can be achieved using state arrays that are frequently associated with siteswaps.

A state diagram will reflect the position of all props at each beat in the pattern. Consider the following state array:

01x23

The state array indicates the time at which each prop is going to land. Prop 0 is landing now. Prop 1 is landing in 1 beat. Prop 2 is landing in 3 beats. Prop 3 is landing in 4 beats. A state diagram should always be the length according to its maximum toss. So if a siteswap has a maximum toss of 7, the state diagrams for that pattern should all be length 7.

Now consider the very basic siteswap 3. We will construct a state array for each beat in the pattern, starting of course when there are no props

3

BEAT 0 NO PROPS xxx
BEAT 1 TOSS 3   xx0
BEAT 2 TOSS 3   x01
BEAT 3 TOSS 3   012
BEAT 4 TOSS 3   120
BEAT 5 TOSS 3   201
BEAT 6 TOSS 3   012
BEAT 7 TOSS 3   120
BEAT 8 TOSS 3   201
...

Notice how beats 3 through 5 could essentially go on forever. This indicates that our siteswap is valid. 

Now let's consider siteswap 531 and try to figure out how we can programmatically identify when we've reached a repeatable set of state arrays.

531

BEAT 0 TOSS 5 xxxx0
BEAT 1 TOSS 3 xx10x
BEAT 2 TOSS 1 210xx

Let's say that a pattern is initialized once all props have been introduced to the pattern and we've completed all of the toss instructions in the siteswap.

BEAT 3 TOSS 5 10xx2
BEAT 4 TOSS 3 0x12x
BEAT 5 TOSS 1 012xx
BEAT 6 TOSS 5 12xx0
BEAT 7 TOSS 3 2x10x
BEAT 8 TOSS 1 210xx
BEAT 9 TOSS 5 10xx2

Let's say that the pattern is complete when we've reached the first throw and we're back at the first state. Thus, our repeatable pattern is the state array represented by beats 3 through 8.

Take note that when a pattern ends in a state where all props are landing sequentially, we'll call this a "ground state" siteswap. This basically just means that you can enter and exit the pattern from the cascade or fountain pattern.

Now consider an excited vanilla siteswap like 51. This siteswap cannot be entered from the ground state and that affects its initialization process.

51

BEAT 0 TOSS 5 xxxx0
BEAT 1 TOSS 1 1xx0x

At this point we would generally toss prop 2 into the mix, but we can't because prop 1 is landing now and needs to be tossed. Thus, we toss prop 1 and save prop 2 for the next beat.

BEAT 3 TOSS 5 xx0x1
BEAT 4 TOSS 1 20x1x - INIT
BEAT 5 TOSS 5 0x1x2
BEAT 6 TOSS 1 01x2x
BEAT 7 TOSS 5 1x2x0
BEAT 8 TOSS 1 12x0x
BEAT 9 TOSS 5 2x0x1
BEAT 10 TOSS 1 20x1x 
BEAT 11 TOSS 5 0x1x2 - COMPLETE

As you can see above, our repeating pattern is beats 5 through 10.

For synchronous siteswaps we need to extend this state model to include left/right hands. Consider (4,4):

(4,4)
LEFT RIGHT
x0   x1
02   13 - INIT
20   31 
02   13
20   31 - COMPLETE

For multiple jugglers we need to extend this state model to include each juggler. Consider <3p|3p>:

<3p|3p>

JUGGLER 1  JUGGLER 2
LEFT RIGHT LEFT RIGHT
xxx  xxx   xxx  xxx
xx1  xxx   xx0  xxx
x1x  xx3   x0x  xx2
1x5  x3x   0x4  x2x - INIT
x5x  3x0   x4x  2x1
5x2  x0x   4x3  x1x
x2x  0x4   x3x  1x5
2x1  x4x   3x0  x5x
x1x  4x3   x0x  5x2
1x5  x3x   0x4  x2x
x5x  3x0   x4x  2x1 - COMPLETE

Finally, consider the multiplex pattern 33[33]. For multiplex patterns we will delimit the landing beats using brackets.

33[33]

JUGGLER 1
LEFT        RIGHT
[x][x][x]   [x][x][x] 
[x][x][0]   [x][x][x] 3
[x][0][x]   [x][x][1] 3
[0][x][2,3] [x][1][x] [33] - init
[x][2,3][x] [1][x][0] 3
[2,3][x][1] [x][0][x] 3
[x][1][x]   [0][x][2,3] [33]
[1][x][0]   [x][2,3][x] 3
[x][0][x]   [2,3][x][1] 3
[0][x][2,3] [x][1][x] [33]
[x][2,3][x] [1][x][x] 3 - complete

So how do you tell when a siteswap is invalid? This occurs when there is a conflict between the number of props landing in a hand and the number of props expected to be tossed by that hand. Consider an invalid siteswap 513.

513

BEAT 0 TOSS 5 [x][x][x][x][0]
BEAT 1 TOSS 1 [1][x][x][0][x]
BEAT 2 TOSS 3 [x][x][0,1][x][x]
BEAT 3 TOSS 5 [x][0,1][x][x][2]
BEAT 4 TOSS 1 ERROR: EXPECTING 1 PROP, 0 LANDING

Monday, February 24, 2014

Using regex to parse siteswap strings

A siteswap is a string that defines a juggling pattern. Explanation of siteswap is out of scope for this post, I'm simply providing additional documentation on how the gunswap Siteswap object parses its input. I think the Juggling Lab documentation has a great page explaining siteswap notation: http://jugglinglab.sourceforge.net/html/ssnotation.html. However, I am not going to consider any of the special extensions they use (at least for now).

Breaking a siteswap down by beats

Every siteswap can be broken down as instructions for a series of beats. Some siteswaps are very simple to break down: 531 is a 5 toss followed by a 3 followed by a 1. However, consider the siteswap (4,4)(4x,4x) which is a relatively long string, but only contains instructions for 2 beats. Each hand throws a 4, then each hand throws a crossing 4. Things can get even more complicated if you consider multiple jugglers, like the siteswap <[33]|(4x,4x)> which only contains instructions for 1 beat: juggler 0 is doing a multiplexed 3 ball cascade and juggler 2 is doing a synchronous 4-ball crossing fountain.

We need to develop a regex that can split any siteswap string into its component beats. So let's start simple.

Vanilla siteswap

TOSS = \d|[a-o]

First consider some simple vanilla siteswaps like 3, 55500, and b97531 (ok maybe this one isn't simple...). All of these siteswaps match the regular expression meaning they can be a digit (\d) or (|) any character "a" through "o" ([a-o]). Note that "a" through "o" really just represent the numbers 10 through 24. We stop at "o" because later on we'll see that "p" is going to be used for something other than representing a toss height.

Multiplexes

MULTIPLEX = \[(\d|[a-g])+\]

Multiplex notation allows us to throw multiple props with the same hand on the same beat. This is handled using brackets. So the siteswap 33[33] is a 4 ball version of the 3 ball cascade where the third throw of the pattern is done with 2 balls following the same path. Let's break down this regex:
  • \[ 
    • starts with a bracket (the bracket needs to be escaped)
  • (\d|[a-g])+ 
    • contains at least 1 of our valid toss expressions
  • \] 
    • ends with a bracket
Synchronous

SYNC = \((TOSS|MULTIPLEX),(TOSS|MULTIPLEX)\)

Now things start to get a little complicated. Consider a synchronous siteswap (4x,4x). This is a synchronous 4-ball fountain where every throw crosses to the other hand. In synchronous siteswap the left side of the comma is the left hand's instructions and the right side is the right hand's instructions. The instructions can be a vanilla toss or a multiplex. Thus, we check for an open and close parentheses with a comma separated vanilla toss or multiplex pattern in between.

You may have noticed that we aren't handling the "x" in (4x,4x). We need to update our TOSS regex to handle that. It is now going to be (\d|[a-g])x?. Note that the question mark means we're looking for 1 or 0 "x" characters following our valid toss pattern. Also note that the "x" character isn't necessarily limited to synchronous siteswap, though its use in vanilla siteswaps is somewhat limited (mostly for transition throws into synchronous).

A valid beat

BEAT = (TOSS|MULTIPLEX|SYNC)

We now have enough regexes to identify valid beats within a pattern, and that's a relatively simple pattern itself. It's simply checking for a vanilla toss, a multiplex, or a sync toss.

This allows us to break even complicated siteswaps into their component beats. Consider the siteswap 5(4,4)[33]. This would be split into: toss a 5, then toss a (4,4), then toss a [33]. While technically not a valid siteswap (we'll see that level of validation later on) it still has a valid siteswap format.

Passing

PASS = <BEAT(\|BEAT)+>

Consider the passing siteswap <3p|3p><3|3> which has two jugglers both running a 3 ball cascade and passing on every other beat. In passing patterns each beat is enclosed between "<" and ">" characters, with each juggler's instructions separated by a "|" character. Each juggler's instructions must be a valid beat, thus we can construct a pass regex solely from the BEAT regex.

Now we need to make another extension to our original vanilla siteswap regex, but only for passing patterns. If we have a 2 juggler passing pattern then we need to look for a "p" appended to any vanilla toss:

(\d|[a-g])x?p?

If there are three or more jugglers then we need a way of determining which juggler the pass is targeted at. This will be denoted by the number immediately following the "p":

(\d|[a-g])x?(p[1-numJugglers])?

Putting it all together

^(PASS)+|(BEAT)+$

The final regex checks to see if you have an entire string composed of any number of passing beats or non-passing beats. That's it! Recall that this does not guarantee the validity of a siteswap, it just ensures the string is a valid format. Later on we will use the concept of state diagrams to determine if a siteswap is valid.