Programatically Drawing Trees With Recursion

I get asked a lot of questions about my tree experiments, such as sakura and interactive elm. I thought I would write up a simple explanation to point people in the right direction.

The easiest place to start is with recursion. Trees are beautiful examples of recursion in the natural world. Recursion is a deep and very important topic, but for our purposes can be simplified to the idea of code calling itself. In the example below, each time you click the stage, all of the “active” (outermost) branches call code to draw two more branches at their ends, the next time you click, those new branches call the same code. Move your mouse around to vary the angle of all of the branches. As an aside, this example also has an interesting “emergent” property of drawing hexagons (try moving your mouse to the bottom when all of the branches are drawn).

Continue reading →

Back from the Galapagos

I just got back from an amazing trip to the Galapagos islands. Besides providing the early inspiration for Darwin’s “On the Origin of Species”, the Galapagos is one of the most pristine environments left on the planet. It’s one thing to hear people talk about how the animals on the islands have no fear of humans, but it doesn’t fully prepare you for the reality of standing inches away from a sea lion nursing her young and completely ignoring your presence.

The islands are gorgeous, varied, and bursting with life. In places, you literally have to tiptoe through the local fauna. Snorkeling in the surrounding waters was equally enthralling, swimming within reach of sea turtles, penguins, sea lions, and an abundance of fish. I was simultaneously overjoyed with the experience, and a little saddened about how successfully humans have trained the remainder of the world’s wildlife to fear us. It was also mildly depressing seeing how much plastic had washed onto the otherwise pristine shores, likely traveling the pacific currents from Asia and the West Coast (the Galapagos is situated on the intersection of a few major pacific currents).

The cruise on the Celebrity Xpedition ship itself wasn’t anything special, but the staff were friendly, the naturalists were great, and the food was passable. I wasn’t really there for the cruise amenities anyway. Though I could have lived without everyone on the cruise getting sick (still recovering from some nasty virus).

Continue reading →

SPL 1.2 Released

I’m happy to announce that we just released version 1.2 of our client-side, check-as-you-type, spell checking library for ActionScript 3 projects in Flash, Flex, or AIR. This version includes some significant updates including:

  • rewritten spelling suggestions algorithm, which is faster and returns better results
  • better support for AIR, and addition of an AIRMenuHelper class to reinsert editing options
  • enhanced multi-line highlighting
  • improved support for languages other than English
  • RegExpHighlighter source code, which highlights matches for a regular expression in a text field (as seen at regexr.com)
  • various minor bug fixes and enhancements

SPL 1.2 is a free upgrade for current users. If you own a license to SPL, and have not received the update package, please contact us through the support form on our product site.

You can find more information on the Spelling Plus Library, and see demos of it in action at the SPL product page.

AS3 Workshop Notes Posted (167 slides!)

Last year I ran an intensive, one day workshop on ActionScript 3 covering a wide range of topics including AS3 / AVM2, migrating from AS2, runtime errors, the event model, the display list, regular expressions, E4X (XML), loading data and assets, optimization, and more.

Today I released all 167 slides from the workshop on my talks page at gskinner.com/talks/. I’m not planning any workshops in the immediate future, and I thought the notes would be useful for developers learning AS3. The content ranges from basic to intermediate, and includes a few obscure tips and architectural ideas.

I haven’t looked over the notes since I ran the workshop, so please pardon any errors.

Drawing Curved Lines Simplified

I’m bad at drawing curved lines in ActionScript. I’m always too lazy to figure out how to calculate exactly where the control point should go when using curveTo. Because of this, most of my experiments have relied on drawing a lot of short straight line segments to simulate curves, rather than figuring out how to draw the curves properly. For example, my tree experiments are drawn entirely with straight line segments.

While revisiting my grass simulations I decided to bite the bullet and figure out an easy way to work with curves. The result is a couple of “spikes” or isolated test cases that demonstrate the logic behind converting a series of straight lines into a nice looking curve.

The basic concept is to bisect each of the straight lines, then draw a curve between the bisections, using the original points as the curve’s control point. Nothing new I’m sure, but it works really well for me, because I can continue to think in straight lines, but draw in curves.

Continue reading →

Cut By The Wind

I showed this experiment at FitC Toronto, then forgot to post it until today.

I’ve been experimenting on and off with grass simulations in ActionScript 3 (ex1 , ex2) for a little over a year. I recently rewrote the logic to draw the grass and wanted to build out a new experiment to use it. (I’ll be posting a bit about the drawing mechanism in the next day or two)

The result was cutByTheWind, which you can see below. I tried to do something that was more cinematic than most of the pieces I’ve built to date, and had some form of open ended narrative. This isn’t really my usual forte, but I’m fairly happy with the results. It is very CPU intensive, so don’t be surprised to hear your fans start up.

Special thanks to Keith and his lovely wife for translating the title into Japanese.

Continue reading →

Core AS3: Modulus

I’ve decided to start a little series of articles on the blog called Core AS3 that will deal with small, simple snippets of code (<5 lines) that are very useful but not particularly self-evident. I often encounter questions at workshops and conferences about small coding constructs that I take for granted, and it occurred to me it might be helpful to document and share them with the community.

The first article in this series is about modulus. Modulus, which is represented by the percent sign % simply returns the remainder of a division operation. For example, 21 modulus 5 is 1. This is handy for a lot of different things, but I’m going to focus on four of them: alternation, frequency, wrapping, and two dimensional data sets.

All code will be simplified to focus on the concept at hand. Most of it should also be applicable to any similar language (ActionScript 2, ActionScript 3, JavaScript, etc)

Continue reading →

Building the Flash Player 10 Demos

We were recently approached by Adobe to build a simple set of demos for the Flash Player 10 beta. The concept was to deliver a set of very simple, feature specific demos and descriptions tied together by a consistent theme. We thought it would be fun to key the demos off of the Astro code name, and develop a fake product box with a retro-space feel.

The end result was released on Adobe labs today. You can check it out here:

http://labs.adobe.com/technologies/flashplayer10/demos/

Continue reading →