Physics test for Project 1

Today I muddled through ActionScript 3.0 for the first time. It was very messy, but I finally got something I’m happy with. Here for your interacting pleasure, the one, the only (so far) Consensus Black Box:

There are three “characters” on top of each other. Click one of them to enable movement with the arrow keys. It still needs a little tweaking, and certainly real graphics (rather than the stand-in black boxes (hence the name)), but all in all, I’m satisfied with it.The code behind it is relatively simple. I went online and found the equilibrium formula for levers:

Mass x Distance left of Fulcrum = Mass x Distance right of Fulcrum

Extending that for multiple objects, I can take the sum of those terms and average it (divide by the number of terms times the length of the lever arm), then multiply that by the range of motion of the lever. The result is the base rotation for the lever:

lever_mc.rotation = ((M1 x D1 ) + (M2 x D2) + (M3 x D3))/(3 x 211.5) * 30;

In response to the ENTER_FRAME event, I added a sine function to the base rotation to get that pleasant rocking effect:

lever_mc.rotation += Math.sin(count/20)*2;

If you haven’t guessed by now, I love math just about as much as I love programming. Knowing enough of both to combine the two together allows for really neat results. Good night, world.
- Joe

Leave a Comment