Valentine’s Day renderings – programming shadows in ActionScript 3

February 15th, 2009 : Nik Rowell

I’ve been putting some thought lately into the best way to render shadows in AS3. The built-in DropShadowFilter is perfect for most situations – particularly headlines and simple movie clips – but it lacked perspective control, at least for what I was envisioning…

arcstonevalentine.jpg

Here’s the technique I used:

  1. Created a BitmapData instance, and added it to the display list as a Bitmap
  2. Added 500 hearts to a container sprite – drawn programatically with a custom Heart class, similar to the code used in this Processing experiment. Their size and rotation was controlled using Perlin noise – following a random path.
  3. One the hearts were all drawn … I used the BitmapData.draw method to draw the contents of the container sprite into the BitmapData instance.
  4. I used the BitmapData.applyFilter to desaturate and apply a slight Blur to the shadow.
  5. Finally, the shadow’s y position and scaleY properties (set when added to the stage) were used to give the shadow a more realistic perspective.

hearttrail_2.jpg

hearttrail_7.jpg

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • ThisNext
  • Furl
  • Reddit
  • Slashdot
  • Technorati

Tags: , , ,


Leave a Reply:

Subscribe without commenting