38
$\begingroup$

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.

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

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[]];
     )]]
$\endgroup$
  • $\begingroup$ Nice! Interesting application of scheduled tasks. $\endgroup$ – bobthechemist May 4 '14 at 17:54
  • $\begingroup$ @bobthechemist Thanks :) to be honest it is always tricky to use them for me :P relevant topic $\endgroup$ – Kuba May 4 '14 at 18:11
  • 1
    $\begingroup$ @gwr will update it as soon as possible when I'm back next Monday :) $\endgroup$ – Kuba Mar 30 '17 at 6:56
  • 1
    $\begingroup$ I just had to push you over the 100K - and it had to be this post ;-) congrats! $\endgroup$ – user21 Sep 25 '18 at 9:11
  • 1
    $\begingroup$ @user21 Ha, thanks. Hope to see you in three weeks! $\endgroup$ – Kuba Sep 25 '18 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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