Wolfram Computation Meets Knowledge

Bringing Zombies to Life… Is That an Oxymoron?

I was lucky enough in college to be able to double-major in physics and film/media. One of the coolest connections that formed from these completely opposite subjects was the use of Mathematica. What started out as just a computational tool for all the work in my physics classes turned into an experimental playground for the digital animation I was creating in my film classes.

Mathematica is an ideal program to model the true science of motion. And as you’ll come to see, it looks complicated, but is actually quite simple!

Let’s start with understanding some basic human anatomy (or zombie anatomy, since this post is technically about zombies):

Zombie stick figure

Our zombie (henceforth referred to as “Ted,” because… well, that’s what I named him) is currently just your basic stick figure. Each leg is made up of a thigh, calf, and foot; each arm is a shoulder, forearm, and hand. And he has a torso, a neck, and a head. Between each line we’re going to place a joint, which will allow Ted to move his limbs and give us our animation control—think of us as puppeteers pulling strings.

So let’s define our function to depend only on the joint rotation angles plus a single set of coordinates from which Ted will be built around, and lastly, a “face” variable that will come in handy later

Define our function

As we build Ted, we’re going to have to do some parenting. No, not that kind of parenting! (Though Ted does appreciate love and attention.)

To get an idea of parenting: raise your arm straight up over your head. To do this, you rotated only your shoulder joint, but your whole arm went with it. Now, with your arm still raised above your head, bend your forearm. You rotated your elbow, and your hand went with it, but your shoulder didn’t move. Now with your arm still bent at the elbow, rotate your shoulder back down. Again, your entire arm went with your shoulder–and your elbow stayed bent, relative to your shoulder.

That’s parenting!

We can do this in Mathematica by taking advantage of the fact the code is read linearly—what is written first will be evaluated first, and the evaluation only changes if the code following it tells it to.

So how do we properly parent limbs? Well, my elbow is always going to follow my shoulder, but my shoulder is not always going to follow my elbow. So in the code, the rotation of my shoulder has to come before my elbow. Following this logic, we can also see that nearly everything comes to a point at the hip—if you bend over, both of your arms, your torso, your neck, and your head all must follow.

So here is Ted, all grown up! I think we did a pretty good job parenting, don’t you?

Definition of Points
Definition of Points cont.

Manipulate ZombieMan

Download CDF

He’s still a stick-figure, though. So with a little more code (ugh, not more code), we can easily transfer our lines into rectangles. Oh, I almost forgot—let’s give Ted his face:

Ted's face

Download CDF

Much better! But we still have yet to actually bring him to life. First, some ambiance (with parts that will move when we animate it!):

movingparts

Background Image

Right now our function depends mostly on angles. And if we want to make Ted walk, we need him to bend the joints in his legs by continuously picking them up and putting them down, and repeat this motion indefinitely. What sort of motion does this?

motion

Sinusoidal motion, of course! These are some rather arbitrary functions I made up to have Ted walk. With some tweaking, we can apply these functions to our angles and… Ted is alive!

Animate BGZombieMan2D

Download CDF

To see a few other cool features of Mathematica, and how we can make the above applet interactive (how about importing your own image as Ted’s face?), download the notebook and try out the code yourself. Happy Halloween!

Download this post as a Computable Document Format (CDF) file.

Comments

Join the discussion

!Please enter your comment (at least 5 characters).

!Please enter your name.

!Please enter a valid email address.

2 comments

  1. Fun and quite practical. I will be using some of this. Thanks!

    Reply
  2. Very cool and a joy to read!

    In addition to realistic motion, I thought that the background and the personalized-photo ideas were brilliant.

    Reply