Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Happy Star Wars day. I was playing around with the image manipulation functions in Mathematica in an attempt to recreate the Star Wars crawl. There's an HTML/CSS implementation which is in my opinion pretty impressive and I'm wondering if it's possible to obtain the same quality out of Mathematica (ideally using features that can be exported as a CDF).

For starters, I was focusing on the crawl (with the "long time ago..." and diminishing Star Wars title components to be added eventually). The text and theme song:

text = "It is a period of civil war.
  Rebel spaceships, striking
  from a hidden base, have won
  their first victory against
  the evil Galactic Empire.\n
  During the battle, Rebel
  spies managed to steal secret
  plans to the Empire's
  ultimate weapon, the DEATH
  STAR, an armored space
  station with enough power
  to destroy an entire planet.\n
  Pursued by the Empire's
  sinister agents, Princess
  Leia races home aboard her
  starship, custodian of the
  stolen plans that can save her
  people and restore
  freedom to the galaxy....";
theme = Import[
  "http://www.moviewavs.com/0093058674/WAVS/Movies/Star_Wars/starwars.wav"]

One can get the gist if the effect fairly succinctly with a combination of ImagePerspectiveTransformation and TranslationTransform after rasterizing the text:

i0 = Rasterize[Panel[Style[text, Yellow], Background -> Black], 
   RasterSize -> 400, ImageSize -> 300];
Animate[
 Show[With[{a = 5.25, b = 5},
   ImagePerspectiveTransformation[
    ImagePerspectiveTransformation[i0, 
     TranslationTransform[{0, crawl}]], {{1, 0.5 b, 0}, {0, a, 0}, {0,
       b, 1.}}, PlotRange -> All]
   ], ImageSize -> 600],
 {crawl, -3, 1}, AnimationRate -> 0.075, AnimationRepetitions -> 1, 
 Initialization -> (EmitSound@theme)]

There are some problems with this approach, however:

  1. Text quality isn't great. The quality can be improved by adjusting the Rasterize options; however I noticed a significant performance hit in doing so.
  2. The transformations result in white bars above and below the crawl.
  3. The theme song repeats and is not easily stoppable.
  4. The notebook size bloats to 2 MB even with the low res settings
  5. Use of Animate won't work when it comes to exporting as a CDF

I am interested in finding solutions to these problems.

share|improve this question
10  
Fourth. When I saw the title, I thought this was going to be a question about the stack-based programming language. ;) –  Oleksandr R. May 4 at 15:27
1  
@OleksandrR. I never know whether to agree with spell/grammar check or to stretch the pun a little too far. –  bobthechemist May 4 at 15:35
    
Ok, if wikipedia uses fourth, it must be true. –  bobthechemist May 5 at 13:50

1 Answer 1

up vote 23 down vote accepted

This is not the full answer but I've solved most of the problems. The hardest one, with sound, remains.

Embedded version without music

enter image description here

bobthechemist's points

  1. Quality is not a problem anymore since here nothing is rasterized.
  2. White edges are due to "features" with Texture, I've fixed that using strange VertexTextureCoordinates.
  3. I can't handle this song now. Just adjust the speed and put it to the initialization as OP did.
  4. The song is also the most heavy thing. It has to be reduced but it won't be a problem.
  5. There is no animate so it will work as deployed CDF.

some notes


Code.

Copy text from OP first.

logo = ImageResize[
   Import["http://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/\
Star_Wars_Logo.svg/694px-Star_Wars_Logo.svg.png"], 300];

Composition[
  CellPrint,
  Cell[#, Deployed -> True, Selectable -> False] &,
  BoxData,
  ToBoxes
  ]@With[{size = {500, 500}},
  DynamicModule[{graphics, pol, proc1, proc2, procR, proc3, LOGO, shading},
   Dynamic[Refresh[         
     Overlay[{graphics, LOGO, shading}, Dynamic@obj, Alignment -> Center],
     None]],

   Initialization :> (

     obj = All;
     op = 0;
     h = -1.3;
     LOGO = Graphics[{Inset[Image[logo, ImageSize -> Dynamic[Round[300 (-op + 1)]]]]}, 
       ImageSize -> size];
     shading = Graphics[Dynamic@{Opacity@op, Rectangle[]}, ImageSize -> size];

     pol = TextCell[
       Fold[StringReplace, text, {"\n  " -> " ", "\n " -> "\n\n"}], 
       "Text", TextJustification -> 1, CellSize -> {320, 540}, 
       FontFamily -> "Helvetica", 18, Bold, Yellow, LineIndent -> 0, 
       Background -> Black, CellFrame -> 10];

     graphics = Graphics3D[{
        Texture@pol, EdgeForm@Black,
       Polygon[{{0, 0, 0}, {0, 1, 0}, {2, 1, 0}, {2, 0, 0}}, 
        VertexTextureCoordinates -> {{.98, .02}, {.02, .02}, {.02, .98}, {.98, .98}}]},
       Boxed -> False, Background -> Black,
       ViewVertical -> {0, 0, 1}, ImageSize -> {500, 500}, 
       ViewVector -> Dynamic@({{-h, .5, 1}, {2 - h, .5, 0}}), 
       ViewAngle -> 1, Lighting -> "Neutral"];

     RemoveScheduledTask@ScheduledTasks[];
     procR[] := (RemoveScheduledTask@ScheduledTasks[]);
     proc1[] := 
      RunScheduledTask[
       If[op < 1, op += .005;, procR[]; obj = {1, 3}; op = 0; proc2[]], .05];
     proc2[] := (RunScheduledTask[
         If[h < 1, h += .002, procR[]; proc3[]];, .05];);
     proc3[] := RunScheduledTask[If[op < 1, op += .05;, procR[];], .02];

     RunScheduledTask[proc1[]];
     )]]
share|improve this answer
    
Nice! Interesting application of scheduled tasks. –  bobthechemist May 4 at 17:54
    
@bobthechemist Thanks :) to be honest it is always tricky to use them for me :P relevant topic –  Kuba May 4 at 18:11
2  
Note that I have to wait until "Revenge of the Sixth" before accepting any answers. –  bobthechemist May 5 at 13:52
    
@bobthechemist I have not found convenient way to deal with music pausing :/ of course it's not that I was working on this for 3 weeks but I've tried couple of times :) At the time of next motivation inflow I will try to make a cdf with synchronised music at least. –  Kuba May 27 at 20:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.