# Scary Mathematica Movies for Halloween

October 29, 2010 — Jon McLoone, Director, Technical Communication & Strategy

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…

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.

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.

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:

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:

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:

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.

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.

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.

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!

 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? Posted by Samuel Chen    October 30, 2010 at 3:13 am
 Love the final video. In a way simple and unmistakably analytical (trajectories) yet cool. Posted by Bo    October 31, 2010 at 5:18 am
 @ 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. Posted by Jon McLoone    November 1, 2010 at 10:29 am
 Thanks Jon, it actually makes sense now! Posted by Samuel Chen    November 1, 2010 at 7:34 pm
 It would be nice if we could get information about Mathematica 8. I think a lot of people are waiting for it. Posted by cipri    November 2, 2010 at 6:04 pm
 wow! its nice Posted by sousou    November 16, 2010 at 3:34 pm
 I didnĀ“t know it was that easy Posted by gui|creditos rapidos    July 11, 2011 at 6:17 am
 Hysterical videos!!! Love it. Have no clue about the math… :) Posted by dolly    October 31, 2011 at 10:28 pm