Wolfram Computation Meets Knowledge

Scary Mathematica Movies for Halloween

With Halloween approaching, I thought that I would plumb new depths in frivolous uses of Mathematica by making some scary pumpkin movies. Woooo!

If your nerves can take the sheer horror of it all, turn the lights down and dare to read on…

A pumpkin rendered in Mathematica

The first thing I had to do was come up with the basic pumpkin shape, a sphere with ripples running from pole to pole. Pretty easy to do if we think of it as an inequality.

Code for a basic pumpkin shape
A sphere with ripples running from pole to pole

There are two subtleties to notice. If we use ArcTan[y/x] to work out the angle around the equator, the branch cut stops the ripples from lining up nicely, so I used the two argument form of ArcTan instead. The other is that I don’t want the pumpkin to be solid, as I want to put candles inside, so the surface has an inner boundary too, even though we can’t see it yet.

The next thing I needed to do was get a knife out and start digging holes in our pumpkin. I used traditional triangular holes. Again, thinking in terms of inequalities makes this pretty easy.

Code to cut out the eyes

I then combined the two to get a familiar pumpkin face, and while I was at it, I added a simple stalk using the Tube primitive:

Adding the stalk and eyes
Displaying the pumpkin
The rendered pumpkin with stem and mouth

It’s the right shape, but hardly very scary. As with many cheap horror films, the answer lies in the lighting. Mathematica gives us great control over lighting with spotlights, directed lights, point sources, and ambient lighting in any number, position, and color that we want. For spooky, though, I kept it simple. First, I got rid of the last mathematical details of the plot:

Getting rid of the last mathematical details of the plot

And then I showed it with just three point sources: two yellow ones placed inside the sphere to give candle light and one well outside the sphere to cast some deep shadows:

Code to add lighting
Rendering of lighted pumpkin

With a little more creativity and time spent on faces and lighting, I am sure there are plenty of scarier pumpkins to be made, but this is good enough to start making some movies with.

First, I wanted to try to make the lighting more dynamic by making the exterior light move and the candles flicker. The flicker is achieved by choosing each candle brightness randomly from one frame to the next. I tried some smooth lighting changes, but they didn’t look like flickering. Having two candles instead of one made the light not just flicker brighter and dimmer, but appear to jump around a bit. The exterior light simply orbited around the pumpkin. All I had to do was generate 180 frames and then export them to an AVI file. This produced a rather large uncompressed AVI file, so I then compressed it into another format using Adobe Premiere Elements. I also used this to manually add the spooky (!) soundtrack.

Adding lighting flicker to the pumpkin

Spooky, but not scary. So my second movie, “Attack of the Killer Pumpkins”, combined the lighting with some movement. I wanted to have the pumpkin emerge into the light. I should probably have done that by controlling the attenuation of the light from one source, but I decided that rather than set a global lighting model, I would light each pumpkin individually and just have the light source get brighter as it approached the camera. Not a reflection of the “reality” that I am modeling, but it seemed easier to me.

Adding movement to the pumpkin

Then I generated a list of pumpkin positions according to time. Each zoomed linearly in the y direction (out of the screen) and oscillated with different amplitudes and frequencies in z (up and down). Working out the trajectories and timing was done by trial and error using a Manipulate of spheres, so that I zoomed them in and out in real time. Rendering a high-quality pumpkin of a specified brightness in each position to make the movie file takes too long for experimentation.

The final step was to view the whole scene from very close, so that I got lots of spooky perspective.

Changing the camera angle

Again, format conversion and the added soundtrack were done manually.

Now turn the lights back on, and do try to remember that it was all just make-believe!

Download notebook

Comments

Join the discussion

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

!Please enter your name.

!Please enter a valid email address.

8 comments

  1. What a great post! Never knew Mathematica could all that! I was amazed even at the first step, how did you know it’s the Cos of ArcTan that would do the trick?

    Reply
  2. Love the final video. In a way simple and unmistakably analytical (trajectories) yet cool.

    Reply
  3. @ Saumuel
    ArcTan[y/x] gives the longitude on the sphere. Just think of the triangle formed by looking from above. So adding a function of this to the radius makes the radius dependent on longitude. Cos, seemed like the natural curvy shape.

    Reply
  4. Thanks Jon, it actually makes sense now!

    Reply
  5. It would be nice if we could get information about Mathematica 8.
    I think a lot of people are waiting for it.

    Reply
  6. Hysterical videos!!! Love it. Have no clue about the math… :)

    Reply