Wanna be 1337? Read Penguin Pete!

Creating Flash Animations on Linux - part 4

Date/Time Permalink: 05/08/07 05:21:48 am
Category: Flash

So while I'm toying with this new Flash discovery, it occurred to me:

  • 3D Flash is cool.
  • jpeg2swf can be scripted from the command line.
  • POVray can be scripted from the command line.
  • Image Magick can be scripted from the command line.
  • Bash could wrap it all together.

This is an idea that would not let me sleep until I tried it. So I coded:

#declare SPIN_FACTOR=170;

plane {<0, 1, -1>, 0
  texture{
   pigment{color rgb <1, 1, 1>}
   finish{ambient rgb <0.498039, 0.498039, 0.498039>
          diffuse 1}}
  scale 1
  translate <0, -1, 1>}

text {ttf "/usr/X11R6/lib/X11/fonts/TTF/times.ttf"
  "Penguin Pete's" 0.1, <0, 0>
  texture{
    pigment{granite color_map{
      [ 0 color rgb <0.93, 0.71, 0.532>]
      [ 0.6 color rgb <0.98, 0.81, 0.6>]
      [ 0.6 color rgb <0.5, 0.3, 0.2>]
      [ 0.65 color rgb <0.5, 0.3, 0.2>]
      [ 0.65 color rgb <0.8, 0.53, 0.46>]
      [ 1 color rgb <0.85, 0.75, 0.35>]}}
    finish{ specular 0.1 roughness 0.5 }
    normal{ dents 4
      turbulence <1, 1, 1> omega 1}
      scale 0.25}
  scale 1
  translate <-2.9, -0.23, 0>}

union {
  union {
    cylinder{
      <-3, 0.75, 0.05>, <3, 0.75, 0.05>, 0.1}
    cylinder{
      <-3, -0.75, 0.05>, <3, -0.75, 0.05>, 0.1}
    torus{ 0.75, 0.1
      rotate x*90
      translate <-3, 0, 0.05>   
      clipped_by { plane { <1, 0, 0>, 0
        translate x*(-3)}}}
    torus{ 0.75, 0.1
      rotate x*90
      translate <3, 0, 0.05>  
      clipped_by { plane { <-1, 0, 0>, 0
        translate x*3}}}}
  texture { pigment { color rgb <0.94, 0.93, 0.85> }
    finish { ambient rgbft <0.1, 0.1, 0.1, 0.1, 0.1>
      diffuse 0.7 brilliance 6 metallic 1
        specular 0.8 roughness 0.00833333
        reflection {
          rgbft <0.8, 0.8, 0.8, 0.8, 0.8>}}}

  rotate x*SPIN_FACTOR}

light_source { <0, 5, -5>, rgb <1, 1, 1> }
camera { perspective location <0, 0, -7>
  sky <0, 1, 0> direction <0, 0, 1>
  right <1.3333, 0, 0> up <0, 1, 0>
  look_at <0, 0, 0> }

global_settings {
   adc_bailout 0.00392157
   assumed_gamma 1.5
   noise_generator 2 }

Yes, I was in such a hurry that I formatted my POVray code like a tornado hit it. If you can't read it, that makes two of us. And here's the Bash wrapper:

#!/bin/bash

IMGNUM=0

while [ "$IMGNUM" -le "17" ];
do  sedfeed='s/SPIN_FACTOR=.*;/SPIN_FACTOR='$(($IMGNUM*10))';/'
  FILENAME="Logo3D_"$(printf "%02d" $IMGNUM)".jpg"
  sed $sedfeed POVray_source.pov > temp
  mv temp POVray_source.pov
  povray POVray_source.pov
  convert POVray_source.png -quality 50% -crop 320x160+0+40 $FILENAME
  IMGNUM=$(($IMGNUM+1))
done

rm POVray_source.png
jpeg2swf -r 100 -o 3DLogo.swf ./*.jpg
rm ./*.jpg

exit 0

Some explanation: We have POVray showing us some textured text floating over a sloped high-contrast white background and a metallic hoop around the text. Looking sorta like this:

3D Logo demo frame

Next, we're going to spin that hoop, in an animation series of 18 frames (10 degrees per frame, after 180 degrees the hoop is the same as before, so no need to do the whole 360).

So the Bash script loops through the frames, adjusting the rotation of the hoop via resetting the value of SPIN_FACTOR, calling POVray to render it, calling Image Magick's 'convert' function to crop the frame and change the image format. When the loop ends, call jpeg2swf to make the Flash file and clean up the intermediate images. Done.

And in the end I got this:

3D Logo 1.

Of course, once you have it down to this kind of science, changing something like the name or the spin parameter is easy. for instance, we take

rotate x*SPIN_FACTOR}

and change that x to a y

rotate y*SPIN_FACTOR}

and get this:

3D Logo 2.

We could even apply the spin factor to the text itself, but that might make it hard to read...

UPDATE: 5/17/07 By sheer luck, I stumbled on this site which has a similar tutorial doing the exact same thing I did here. Over a year and a half ago! Completely different scene, but I mean the same method of scripting POVray, SWFTools, Image Magick, and Bash.

Almost spooky... is there a twin out there? (ooooo-eeeee....)

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

suddenly the moon